完成getAccessToken改造
This commit is contained in:
parent
07f28b3c05
commit
a75e10e4af
@ -249,22 +249,19 @@ class KefuController {
|
|||||||
|
|
||||||
private function sendKefuMsg($accountid, $data)
|
private function sendKefuMsg($accountid, $data)
|
||||||
{
|
{
|
||||||
$postarray = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
||||||
//POST发送https请求客服接口api
|
|
||||||
$access_token = $this->getAccessToken($accountid);
|
$access_token = $this->getAccessToken($accountid);
|
||||||
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
|
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
|
||||||
|
|
||||||
$response = '';
|
$response = '';
|
||||||
if (!phpcommon\HttpClient::post($url, $postarray, $response)) {
|
if (!phpcommon\HttpClient::post($url,
|
||||||
|
json_encode($data, JSON_UNESCAPED_UNICODE),
|
||||||
|
$response)
|
||||||
|
) {
|
||||||
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$ret_info = json_decode($response, true);
|
$ret_info = json_decode($response, true);
|
||||||
#error_log('sendKefuMsgRet:' . $response);
|
return !empty($ret_info) && $ret_info['errcode'] == 0;
|
||||||
if ($ret_info['errcode'] == 0) {
|
|
||||||
} else {
|
|
||||||
echo(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sendKefuMsgSomeUser($arrayInfo)
|
private function sendKefuMsgSomeUser($arrayInfo)
|
||||||
@ -383,33 +380,29 @@ class KefuController {
|
|||||||
$access_token = $r->get('kf_token:' . $accountid . ':');
|
$access_token = $r->get('kf_token:' . $accountid . ':');
|
||||||
if (!empty($access_token)) {
|
if (!empty($access_token)) {
|
||||||
return $access_token;
|
return $access_token;
|
||||||
} else {
|
}
|
||||||
$gameid = phpcommon\extractGameId($accountid);
|
$gameid = phpcommon\extractGameId($accountid);
|
||||||
$config_name = "../config/game$gameid/weixin/config.php";
|
$config_name = "../config/game$gameid/weixin/config.php";
|
||||||
@require $config_name;
|
@require $config_name;
|
||||||
|
|
||||||
$appid = WEIXIN_APP_ID;
|
|
||||||
$appkey = WEIXIN_APP_SECRET;
|
|
||||||
$url = "https://api.weixin.qq.com/cgi-bin/token?" .
|
|
||||||
"grant_type=client_credential&appid=$appid&secret=$appkey";
|
|
||||||
$params = array();
|
|
||||||
$response = '';
|
$response = '';
|
||||||
|
if (!phpcommon\HttpClient::get('https://api.weixin.qq.com/cgi-bin/token',
|
||||||
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
array(
|
||||||
|
'grant_type' => 'client_credential',
|
||||||
|
'appid' => WEIXIN_APP_ID,
|
||||||
|
'secret' => WEIXIN_APP_SECRET
|
||||||
|
),
|
||||||
|
$response)) {
|
||||||
phpcommon\sendError(ERR_INTERNAL, '系统繁忙');
|
phpcommon\sendError(ERR_INTERNAL, '系统繁忙');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#error_log('response_token:' . $response);
|
$respobj = json_decode($response, true);
|
||||||
$res = json_decode($response, true);
|
if (isset($respobj['access_token'])) {
|
||||||
if ( isset($res['access_token']) ) {
|
$r->set('kf_token:' . $accountid . ':', $respobj['access_token']);
|
||||||
//刚获取的token放到redis中 //微信限制过期时间为两小时
|
$r->pexpire('kf_token:' . $accountid . ':', 1000 * ($respobj['expires_in'] - 60 * 1));
|
||||||
$r->set('kf_token:' . $accountid . ':', $res['access_token']);
|
return $respobj['access_token'];
|
||||||
$r->pexpire('kf_token:' . $accountid . ':', 1000 * ($res['expires_in'] - 60 * 1));
|
|
||||||
return $res['access_token'];
|
|
||||||
} else {
|
} else {
|
||||||
die();
|
return '';
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user