payload = $payload; return call_user_func_array([$this, $payload['Event']], []); } else { return '暂不支持的消息类型'; } } /** * 扫码事件 * @Author: * @Date:2018-11-12T16:28:19+0800 */ private function SCAN() { } /** * 主菜单点击 * @Author: * @Date:2018-11-12T16:28:06+0800 */ private function CLICK() { return false; } /** * 关注事件 * @Author: * @Date:2018-11-12T16:27:51+0800 */ private function subscribe() { $app = app('wechat.official_account'); $user = $app->user->get($this->payload['FromUserName']); // 先查找用户是否存在,不存在再注册 $existUser = User::where('openid', $this->payload['FromUserName'])->first(); if ($existUser) { $existUser->update([ 'info' => [ 'headimgurl' => $user['headimgurl'], 'sex' => $user['sex'], 'country' => $user['country'], 'province' => $user['province'], 'city' => $user['city'], 'subscribe_at' => $user['subscribe_time'], 'subscribe_scene' => $user['subscribe_scene'], // 'qr_scene' => $user['qr_scene'], // 'qr_scene_str' => $user['qr_scene_str'], ], ]); return $this->firstSubscribeMessage($existUser); } } public function VIEW() { #Todo.. } public function LOCATION() { #Todo.. } /** * 取消关注事件 * @Author: * @Date:2018-12-12T13:44:54+0800 * @return [type] [description] */ private function unsubscribe() { $existUser = User::where('openid', $this->payload['FromUserName'])->first(); if ($existUser) { $existUser->update([ 'info' => [ 'subscribe_at' => null, // 'subscribe_scene' => null, ], ]); } } private function firstSubscribeMessage($user) { $text = new Text('您好,欢迎关注连卡蝠'); return $text; } }