12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace App\Service\WechatPlatform;
- use EasyWeChat\OpenPlatform\Application;
- use Illuminate\Support\Facades\Cache;
- class WechatPlatform
- {
- public static function buildApplication($componentInfo) {
- $config = [
- 'app_id' => $componentInfo->app_id, // 开放平台账号的 appid
- 'secret' => $componentInfo->secret, // 开放平台账号的 secret
- 'token' => $componentInfo->token, // 开放平台账号的 token
- 'aes_key' => $componentInfo->aes_key, // 明文模式请勿填写 EncodingAESKey
- 'http' => [
- 'throw' => true, // 状态码非 200、300 时是否抛出异常,默认为开启
- 'timeout' => 5.0,
- 'retry' => true, // 使用默认重试配置
- ],
- ];
- $app = new Application($config);
- $app->setCache(Cache::store('redis'));
- return $app;
- }
- /**
- * @param $app Application
- * @param $appid
- * @param $refreshToken
- * @return \EasyWeChat\OfficialAccount\Application
- */
- public static function officialAccount($app, $appid, $refreshToken) {
- return $app->getOfficialAccountWithRefreshToken($appid, $refreshToken);
- }
- }
|