From 1717fcfd85c8ef6cccd5672c9d49a7f09bc8fa0e Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 15 Jul 2019 19:25:46 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E4=BF=AE=E6=94=B9=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/handler/PublishHandler.php | 12 ++++++++---- application/service/handler/ReceiveHandler.php | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/application/service/handler/PublishHandler.php b/application/service/handler/PublishHandler.php index 7ece70918..7369b661c 100644 --- a/application/service/handler/PublishHandler.php +++ b/application/service/handler/PublishHandler.php @@ -52,11 +52,15 @@ class PublishHandler case 'text': $receive = $wechat->getReceive(); if ($receive['Content'] === 'TESTCOMPONENT_MSG_TYPE_TEXT') { - return $wechat->text('TESTCOMPONENT_MSG_TYPE_TEXT_callback')->reply([], true); + $xml = $wechat->text('TESTCOMPONENT_MSG_TYPE_TEXT_callback')->reply([], true); + p('====测试回复文本======'); + p($xml); + return $xml; + } else { + $key = str_replace("QUERY_AUTH_CODE:", '', $receive['Content']); + WechatService::instance('Service')->getQueryAuthorizerInfo($key); + return $wechat->text("{$key}_from_api")->reply([], true); } - $key = str_replace("QUERY_AUTH_CODE:", '', $receive['Content']); - WechatService::instance('Service')->getQueryAuthorizerInfo($key); - return $wechat->text("{$key}_from_api")->reply([], true); case 'event': $receive = $wechat->getReceive(); return $wechat->text("{$receive['Event']}from_callback")->reply([], true); diff --git a/application/service/handler/ReceiveHandler.php b/application/service/handler/ReceiveHandler.php index e2085bd3c..28a0b15d3 100644 --- a/application/service/handler/ReceiveHandler.php +++ b/application/service/handler/ReceiveHandler.php @@ -39,7 +39,7 @@ class ReceiveHandler public static function handler($appid) { try { - $service = WechatService::WeChatReceive($appid); + $wechat = WechatService::WeChatReceive($appid); } catch (\Exception $e) { return "Wechat message handling failed, {$e->getMessage()}"; } @@ -50,12 +50,12 @@ class ReceiveHandler return $message; } try { - list($data, $openid) = [$service->getReceive(), $service->getOpenid()]; + list($data, $openid) = [$wechat->getReceive(), $wechat->getOpenid()]; if (isset($data['EventKey']) && is_object($data['EventKey'])) $data['EventKey'] = (array)$data['EventKey']; - $input = ['openid' => $openid, 'appid' => $appid, 'receive' => serialize($data), 'encrypt' => intval($service->isEncrypt())]; + $input = ['openid' => $openid, 'appid' => $appid, 'receive' => serialize($data), 'encrypt' => intval($wechat->isEncrypt())]; if (is_string($result = http_post($config['appuri'], $input, ['timeout' => 30]))) { if (is_array($json = json_decode($result, true))) { - $xml = $service->reply($json, true, true); + $xml = $wechat->reply($json, true, $wechat->isEncrypt()); p(""); p("====== 准备回复的内容如下 ========"); p($xml);