WechatController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\wechat;
  12. use app\Request;
  13. use app\services\wechat\WechatServices as WechatAuthServices;
  14. /**
  15. * 微信公众号
  16. * Class WechatController
  17. * @package app\api\controller\wechat
  18. */
  19. class WechatController
  20. {
  21. protected $services = NUll;
  22. /**
  23. * WechatController constructor.
  24. * @param WechatAuthServices $services
  25. */
  26. public function __construct(WechatAuthServices $services)
  27. {
  28. $this->services = $services;
  29. }
  30. /**
  31. * 微信公众号服务
  32. * @return \think\Response
  33. */
  34. public function serve()
  35. {
  36. return $this->services->serve();
  37. }
  38. /**
  39. * 支付异步回调
  40. */
  41. public function notify()
  42. {
  43. return $this->services->notify();
  44. }
  45. /**
  46. * 公众号权限配置信息获取
  47. * @param Request $request
  48. * @return mixed
  49. */
  50. public function config(Request $request)
  51. {
  52. return app('json')->success($this->services->config($request->get('url')));
  53. }
  54. /**
  55. * 公众号授权登陆
  56. * @param Request $request
  57. * @return mixed
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @throws \think\exception\DbException
  61. */
  62. public function auth(Request $request)
  63. {
  64. [$spreadId, $login_type] = $request->getMore([
  65. [['spread', 'd'], 0],
  66. ['login_type', ''],
  67. ], true);
  68. $token = $this->services->auth($spreadId, $login_type);
  69. if ($token && isset($token['key'])) {
  70. return app('json')->success('授权成功,请绑定手机号', $token);
  71. } else if ($token) {
  72. return app('json')->success('登录成功', ['userInfo' => $token['userInfo']]);
  73. } else
  74. return app('json')->fail('登录失败');
  75. }
  76. public function follow()
  77. {
  78. $data = $this->services->follow();
  79. if ($data) {
  80. return app('json')->success('ok', $data);
  81. } else {
  82. return app('json')->fail('获取失败');
  83. }
  84. }
  85. }