superzc/qqminiprogram

1.0.0 2023-12-19 12:25 UTC

This package is auto-updated.

Last update: 2024-11-10 07:50:23 UTC


README

Latest Version on Packagist Release Version

This package provides additional features to the Laravel framework.

Installation

You can install the package via composer:

composer require superzc/qqminiprogram

Usage

修改小程序配置文件config/miniprogram.php

return [
    'qq' => [
        'appid' => 'xxx',
        'appsecret' => 'xxx',
    ],
];

调用类方法

use Superzc\QQMiniprogram\QQMiniprogram;
use Superzc\QQMiniprogram\Exceptions\DefaultException as QQMPDefaultException;

try {
    $qqminiprogram = new QQMiniprogram();

    // 如果需要登录调用凭据,先获取access_token(有效期2小时,建议缓存,避免重复刷新),再设置access_token
    $access_token = $qqminiprogram->getAccessToken(); 
    $qqminiprogram->setAccessToken($access_token);

    $result = $qqminiprogram->doSomething();
} catch (QQMPDefaultException $e) {
    return response()->json([
        'ret' => $e->getCode(),
        'msg' => $e->getMessage(),
    ]);
}

使用门面

use Superzc\QQMiniprogram\Facades\QQMiniprogram;

try {
    // 如果需要登录调用凭据,先获取access_token(有效期2小时,建议缓存,避免重复刷新),再设置access_token
    $access_token = QQMiniprogram::getAccessToken(); 
    QQMiniprogram::setAccessToken($access_token);

    $result = QQMiniprogram::doSomething();
} catch (QQMPDefaultException $e) {
    return response()->json([
        'ret' => $e->getCode(),
        'msg' => $e->getMessage(),
    ]);
}

Change log

暂无