更新代码
This commit is contained in:
112
app/Http/WechatHandlers/EventMessageHandler.php
Normal file
112
app/Http/WechatHandlers/EventMessageHandler.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use App\User;
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
// use EasyWeChat\Kernel\Messages\News;
|
||||
// use EasyWeChat\Kernel\Messages\NewsItem;
|
||||
use EasyWeChat\Kernel\Messages\Image;
|
||||
|
||||
class EventMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
private $payload;
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
if (method_exists($this, $payload->Event)) {
|
||||
$this->payload = $payload;
|
||||
return call_user_func_array([$this, $payload->Event], []);
|
||||
} else {
|
||||
return '暂不支持的消息类型';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码事件
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-12T16:28:19+0800
|
||||
*/
|
||||
private function SCAN()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单点击
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-12T16:28:06+0800
|
||||
*/
|
||||
private function CLICK()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关注事件
|
||||
* @Author:<C.Jason>
|
||||
* @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:<Leady>
|
||||
* @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)
|
||||
{
|
||||
$mediaId = 'fysQHODFoeIoO-ZEDRFVBmtkCAjqXnYco1HeyFKy_kg';
|
||||
$text = new Image($mediaId);
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
26
app/Http/WechatHandlers/FileMessageHandler.php
Normal file
26
app/Http/WechatHandlers/FileMessageHandler.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class FileMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
$payload->ToUserName;
|
||||
$payload->FromUserName;
|
||||
$payload->CreateTime;
|
||||
$payload->MsgId;
|
||||
|
||||
$payload->Title;
|
||||
$payload->Description;
|
||||
$payload->FileKey;
|
||||
$payload->FileMd5;
|
||||
$payload->FileTotalLen;
|
||||
|
||||
return '文件消息';
|
||||
}
|
||||
}
|
||||
23
app/Http/WechatHandlers/ImageMessageHandler.php
Normal file
23
app/Http/WechatHandlers/ImageMessageHandler.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class ImageMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
$payload->ToUserName;
|
||||
$payload->FromUserName;
|
||||
$payload->CreateTime;
|
||||
$payload->MsgId;
|
||||
|
||||
$payload->MediaId;
|
||||
$payload->PicUrl;
|
||||
|
||||
return '图片消息';
|
||||
}
|
||||
}
|
||||
24
app/Http/WechatHandlers/LinkMessageHandler.php
Normal file
24
app/Http/WechatHandlers/LinkMessageHandler.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class LinkMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
$payload->ToUserName;
|
||||
$payload->FromUserName;
|
||||
$payload->CreateTime;
|
||||
$payload->MsgId;
|
||||
|
||||
$payload->Title;
|
||||
$payload->Description;
|
||||
$payload->Url;
|
||||
|
||||
return '链接消息';
|
||||
}
|
||||
}
|
||||
24
app/Http/WechatHandlers/LocationMessageHandler.php
Normal file
24
app/Http/WechatHandlers/LocationMessageHandler.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class LocationMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
$payload->ToUserName;
|
||||
$payload->FromUserName;
|
||||
$payload->CreateTime;
|
||||
$payload->MsgId;
|
||||
|
||||
$payload->Latitude;
|
||||
$payload->Longitude;
|
||||
$payload->Precision;
|
||||
|
||||
return '上报位置消息';
|
||||
}
|
||||
}
|
||||
23
app/Http/WechatHandlers/ShortVideoMessageHandler.php
Normal file
23
app/Http/WechatHandlers/ShortVideoMessageHandler.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class ShortVideoMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
$payload->ToUserName;
|
||||
$payload->FromUserName;
|
||||
$payload->CreateTime;
|
||||
$payload->MsgId;
|
||||
|
||||
$payload->MediaId;
|
||||
$payload->ThumbMediaId;
|
||||
|
||||
return '短视频消息';
|
||||
}
|
||||
}
|
||||
15
app/Http/WechatHandlers/TextMessageHandler.php
Normal file
15
app/Http/WechatHandlers/TextMessageHandler.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class TextMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
return '您的留言已经收到';
|
||||
return $payload->Content;
|
||||
}
|
||||
}
|
||||
14
app/Http/WechatHandlers/TransferMessageHandler.php
Normal file
14
app/Http/WechatHandlers/TransferMessageHandler.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class TransferMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
return '客服消息' . json_encode($payload);
|
||||
}
|
||||
}
|
||||
23
app/Http/WechatHandlers/VideoMessageHandler.php
Normal file
23
app/Http/WechatHandlers/VideoMessageHandler.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class VideoMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
$payload->ToUserName;
|
||||
$payload->FromUserName;
|
||||
$payload->CreateTime;
|
||||
$payload->MsgId;
|
||||
|
||||
$payload->MediaId;
|
||||
$payload->ThumbMediaId;
|
||||
|
||||
return '视频消息';
|
||||
}
|
||||
}
|
||||
24
app/Http/WechatHandlers/VoiceMessageHandler.php
Normal file
24
app/Http/WechatHandlers/VoiceMessageHandler.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\WechatHandlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
|
||||
class VoiceMessageHandler implements EventHandlerInterface
|
||||
{
|
||||
|
||||
public function handle($payload = null)
|
||||
{
|
||||
|
||||
$payload->ToUserName;
|
||||
$payload->FromUserName;
|
||||
$payload->CreateTime;
|
||||
$payload->MsgId;
|
||||
|
||||
$payload->MediaId;
|
||||
$payload->Format;
|
||||
$payload->Recognition;
|
||||
|
||||
return '语音消息';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user