From 729ced0515ebe1a9f1daf42f61490400735348cf Mon Sep 17 00:00:00 2001 From: wang hou sheng <76928547+wanghousheng@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:13:07 +0800 Subject: [PATCH] 1 --- app/api/controller/Wxserver.php | 8 ++++++-- app/common/library/wxserver/Server.php | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/api/controller/Wxserver.php b/app/api/controller/Wxserver.php index 1fc755a6..ebbfe8fb 100644 --- a/app/api/controller/Wxserver.php +++ b/app/api/controller/Wxserver.php @@ -77,8 +77,12 @@ class Wxserver extends BaseController } elseif ($data['MsgType'] == 'text' && !empty($data['Content'])) { if ($data['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') { $data['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback'; + echo $this->responseText($data); + } elseif (strpos($data['Content'], 'QUERY_AUTH_CODE:') !== false) { + $query_auth_code = trim(str_replace("QUERY_AUTH_CODE:", "", $data['Content'])); + $obj->apiText($query_auth_code, $data['FromUserName']); } - echo $this->responseText($data); + } } } @@ -95,7 +99,7 @@ class Wxserver extends BaseController "; $fromUser = $data['ToUserName']; $toUser = $data['FromUserName']; - $content = !empty($data['Content']) ? $data['Content'] : 'success'; + $content = $data['Content']; $time = time(); $msgType = 'text'; return sprintf($template, $toUser, $fromUser, $time, $msgType, $content); diff --git a/app/common/library/wxserver/Server.php b/app/common/library/wxserver/Server.php index 72f2fa37..fa3d701b 100644 --- a/app/common/library/wxserver/Server.php +++ b/app/common/library/wxserver/Server.php @@ -462,6 +462,27 @@ class Server return $list; } + public function apiText($authorization_code, $touser) + { + $url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=' . $this->getComponentAccessToken(); + $data['component_appid'] = self::APPID; + $data['authorization_code'] = $authorization_code; + $result = $this->curlPost($url, json_encode($data)); + $result = json_decode($result, true); + if (!empty($result['authorization_info']['authorizer_access_token'])) { + $token = $result['authorization_info']['authorizer_access_token']; + $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $token; + $data = []; + $data['touser'] = $touser; + $data['msgtype'] = 'text'; + $data['text'] = [ + 'content' => $authorization_code . '$_from_api', + ]; + $this->curlPost($url, json_encode($data)); + } + + } + /** * @notes:获取授权信息 * @param $authorization_code