调整架构,新增微信模块服务
This commit is contained in:
parent
0e7453a6fe
commit
2d95212973
@ -2,22 +2,46 @@
|
|||||||
namespace catchAdmin\wechat;
|
namespace catchAdmin\wechat;
|
||||||
|
|
||||||
use catchAdmin\wechat\command\SyncUsersCommand;
|
use catchAdmin\wechat\command\SyncUsersCommand;
|
||||||
|
use catcher\ModuleService;
|
||||||
use think\Service;
|
use think\Service;
|
||||||
|
|
||||||
class CatchWechatService extends Service
|
class CatchWechatService extends ModuleService
|
||||||
{
|
{
|
||||||
public function boot()
|
/**
|
||||||
{}
|
* register
|
||||||
|
*
|
||||||
|
* @time 2020年06月24日
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
|
parent::register();
|
||||||
|
|
||||||
$this->registerCommand();
|
$this->registerCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* register command
|
||||||
|
*
|
||||||
|
* @time 2020年06月24日
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function registerCommand()
|
public function registerCommand()
|
||||||
{
|
{
|
||||||
$this->commands([
|
$this->commands([
|
||||||
SyncUsersCommand::class,
|
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 ]
|
// | 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()
|
public function index()
|
||||||
{
|
{
|
||||||
|
dd(WeChat::officialAccount()->server->serve()->send());
|
||||||
return CatchResponse::paginate($this->user->getList());
|
return CatchResponse::paginate($this->user->getList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,3 +8,36 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
// | 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": "微信管理",
|
"name": "微信管理",
|
||||||
"alias": "wechat",
|
"alias": "wechat",
|
||||||
"description": "catchadmin 微信管理模块",
|
"description": "catchadmin 微信管理模块",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"wechat", "module"
|
"wechat",
|
||||||
],
|
"module"
|
||||||
"order": 2,
|
],
|
||||||
"services": ["\\catchAdmin\\wechat\\CatchWechatService"],
|
"order": 2,
|
||||||
"aliases": "wechat",
|
"services": [
|
||||||
"files": [],
|
"\\catchAdmin\\wechat\\CatchWechatService"
|
||||||
"requires": []
|
],
|
||||||
|
"aliases": "wechat",
|
||||||
|
"files": [],
|
||||||
|
"requires": [],
|
||||||
|
"enable": true
|
||||||
}
|
}
|
@ -23,5 +23,7 @@ $router->group('wechat', function () use ($router){
|
|||||||
$router->resource('', '\catchAdmin\wechat\controller\Tags');
|
$router->resource('', '\catchAdmin\wechat\controller\Tags');
|
||||||
$router->get('sync', '\catchAdmin\wechat\controller\Tags@sync');
|
$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