wang hou sheng 11 months ago
parent bd1e98e33e
commit 729ced0515
  1. 8
      app/api/controller/Wxserver.php
  2. 21
      app/common/library/wxserver/Server.php

@ -77,8 +77,12 @@ class Wxserver extends BaseController
} elseif ($data['MsgType'] == 'text' && !empty($data['Content'])) { } elseif ($data['MsgType'] == 'text' && !empty($data['Content'])) {
if ($data['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') { if ($data['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
$data['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback'; $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
</xml>"; </xml>";
$fromUser = $data['ToUserName']; $fromUser = $data['ToUserName'];
$toUser = $data['FromUserName']; $toUser = $data['FromUserName'];
$content = !empty($data['Content']) ? $data['Content'] : 'success'; $content = $data['Content'];
$time = time(); $time = time();
$msgType = 'text'; $msgType = 'text';
return sprintf($template, $toUser, $fromUser, $time, $msgType, $content); return sprintf($template, $toUser, $fromUser, $time, $msgType, $content);

@ -462,6 +462,27 @@ class Server
return $list; 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:获取授权信息 * @notes:获取授权信息
* @param $authorization_code * @param $authorization_code

Loading…
Cancel
Save