Mp.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\service\api;
  3. use app\service\ConfServiceFacade;
  4. use laytp\traits\Error;
  5. use think\facade\Cache;
  6. use think\facade\Config;
  7. use think\facade\Request;
  8. use EasyWeChat\Factory;
  9. class Mp{
  10. use Error;
  11. /**
  12. * 初始化
  13. * @param $token
  14. * @return bool
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function option($snsapi='snsapi_base')
  20. {
  21. $wechat = ConfServiceFacade::groupGet('system.wechat', true);
  22. $config = [
  23. 'app_id' => $wechat['appid'],
  24. 'secret' => $wechat['appsecret'],
  25. // 下面为可选项
  26. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  27. 'response_type' => 'array',
  28. // 'log' => [
  29. // 'level' => 'debug',
  30. // 'file' => __DIR__.'/wechat.log',
  31. // ],
  32. /**
  33. * OAuth 配置
  34. *
  35. * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
  36. * callback:OAuth授权完成后的回调页地址
  37. */
  38. 'oauth' => [
  39. 'scopes' => [$snsapi],
  40. 'callback' => request()->domain() . SURL . '/index.php/api.wechat/notify',
  41. ],
  42. ];
  43. return Factory::officialAccount($config);
  44. }
  45. }