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);