123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace app\service\handler;
- use app\service\service\WechatService;
- class PublishHandler
- {
-
- protected static $appid;
-
- public static function handler($appid)
- {
- try {
- $wechat = WechatService::WeChatReceive($appid);
- } catch (\Exception $e) {
- return "Wechat message handling failed, {$e->getMessage()}";
- }
-
- switch (strtolower($wechat->getMsgType())) {
- case 'text':
- $receive = $wechat->getReceive();
- if ($receive['Content'] === 'TESTCOMPONENT_MSG_TYPE_TEXT') {
- return $wechat->text('TESTCOMPONENT_MSG_TYPE_TEXT_callback')->reply([], true);
- } else {
- $key = str_replace("QUERY_AUTH_CODE:", '', $receive['Content']);
- WechatService::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);
- default:
- return 'success';
- }
- }
- }
|