过滤快速创建小程序的重复消息

dev
李春波 1 year ago
parent 1c323ca498
commit 2c0db79cd5
  1. 3
      app/common/service/Yinghuo.php
  2. 12
      app/common/service/wechat/OpenPlatform.php
  3. 6
      app/wechat/controller/IndexController.php

@ -140,7 +140,8 @@ class Yinghuo
"form" => [
"enabled" => true,
"app_id" => $appid,
"app_secret" => "fastRegisterApp"
"app_secret" => "fastRegisterApp",
"enableShipping" => false,
]
];
return $this->curl('/store/client.wxapp.setting/update', $data, 'store');

@ -8,6 +8,7 @@ use app\common\service\BaseServices;
use EasyWeChat\Factory;
use EasyWeChat\OpenPlatform\Application;
use support\Log;
use support\Cache;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use think\db\exception\DataNotFoundException;
@ -76,8 +77,16 @@ class OpenPlatform extends BaseServices {
$this->addComponentCallBackRecord($message);
switch ($message['InfoType']) {
case 'notify_third_fastregisterbetaapp':
// 过滤掉重复请求
$key = 'wechat_mp_' . md5(json_encode($message));
if (Cache::has($key)) {
Log::info('收到重复注册试用小程序请求,已过滤');
return 'success';
} else {
Cache::set($key, '', 10);
}
FastRegisterApp::callback($message);
break;
return 'success';
case 'authorized':
case 'updateauthorized':
$this->addAuthorizerInfo($message);
@ -89,6 +98,7 @@ class OpenPlatform extends BaseServices {
break;
}
}
return 'success';
});
// 消息与事件通知 日志记录
$message = $this->app->server->getMessage();

@ -27,12 +27,12 @@ class IndexController extends BaseController
$key = 'wechat_mp_' . md5(json_encode($xml));
if (Cache::has($key)) {
Log::info('收到重复请求,已过滤');
return '请求重复';
return 'success';
} else {
Cache::set($key, '', 3);
Cache::set($key, '', 10);
}
$xml = simplexml_load_string($xml);
if (empty($xml)) return '请求体为空';
if (empty($xml)) return 'success';
if ($appid) {
// 转发消息与事件推送请求给第三方
$forwardResult = Forward::run($request, $appid, 'app');

Loading…
Cancel
Save