-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from Qsnh/dev
Dev
- Loading branch information
Showing
53 changed files
with
2,177 additions
and
1,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Qsnh/meedu. | ||
* | ||
* (c) XiaoTeng <616896861@qq.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace App\Hooks; | ||
|
||
use App\Meedu\Hooks\HookParams; | ||
use App\Meedu\Hooks\HookRuntimeInterface; | ||
use App\Services\Other\Services\MpWechatService; | ||
use App\Services\Other\Interfaces\MpWechatServiceInterface; | ||
|
||
class MpWechatMessageReplyHook implements HookRuntimeInterface | ||
{ | ||
public const MSG_TYPE_TEXT = 'text'; | ||
public const MSG_TYPE_EVENT = 'event'; | ||
|
||
public function handle(HookParams $params, \Closure $next) | ||
{ | ||
$types = [self::MSG_TYPE_TEXT => 1, self::MSG_TYPE_EVENT => 1]; | ||
$msgType = $params->getValue('MsgType', ''); | ||
if (!isset($types[$msgType])) { | ||
return $next($params); | ||
} | ||
|
||
/** | ||
* @var HookParams $response | ||
*/ | ||
$response = $next($params); | ||
if ($response && $response->getResponse()) { | ||
// 如果已经有其它的中间件处理了该条消息并返回了值 | ||
// 那么这里就不需要继续处理了 | ||
// 当前中间件的权重是最低的 | ||
return $response; | ||
} | ||
|
||
/** | ||
* @var MpWechatService $mpWechatService | ||
*/ | ||
$mpWechatService = app()->make(MpWechatServiceInterface::class); | ||
|
||
try { | ||
if ($msgType === self::MSG_TYPE_TEXT) { | ||
// 文本消息 | ||
return $mpWechatService->textMessageReplyFind($params->getValue('raw.Content', '')); | ||
} elseif ($msgType === self::MSG_TYPE_EVENT) { | ||
// 事件消息 | ||
return $mpWechatService->eventMessageReplyFind($params->getValue('raw.Event'), $params->getValue('raw.EventKey')); | ||
} | ||
} catch (\Exception $e) { | ||
exception_record($e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Qsnh/meedu. | ||
* | ||
* (c) XiaoTeng <616896861@qq.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace App\Http\Controllers\Api\Wechat; | ||
|
||
use App\Meedu\Wechat; | ||
use App\Meedu\Hooks\HookRun; | ||
use App\Meedu\Hooks\HookParams; | ||
use App\Meedu\Hooks\Constant\PositionConstant; | ||
use App\Http\Controllers\Api\V2\BaseController; | ||
|
||
class MpWechatController extends BaseController | ||
{ | ||
public function serve() | ||
{ | ||
$mp = Wechat::getInstance(); | ||
$mp->server->push(function ($message) { | ||
return HookRun::run(PositionConstant::MP_WECHAT_RECEIVER_MESSAGE, new HookParams([ | ||
'MsgType' => $message['MsgType'], | ||
'ToUserName' => $message['ToUserName'], | ||
'FromUserName' => $message['FromUserName'], | ||
'CreateTime' => $message['CreateTime'], | ||
'MsgId' => $message['MsgId'], | ||
'raw' => $message, | ||
])); | ||
}); | ||
|
||
return $mp->server->serve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.