From 02ae5ee9e63475f71ea025de93773b947fa16c65 Mon Sep 17 00:00:00 2001 From: wang hou sheng <76928547+wanghousheng@users.noreply.github.com> Date: Sun, 7 Apr 2024 21:28:10 +0800 Subject: [PATCH] 1 --- app/api/controller/Wxserver.php | 18 +----------------- app/common/library/wxserver/Server.php | 7 +------ 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/app/api/controller/Wxserver.php b/app/api/controller/Wxserver.php index 15b6dc56..18707729 100644 --- a/app/api/controller/Wxserver.php +++ b/app/api/controller/Wxserver.php @@ -4,7 +4,6 @@ declare (strict_types=1); namespace app\api\controller; use cores\BaseController; -use think\facade\Db; use think\response\Json; class Wxserver extends BaseController @@ -28,25 +27,10 @@ class Wxserver extends BaseController public function redirect() { $authorization_code = $this->request->get('auth_code'); - $expires_in = $this->request->get('expires_in'); - $data = $this->request->input(); - $datas = $this->request->get(); - if ($datas) { - if (is_array($datas)) { - $datas = json_encode($datas); - } - Db::table('yoshop_wx_server')->insertGetId(['content' => '回调数据get&' . $datas . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]); - } - if ($data) { - if (is_array($data)) { - $data = json_encode($data); - } - Db::table('yoshop_wx_server')->insertGetId(['content' => '回调数据input&' . $data . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]); - } - Db::table('yoshop_wx_server')->insertGetId(['content' => '回调授权地址' . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]); if ($authorization_code) { $obj = new \app\common\library\wxserver\Server(); $obj->authorizationInfo($authorization_code); } + echo 'success'; } } \ No newline at end of file diff --git a/app/common/library/wxserver/Server.php b/app/common/library/wxserver/Server.php index 3b35f834..70004b6e 100644 --- a/app/common/library/wxserver/Server.php +++ b/app/common/library/wxserver/Server.php @@ -63,8 +63,7 @@ class Server $result = $this->curlPost($url, json_encode($data), 10); $result = json_decode($result, true); if (!empty($result['component_access_token'])) { - $expire = !empty($result['expires_in']) ? intval($result['expires_in']) : 7200; - Cache::set('ComponentAccessToken', $result['component_access_token'], $expire); + Cache::set('ComponentAccessToken', $result['component_access_token'], 6200); return $result['component_access_token']; } } @@ -117,22 +116,18 @@ class Server */ public function authorizationInfo($authorization_code) { - Db::table('yoshop_wx_server')->insertGetId(['content' => '回调进来了' . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]); $url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=' . $this->getComponentAccessToken(); $data = []; $data['component_appid'] = self::APPID; $data['authorization_code'] = $authorization_code; $result = $this->curlPost($url, json_encode($data)); - Db::table('yoshop_wx_server')->insertGetId(['content' => $result, 'created_at' => date('Y-m-d H:i:s')]); $result = json_decode($result, true); if ($result && !empty($result['authorization_info']) && !empty($result['authorization_info']['authorizer_appid'])) { - Db::table('yoshop_wx_server')->insertGetId(['content' => '获取详情' . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]); $url = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=' . $this->getComponentAccessToken(); $data = []; $data['component_appid'] = self::APPID; $data['authorizer_appid'] = $result['authorization_info']['authorizer_appid']; $res = $this->curlPost($url, json_encode($data)); - Db::table('yoshop_wx_server')->insertGetId(['content' => $res, 'created_at' => date('Y-m-d H:i:s')]); $res = json_decode($res, true); if ($res && !empty($res['authorizer_info']) && !empty($res['authorization_info'])) { $authorizer_info = $res['authorizer_info'];