WechatPlatform.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Service\WechatPlatform;
  3. use EasyWeChat\OpenPlatform\Application;
  4. use Illuminate\Support\Facades\Cache;
  5. class WechatPlatform
  6. {
  7. public static function buildApplication($componentInfo) {
  8. $config = [
  9. 'app_id' => $componentInfo->app_id, // 开放平台账号的 appid
  10. 'secret' => $componentInfo->secret, // 开放平台账号的 secret
  11. 'token' => $componentInfo->token, // 开放平台账号的 token
  12. 'aes_key' => $componentInfo->aes_key, // 明文模式请勿填写 EncodingAESKey
  13. 'http' => [
  14. 'throw' => true, // 状态码非 200、300 时是否抛出异常,默认为开启
  15. 'timeout' => 5.0,
  16. 'retry' => true, // 使用默认重试配置
  17. ],
  18. ];
  19. $app = new Application($config);
  20. $app->setCache(Cache::store('redis'));
  21. return $app;
  22. }
  23. /**
  24. * @param $app Application
  25. * @param $appid
  26. * @param $refreshToken
  27. * @return \EasyWeChat\OfficialAccount\Application
  28. */
  29. public static function officialAccount($app, $appid, $refreshToken) {
  30. return $app->getOfficialAccountWithRefreshToken($appid, $refreshToken);
  31. }
  32. }