新增事件消息

This commit is contained in:
JaguarJack
2020-06-26 22:08:01 +08:00
parent a232f555c3
commit bcd7215333
19 changed files with 420 additions and 57 deletions

View File

@@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class Factory
{
/**
* 对象生产
*
* @time 2020年06月26日
* @param $message
* @return mixed
*/
public static function make($message)
{
return self::parse($message);
}
/**
* 解析
*
* @time 2020年06月26日
* @param $message
* @return mixed
*/
protected static function parse($message)
{
// 事件类型
if ($message['MsgType'] == 'event') {
$event = __NAMESPACE__ . '\\events\\' . ucfirst($message['Event']);
return new $event($message);
}
$messageClass = __NAMESPACE__ . '\\' . ucfirst($message['MsgType']);
return new $messageClass($message);
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class Image extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class Link extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class Location extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,74 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
use think\helper\Str;
abstract class Message
{
protected $message;
public function __construct(array $message)
{
$this->message = $message;
}
/**
* 接收方账号
*
* @time 2020年06月26日
* @return mixed
*/
protected function toUserName()
{
return $this->message['ToUserName'];
}
/**
* 发送方账号
*
* @time 2020年06月26日
* @return mixed
*/
protected function fromUserName()
{
return $this->message['FromUserName'];
}
abstract public function reply();
/**
* 访问消息内容
*
* @time 2020年06月26日
* @param $name
* @return mixed
*/
public function __get($name)
{
// TODO: Implement __get() method.
return $this->message[Str::camel($name)];
}
/**
* 访问消息内容
*
* @time 2020年06月26日
* @param $name
* @param $arguments
* @return mixed
*/
public function __call($name, $arguments)
{
// TODO: Implement __call() method.
return $this->message[lcfirst($name)];
}
}

View File

@@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class ShortVideo extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class Text extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class Video extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages;
class Voice extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,21 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages\events;
use catchAdmin\wechat\library\messages\Message;
class Click extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,21 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages\events;
use catchAdmin\wechat\library\messages\Message;
class Location extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,21 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages\events;
use catchAdmin\wechat\library\messages\Message;
class Scan extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}

View File

@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages\events;
use catchAdmin\wechat\library\messages\Message;
use catchAdmin\wechat\model\WechatUsers;
use catcher\library\WeChat;
/**
* 订阅事件
*
* Class Subscribe
* @package catchAdmin\wechat\library\messages\events
*/
class Subscribe extends Message
{
public function reply()
{
// TODO: Implement reply() method.
$wechatUser = WechatUsers::onlyTrashed()->where('openid', $this->fromUserName())->find();
if ($wechatUser) {
return $wechatUser->restore();
}
$user = WeChat::officialAccount()->user->get($this->fromUserName());
$user['avatar'] = $user['headimgurl'];
$user['unionid'] = $user['unionid'] ?? '';
$user['created_at'] = time();
$user['updated_at'] = time();
if (!empty($user['tagid_list'])) {
$user['tagid_list'] = trim(implode(',', $user['tagid_list']), ',');
}
unset($user['headimgurl'], $user['qr_scene'], $user['qr_scene_str']);
if (app(WechatUsers::class)->storeBy($user)) {
return '谢谢你的关注';
}
return false;
}
}

View File

@@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages\events;
use catchAdmin\wechat\library\messages\Message;
use catchAdmin\wechat\model\WechatUsers;
/**
* 取消订阅事件
*
* Class Unsubscribe
* @package catchAdmin\wechat\library\messages\events
*/
class Unsubscribe extends Message
{
public function reply()
{
// TODO: Implement reply() method.
WechatUsers::where('openid', $this->fromUserName())->find()->delete();
}
}

View File

@@ -0,0 +1,21 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\wechat\library\messages\events;
use catchAdmin\wechat\library\messages\Message;
class View extends Message
{
public function reply()
{
// TODO: Implement reply() method.
}
}