WechatPlatform.php 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Service\WechatPlatform;
  3. use EasyWeChat\Factory;
  4. use EasyWeChat\OpenPlatform\Application;
  5. use Illuminate\Support\Facades\Cache;
  6. class WechatPlatform
  7. {
  8. public static function buildApplication($componentInfo) {
  9. $config = [
  10. 'app_id' => $componentInfo->app_id, // 开放平台账号的 appid
  11. 'secret' => $componentInfo->secret, // 开放平台账号的 secret
  12. 'token' => $componentInfo->token, // 开放平台账号的 token
  13. 'aes_key' => $componentInfo->aes_key, // 明文模式请勿填写 EncodingAESKey
  14. ];
  15. $app = Factory::openPlatform(array_merge($config, config('easywechat')));
  16. $app->rebind('cache',Cache::store('redis'));
  17. return $app;
  18. }
  19. /**
  20. * @param $app Application
  21. * @param $appid
  22. * @param $refreshToken
  23. * @return \EasyWeChat\OfficialAccount\Application
  24. */
  25. public static function officialAccount($app, $appid, $refreshToken) {
  26. return $app->officialAccount($appid, $refreshToken);
  27. }
  28. }