Explorar o código

微信公众号关注事件

whitefang hai 1 ano
pai
achega
c79ef22c8f

+ 3 - 0
app/adminapi/logic/channel/OfficialAccountReplyLogic.php

@@ -167,6 +167,9 @@ class OfficialAccountReplyLogic extends BaseLogic
                         return $replyContent;
                     }
                     break;
+                case OfficialAccountEnum::EVENT_UNSUBSCRIBE: // 取消关注事件
+                    WeChatOaService::class->getUserInfo($message['FromUserName']);
+                    break;
             }
             return $next($message);
         });

+ 5 - 0
app/common/enum/OfficialAccountEnum.php

@@ -80,6 +80,11 @@ class OfficialAccountEnum
      */
     const EVENT_SUBSCRIBE = 'subscribe';
 
+    /**
+     * 事件类型 - 取消关注
+     */
+    const EVENT_UNSUBSCRIBE = 'unsubscribe';
+
     /**
      * @notes 获取类型英文名称
      * @param $type

+ 6 - 0
app/common/service/wechat/WeChatOaService.php

@@ -221,4 +221,10 @@ class WeChatOaService
             throw new \Exception($e->getMessage());
         }
     }
+
+    public function getUserInfo($openid)
+    {
+        $open_user =$this->app->getClient()->get('cgi-bin/user/info?openid={$openid}&lang=zh_CN');
+        Log::info('WeChatOa-getUserInfo:'.json_encode($open_user,JSON_UNESCAPED_UNICODE));
+    }
 }