Service.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace addons\notice\library;
  3. use EasyWeChat\Factory;
  4. class Service
  5. {
  6. /**
  7. * 获取 easyWechat 公众号实例
  8. *
  9. * @return \EasyWeChat\OfficialAccount\Application
  10. */
  11. public static function getOfficialAccount()
  12. {
  13. $appId = get_addon_config('notice')['app_id'] ?? '';
  14. $secret = get_addon_config('notice')['secret'] ?? '';
  15. if (empty($appId)) {
  16. $config = get_addon_config('third');
  17. if ($config) {
  18. $appId = $config['wechat']['app_id'] ?? '';
  19. $secret = $config['wechat']['app_secret'] ?? '';
  20. }
  21. }
  22. if (empty($appId)) {
  23. $config = get_addon_config('epay');
  24. if ($config) {
  25. $appId = $config['wechat']['app_id'] ?? '';
  26. $secret = $config['wechat']['app_secret'] ?? '';
  27. }
  28. }
  29. $config = [
  30. 'app_id' => $appId,
  31. 'secret' => $secret,
  32. 'response_type' => 'array',
  33. ];
  34. $app = Factory::officialAccount($config);
  35. return $app;
  36. }
  37. }