WechatService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Services\Common;
  3. use EasyWeChat\Factory;
  4. use EasyWeChat\OfficialAccount\Application;
  5. /**
  6. * 微信服务.从这里可以获取公众号,小程序实例
  7. * Class WechatService
  8. * @package App\Services\Common
  9. */
  10. class WechatService
  11. {
  12. protected $config = [];
  13. /**
  14. * WechatService constructor.
  15. */
  16. public function __construct()
  17. {
  18. $this->config['log'] = config('wechat.log');
  19. }
  20. /**
  21. * 返回公众号实例
  22. * @param null $subsite_id
  23. * @return Application
  24. */
  25. public function getOfficialAccount($subsite_id = null)
  26. {
  27. $this->config['app_id'] = subsite_config('aix.system.oauth.wechat_official.app_id', null, $subsite_id);
  28. $this->config['secret'] = subsite_config('aix.system.oauth.wechat_official.app_secret', null, $subsite_id);
  29. $this->config['token'] = subsite_config('aix.system.oauth.wechat_official.app_token', null, $subsite_id);
  30. $this->config['aes_key'] = subsite_config('aix.system.oauth.wechat_official.aes_key', null, $subsite_id);
  31. return Factory::officialAccount($this->config);
  32. }
  33. /**
  34. * 获取微信开放平台的网站应用实例.(用于电脑端网站登录,使用开放平台中创建的网站的appid与appsecret
  35. * @return Application
  36. */
  37. public function getOpenAccount()
  38. {
  39. $this->config['app_id'] = config('aix.system.oauth.wechat_open.app_id');
  40. $this->config['secret'] = config('aix.system.oauth.wechat_open.app_secret');
  41. return Factory::officialAccount($this->config);
  42. }
  43. public function getPayOfficialAccount()
  44. {
  45. $this->config['app_id'] = config('aix.system.pay.wechat.appid');
  46. $this->config['secret'] = config('aix.system.pay.wechat.secret_key');
  47. return Factory::officialAccount($this->config);
  48. }
  49. }