123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- namespace app\controller\api\wechat;
- use app\common\ApiBaseController;
- use app\Request;
- use app\services\wechat\RoutineServices;
- use app\services\wechat\WechatServices;
- use GuzzleHttp\Exception\GuzzleException;
- use qiniu\services\huifu\CacheService;
- use qiniu\services\huifu\wechat\OfficialAccount;
- use qiniu\services\huifu\wechat\Work;
- use EasyWeChat\Kernel\Exceptions\BadRequestException;
- use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
- use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
- use ReflectionException;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Response;
- class Wechat extends ApiBaseController
- {
-
- public function __construct(Request $request, WechatServices $service)
- {
- parent::__construct($request);
- $this->service = $service;
- }
-
- public function serve()
- {
- return $this->service->serve();
- }
-
- public function config(Request $request)
- {
- $url = $request->get('url', '') ?: sys_config('site_url');
- return $this->success($this->service->config($url));
- }
-
- public function auth(Request $request)
- {
- [$spread_spid, $login_type] = $request->getMore([
- [['spread_spid', 'd'], 0],
- ['login_type', 'wechat'],
- ], true);
- $token = $this->service->auth($spread_spid, $login_type);
- if ($token && isset($token['key'])) {
- return $this->success('授权成功,请绑定手机号', $token);
- } else if ($token) {
- return $this->success('登录成功', ['token' => $token['token'], 'userInfo' => $token['userInfo'], 'expires_time' => $token['params']['exp']]);
- } else
- return $this->error('登录失败');
- }
-
- public function silenceAuth($spread_spid = '')
- {
- $token = $this->service->silenceAuth($spread_spid);
- if ($token && isset($token['key'])) {
- return $this->success('授权成功,请绑定手机号', $token);
- } else if ($token) {
- return $this->success('登录成功', ['token' => $token['token'], 'expires_time' => $token['params']['exp']]);
- } else
- return $this->error('登录失败');
- }
-
- public function silenceAuthNoLogin($spread_spid = '', $snsapi = '')
- {
- $token = $this->service->silenceAuth($spread_spid, true, $snsapi);
- if ($token && isset($token['auth_login'])) {
- return $this->success('授权成功', $token);
- } else if ($token) {
- return $this->success('登录成功', ['token' => $token['token'], 'userInfo' => $token['userInfo'], 'expires_time' => $token['params']['exp']]);
- } else
- return $this->error('登录失败');
- }
-
- public function authBindingPhone($key = '', $phone = '', $captcha = '')
- {
-
- check_sms_captcha($phone, 'wechat_auth', $captcha);
- $token = $this->service->authBindingPhone($key, $phone);
- if ($token) {
- return $this->success('登录成功', $token);
- } else
- return $this->error('登录失败');
- }
-
- public function follow()
- {
- $data = $this->service->follow();
- if ($data) {
- return $this->success('ok', $data);
- } else {
- return $this->error('获取失败');
- }
- }
- }
|