From a8cb9f0f94b9b45601a731ad61cab5c25356a356 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 22 Aug 2019 10:20:22 +0800 Subject: [PATCH] 1 --- third_party/phpcommon | 2 +- webapp/controller/KefuController.class.php | 45 ++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/third_party/phpcommon b/third_party/phpcommon index 2e7067d..1e3bb4d 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit 2e7067d848c09897f27e6486c38399b27126ca26 +Subproject commit 1e3bb4df855f6d11df75545d10b0c2aacea34a06 diff --git a/webapp/controller/KefuController.class.php b/webapp/controller/KefuController.class.php index 155c5a9..efa8bcc 100644 --- a/webapp/controller/KefuController.class.php +++ b/webapp/controller/KefuController.class.php @@ -210,26 +210,10 @@ class KefuController { private function sendKefuMsg($accountid, $data) { - $gameid = phpcommon\extractGameId($accountid); - $access_token = $this->getAccessToken($gameid); - $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . urlencode($access_token); - - $response = ''; - if (!phpcommon\HttpClient::post($url, - json_encode($data, JSON_UNESCAPED_UNICODE), - $response) - ) { - phpcommon\sendError(ERR_RETRY, '系统繁忙'); - return; - } - $ret_info = json_decode($response, true); - error_log(json_encode($response)); - if (isset($ret_info['errcode']) && ($ret_info['errcode'] == 40001 || $ret_info['errcode'] == 40003)) { - error_log('重新获取access_token'); - $r = $this->getRedis($gameid); - $r->del('kf_token:' . $gameid . ':'); + try { + $gameid = phpcommon\extractGameId($accountid); $access_token = $this->getAccessToken($gameid); - $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=" . urlencode($access_token); $response = ''; if (!phpcommon\HttpClient::post($url, @@ -240,8 +224,29 @@ class KefuController { return; } $ret_info = json_decode($response, true); + error_log(json_encode($response)); + if (isset($ret_info['errcode']) && ($ret_info['errcode'] == 40001 || $ret_info['errcode'] == 40003)) { + error_log('重新获取access_token'); + $r = $this->getRedis($gameid); + $r->del('kf_token:' . $gameid . ':'); + $access_token = $this->getAccessToken($gameid); + $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token"; + + $response = ''; + if (!phpcommon\HttpClient::post($url, + json_encode($data, JSON_UNESCAPED_UNICODE), + $response) + ) { + phpcommon\sendError(ERR_RETRY, '系统繁忙'); + return; + } + $ret_info = json_decode($response, true); + } + return !empty($ret_info) && $ret_info['errcode'] == 0; + } catch (Exception $e) { + error_log($e->getMessage()); + return false; } - return !empty($ret_info) && $ret_info['errcode'] == 0; } private function sendOneDBInfo($conn, &$media_conf)