修改微信菜单

This commit is contained in:
Anyon 2019-12-10 10:34:52 +08:00
parent e9c36078dc
commit e7bcba6d86
9 changed files with 32 additions and 23 deletions

View File

@ -30,7 +30,7 @@ class Menu extends Controller
* 微信菜单的类型
* @var array
*/
protected $menuType = [
protected $menuTypes = [
'click' => '匹配规则',
'view' => '跳转网页',
'miniprogram' => '打开小程序',
@ -54,12 +54,11 @@ class Menu extends Controller
public function index()
{
if ($this->request->get('output') === 'json') {
$where = [['keys', 'notin', ['subscribe', 'default']], ['status', 'eq', '1']];
$where = [['keys', 'notin', ['subscribe', 'default']], ['status', '=', '1']];
$keys = $this->app->db->name('WechatKeys')->where($where)->order('sort desc,id desc')->select();
$this->success('获取数据成功!', ['menudata' => sysdata('menudata'), 'keysdata' => $keys]);
} else {
$this->title = '微信菜单定制';
$this->menuTypes = $this->menuType;
$this->fetch();
}
}
@ -68,7 +67,7 @@ class Menu extends Controller
* 编辑微信菜单
* @auth true
*/
public function edit()
public function push()
{
if ($this->request->isPost()) {
$data = $this->request->post('data');
@ -85,7 +84,7 @@ class Menu extends Controller
}
} else {
try {
sysdata('menudata', $this->_buildMenuData($menudata = json_decode($data, true)));
sysdata('menudata', $this->_buildMenuData(json_decode($data, true)));
WechatService::WeChatMenu()->create(['button' => sysdata('menudata')]);
sysoplog('微信管理', '发布微信菜单成功');
$this->success('保存发布菜单成功!', '');
@ -104,7 +103,7 @@ class Menu extends Controller
* @param array $list
* @return array
*/
private function _buildMenuData(array $list)
private function _buildMenuData(array $list): array
{
foreach ($list as &$vo) {
unset($vo['active'], $vo['show']);
@ -155,12 +154,12 @@ class Menu extends Controller
{
try {
WechatService::WeChatMenu()->delete();
$this->success('菜单取消成功,重新关注可立即生效!', '');
$this->success('菜单取消成功,重新关注可立即生效!');
} catch (HttpResponseException $exception) {
sysoplog('微信管理', '取消微信菜单成功');
throw $exception;
} catch (\Exception $e) {
$this->error("菜单取消失败,请稍候再试!<br> {$e->getMessage()}");
} catch (\Exception $exception) {
$this->error("菜单取消失败,请稍候再试!<br> {$exception->getMessage()}");
}
}

View File

@ -96,7 +96,7 @@
</div>
<div class="text-center margin-top-20">
{if auth("edit")}
{if auth("push")}
<button class="layui-btn menu-submit" ng-click="submit()">保存发布</button>
{/if}
{if auth("cancel")}
@ -194,7 +194,7 @@
$rootScope.submit = function () {
$vali.checkAllInput();
if ($form.find('.validate-error').size() > 0) return false;
$.form.load('{:url("edit")}', {data: angular.toJson($rootScope.list)}, 'post');
$.form.load('{:url("push")}', {data: angular.toJson($rootScope.list)}, 'post');
}
}
})

8
composer.lock generated
View File

@ -909,12 +909,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "1246ce655df8db112a60bf57037a9a17f4b11d77"
"reference": "030a60c13c6d8d15a6ce507edaf47ee384835983"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/1246ce655df8db112a60bf57037a9a17f4b11d77",
"reference": "1246ce655df8db112a60bf57037a9a17f4b11d77",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/030a60c13c6d8d15a6ce507edaf47ee384835983",
"reference": "030a60c13c6d8d15a6ce507edaf47ee384835983",
"shasum": "",
"mirrors": [
{
@ -958,7 +958,7 @@
],
"description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top",
"time": "2019-12-09T10:17:25+00:00"
"time": "2019-12-10T02:15:54+00:00"
},
{
"name": "zoujingli/wechat-developer",

View File

@ -202,6 +202,11 @@ return array(
'app\\admin\\controller\\api\\Update' => $baseDir . '/app/admin/controller/api/Update.php',
'app\\admin\\controller\\api\\Upload' => $baseDir . '/app/admin/controller/api/Upload.php',
'app\\index\\controller\\Index' => $baseDir . '/app/index/controller/Index.php',
'app\\wechat\\command\\Fans' => $baseDir . '/app/wechat/command/Fans.php',
'app\\wechat\\command\\fans\\FansAll' => $baseDir . '/app/wechat/command/fans/FansAll.php',
'app\\wechat\\command\\fans\\FansBlack' => $baseDir . '/app/wechat/command/fans/FansBlack.php',
'app\\wechat\\command\\fans\\FansList' => $baseDir . '/app/wechat/command/fans/FansList.php',
'app\\wechat\\command\\fans\\FansTags' => $baseDir . '/app/wechat/command/fans/FansTags.php',
'app\\wechat\\controller\\Config' => $baseDir . '/app/wechat/controller/Config.php',
'app\\wechat\\controller\\Fans' => $baseDir . '/app/wechat/controller/Fans.php',
'app\\wechat\\controller\\Keys' => $baseDir . '/app/wechat/controller/Keys.php',

View File

@ -342,6 +342,11 @@ class ComposerStaticInitada0e677dd8f1307ba83d0cf07626e6c
'app\\admin\\controller\\api\\Update' => __DIR__ . '/../..' . '/app/admin/controller/api/Update.php',
'app\\admin\\controller\\api\\Upload' => __DIR__ . '/../..' . '/app/admin/controller/api/Upload.php',
'app\\index\\controller\\Index' => __DIR__ . '/../..' . '/app/index/controller/Index.php',
'app\\wechat\\command\\Fans' => __DIR__ . '/../..' . '/app/wechat/command/Fans.php',
'app\\wechat\\command\\fans\\FansAll' => __DIR__ . '/../..' . '/app/wechat/command/fans/FansAll.php',
'app\\wechat\\command\\fans\\FansBlack' => __DIR__ . '/../..' . '/app/wechat/command/fans/FansBlack.php',
'app\\wechat\\command\\fans\\FansList' => __DIR__ . '/../..' . '/app/wechat/command/fans/FansList.php',
'app\\wechat\\command\\fans\\FansTags' => __DIR__ . '/../..' . '/app/wechat/command/fans/FansTags.php',
'app\\wechat\\controller\\Config' => __DIR__ . '/../..' . '/app/wechat/controller/Config.php',
'app\\wechat\\controller\\Fans' => __DIR__ . '/../..' . '/app/wechat/controller/Fans.php',
'app\\wechat\\controller\\Keys' => __DIR__ . '/../..' . '/app/wechat/controller/Keys.php',

View File

@ -935,12 +935,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "1246ce655df8db112a60bf57037a9a17f4b11d77"
"reference": "030a60c13c6d8d15a6ce507edaf47ee384835983"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/1246ce655df8db112a60bf57037a9a17f4b11d77",
"reference": "1246ce655df8db112a60bf57037a9a17f4b11d77",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/030a60c13c6d8d15a6ce507edaf47ee384835983",
"reference": "030a60c13c6d8d15a6ce507edaf47ee384835983",
"shasum": "",
"mirrors": [
{
@ -956,7 +956,7 @@
"ext-json": "*",
"topthink/framework": "^6.0"
},
"time": "2019-12-09T10:17:25+00:00",
"time": "2019-12-10T02:15:54+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2019-12-09 18:41:34
// This file is automatically generated at:2019-12-10 10:17:59
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',

View File

@ -100,9 +100,9 @@ if (!function_exists('sysdata')) {
function sysdata($name, $value = null)
{
if (is_null($value)) {
return SystemService::instance()->get($name);
return SystemService::instance()->getData($name);
} else {
return SystemService::instance()->set($name, $value);
return SystemService::instance()->setData($name, $value);
}
}
}

View File

@ -46,7 +46,7 @@ class TokenService extends Service
// 读取缓存并检查是否有效
$cache = $this->app->session->get($token, []);
if (empty($cache['node']) || empty($cache['time']) || empty($cache['token'])) return false;
if ($cache['token'] !== $token || $cache['time'] + 600 < time() || $cache['node'] !== $node) return false;
if ($cache['time'] + 600 < time() || strtolower($cache['node']) !== strtolower($node)) return false;
return true;
}