调整架构,新增微信模块服务
This commit is contained in:
parent
0e7453a6fe
commit
2d95212973
@ -2,22 +2,46 @@
|
||||
namespace catchAdmin\wechat;
|
||||
|
||||
use catchAdmin\wechat\command\SyncUsersCommand;
|
||||
use catcher\ModuleService;
|
||||
use think\Service;
|
||||
|
||||
class CatchWechatService extends Service
|
||||
class CatchWechatService extends ModuleService
|
||||
{
|
||||
public function boot()
|
||||
{}
|
||||
|
||||
/**
|
||||
* register
|
||||
*
|
||||
* @time 2020年06月24日
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
parent::register();
|
||||
|
||||
$this->registerCommand();
|
||||
}
|
||||
|
||||
/**
|
||||
* register command
|
||||
*
|
||||
* @time 2020年06月24日
|
||||
* @return void
|
||||
*/
|
||||
public function registerCommand()
|
||||
{
|
||||
$this->commands([
|
||||
SyncUsersCommand::class,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* loaded router from
|
||||
*
|
||||
* @time 2020年06月24日
|
||||
* @return string
|
||||
*/
|
||||
public function loadRouteFrom()
|
||||
{
|
||||
// TODO: Implement loadRouteFrom() method.
|
||||
return __DIR__ . DIRECTORY_SEPARATOR . 'route.php';
|
||||
}
|
||||
}
|
@ -8,3 +8,32 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace catchAdmin\wechat\controller;
|
||||
|
||||
use catcher\base\CatchController;
|
||||
use catcher\library\WeChat;
|
||||
use think\Request;
|
||||
|
||||
class Message extends CatchController
|
||||
{
|
||||
public function done(Request $request)
|
||||
{
|
||||
if ($request->isPost()) {
|
||||
WeChat::officialAccount()->server->push(function ($message) {
|
||||
switch ($message['MsgType']) {
|
||||
case 'subscribe':
|
||||
return '收到事件消息';
|
||||
break;
|
||||
case 'unsubscribe':
|
||||
return '收到文字消息';
|
||||
break;
|
||||
case 'image':
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
return '';
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,7 @@ class Users extends CatchController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
dd(WeChat::officialAccount()->server->serve()->send());
|
||||
return CatchResponse::paginate($this->user->getList());
|
||||
}
|
||||
|
||||
|
@ -8,3 +8,36 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace catchAdmin\wechat\controller;
|
||||
|
||||
use catcher\base\CatchController;
|
||||
use think\facade\Log;
|
||||
use think\Request;
|
||||
use catcher\library\WeChat as WechatServer;
|
||||
|
||||
class Wechat extends CatchController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$app = WechatServer::officialAccount();
|
||||
$app->server->push(function ($message) {
|
||||
switch ($message['MsgType']) {
|
||||
case 'event':
|
||||
file_put_contents(base_path() . DIRECTORY_SEPARATOR .'root.txt', json_encode((array)$message));
|
||||
return '收到事件消息了吗😄';
|
||||
break;
|
||||
case 'text':
|
||||
return '收到文字消息';
|
||||
break;
|
||||
case 'image':
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return '结束了';
|
||||
});
|
||||
|
||||
|
||||
$app->server->serve()->send();exit;
|
||||
}
|
||||
}
|
@ -1,13 +1,17 @@
|
||||
{
|
||||
"name": "微信管理",
|
||||
"alias": "wechat",
|
||||
"description": "catchadmin 微信管理模块",
|
||||
"keywords": [
|
||||
"wechat", "module"
|
||||
],
|
||||
"order": 2,
|
||||
"services": ["\\catchAdmin\\wechat\\CatchWechatService"],
|
||||
"aliases": "wechat",
|
||||
"files": [],
|
||||
"requires": []
|
||||
"name": "微信管理",
|
||||
"alias": "wechat",
|
||||
"description": "catchadmin 微信管理模块",
|
||||
"keywords": [
|
||||
"wechat",
|
||||
"module"
|
||||
],
|
||||
"order": 2,
|
||||
"services": [
|
||||
"\\catchAdmin\\wechat\\CatchWechatService"
|
||||
],
|
||||
"aliases": "wechat",
|
||||
"files": [],
|
||||
"requires": [],
|
||||
"enable": true
|
||||
}
|
@ -23,5 +23,7 @@ $router->group('wechat', function () use ($router){
|
||||
$router->resource('', '\catchAdmin\wechat\controller\Tags');
|
||||
$router->get('sync', '\catchAdmin\wechat\controller\Tags@sync');
|
||||
});
|
||||
});
|
||||
// 消息
|
||||
$router->rule('message', '\catchAdmin\wechat\controller\Message@done', 'GET|POST');
|
||||
})->middleware('auth');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user