Skip to content

Commit be33d38

Browse files
committed
feat(后台): 增加微信公众平台配置面板
1 parent 08b2b9b commit be33d38

File tree

8 files changed

+200
-1
lines changed

8 files changed

+200
-1
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* +----------------------------------------------------------------------+
7+
* | ThinkSNS Plus |
8+
* +----------------------------------------------------------------------+
9+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
10+
* +----------------------------------------------------------------------+
11+
* | This source file is subject to version 2.0 of the Apache license, |
12+
* | that is bundled with this package in the file LICENSE, and is |
13+
* | available through the world-wide-web at the following url: |
14+
* | http://www.apache.org/licenses/LICENSE-2.0.html |
15+
* +----------------------------------------------------------------------+
16+
* | Author: Slim Kit Group <master@zhiyicx.com> |
17+
* | Homepage: www.thinksns.com |
18+
* +----------------------------------------------------------------------+
19+
*/
20+
21+
namespace Zhiyi\Plus\Admin\Controllers\Setting;
22+
23+
use Illuminate\Http\Response;
24+
use function Zhiyi\Plus\setting;
25+
use Illuminate\Http\JsonResponse;
26+
use Zhiyi\Plus\Admin\Controllers\Controller;
27+
use Zhiyi\Plus\Admin\Requests\SetWeChatMpConfigure as SetWeChatMpConfigureRequest;
28+
29+
class WeChatMp extends Controller
30+
{
31+
/**
32+
* Get configure.
33+
* @return \Illuminate\Http\JsonResponse
34+
*/
35+
public function getConfigure(): JsonResponse
36+
{
37+
$settings = setting('user', 'vendor:wechat-mp', [
38+
'appid' => '',
39+
'secret' => '',
40+
]);
41+
42+
return new JsonResponse($settings, Response::HTTP_OK);
43+
}
44+
45+
/**
46+
* set configure.
47+
* @param \Zhiyi\Plus\Admin\Requests\SetWeChatMpConfigure $request
48+
* @return \Illuminate\Http\Response
49+
*/
50+
public function setConfigure(SetWeChatMpConfigureRequest $request)
51+
{
52+
setting('user')->set('vendor:wechat-mp', [
53+
'appid' => $request->input('appid'),
54+
'secret' => $request->input('secret'),
55+
]);
56+
57+
return new Response('', Response::HTTP_NO_CONTENT);
58+
}
59+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* +----------------------------------------------------------------------+
7+
* | ThinkSNS Plus |
8+
* +----------------------------------------------------------------------+
9+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
10+
* +----------------------------------------------------------------------+
11+
* | This source file is subject to version 2.0 of the Apache license, |
12+
* | that is bundled with this package in the file LICENSE, and is |
13+
* | available through the world-wide-web at the following url: |
14+
* | http://www.apache.org/licenses/LICENSE-2.0.html |
15+
* +----------------------------------------------------------------------+
16+
* | Author: Slim Kit Group <master@zhiyicx.com> |
17+
* | Homepage: www.thinksns.com |
18+
* +----------------------------------------------------------------------+
19+
*/
20+
21+
namespace Zhiyi\Plus\Admin\Requests;
22+
23+
use Illuminate\Foundation\Http\FormRequest;
24+
25+
class SetWeChatMpConfigure extends FormRequest
26+
{
27+
/**
28+
* Determine if the user is authorized to make this request.
29+
*
30+
* @return bool
31+
* @author Seven Du <shiweidu@outlook.com>
32+
*/
33+
public function authorize(): bool
34+
{
35+
return true;
36+
}
37+
38+
/**
39+
* Get the validation rules that apply to the request.
40+
*
41+
* @return array
42+
* @author Seven Du <shiweidu@outlook.com>
43+
*/
44+
public function rules(): array
45+
{
46+
return [
47+
'appid' => 'required|string',
48+
'secret' => 'required|string',
49+
];
50+
}
51+
}

resources/assets/admin/api/vendor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export const easemob = new VendorRequestGenerator('setting/vendor/easemob');
2525
export const qq = new VendorRequestGenerator('setting/vendor/qq');
2626
export const wechat = new VendorRequestGenerator('setting/vendor/wechat');
2727
export const weibo = new VendorRequestGenerator('setting/vendor/weibo');
28+
export const wechatMp = new VendorRequestGenerator('setting/vendor/wechat-mp');
2829

resources/assets/admin/component/User.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/weibo' }">
4848
<a href="#">微博登录</a>
4949
</router-link>
50+
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/wechat-mp' }">
51+
<a href="#">微信公众平台</a>
52+
</router-link>
5053
<li class="divider"></li>
5154
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/easemob' }">
5255
<a href="#">环信即时聊天</a>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { default as Easemob } from './easemob';
22
export { default as QQ } from './qq';
33
export { default as WeChat } from './wechat';
4-
export { default as Weibo } from './weibo';
4+
export { default as Weibo } from './weibo';
5+
export { default as WeChatMp } from './wechat-mp';
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<template>
2+
<div class="container-fluid">
3+
<div class="row">
4+
<div class="col-md-7">
5+
<div class="panel panel-default">
6+
<div class="panel-heading">微信公众平台</div>
7+
<div class="panel-body">
8+
<sb-ui-loading v-if="loading" />
9+
<form class="form-horizontal" v-else>
10+
11+
<!-- app id -->
12+
<div class="form-group">
13+
<label class="col-sm-3 control-label">APP ID</label>
14+
<div class="col-sm-9">
15+
<input type="text" class="form-control" v-model="form.appid">
16+
</div>
17+
</div>
18+
19+
<!-- Secret -->
20+
<div class="form-group">
21+
<label class="col-sm-3 control-label">Secret</label>
22+
<div class="col-sm-9">
23+
<input type="text" class="form-control" v-model="form.secret">
24+
</div>
25+
</div>
26+
27+
<!-- 提交按钮 -->
28+
<div class="form-group">
29+
<div class="col-sm-9 col-sm-offset-3">
30+
<ui-button type="button" class="btn btn-primary" @click="onSubmit" />
31+
</div>
32+
</div>
33+
34+
</form>
35+
</div>
36+
</div>
37+
</div>
38+
<div class="col-md-5">
39+
<div class="panel panel-default">
40+
<div class="panel-heading">帮助</div>
41+
<div class="panel-body">
42+
请前往「<a target="_blank" href="https://mp.weixin.qq.com/">微信公众平台</a>」进行申请。
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
</template>
49+
50+
<script>
51+
import { wechatMp } from '../../api/vendor';
52+
export default {
53+
data: () => ({
54+
form: {
55+
appid: '',
56+
secret: '',
57+
},
58+
loading: true,
59+
}),
60+
methods: {
61+
onSubmit(event) {
62+
wechatMp.update(this.form).then(() => {
63+
this.$store.dispatch("alert-open", { type: "success", message: '提交成功' });
64+
}).catch(({ response: { data: message = "提交失败,请刷新页面重试!" } }) => {
65+
this.$store.dispatch("alert-open", { type: "danger", message });
66+
}).finally(event.stopProcessing);
67+
}
68+
},
69+
created() {
70+
wechatMp.get().then(({ data }) => {
71+
this.loading = false;
72+
this.form = data;
73+
}).catch(({ response: { data: message = "获取失败,请刷新页面重试!" } }) => {
74+
this.$store.dispatch("alert-open", { type: "danger", message });
75+
});
76+
}
77+
}
78+
</script>
79+

resources/assets/admin/router/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const routers = {
3535
{ path: 'vendor-qq', component: vendorPages.QQ, name: 'user:vendor/qq' },
3636
{ path: 'vendor-wechat', component: vendorPages.WeChat, name: 'user:vendor/wechat' },
3737
{ path: 'vendor-weibo', component: vendorPages.Weibo, name: 'user:vendor/weibo' },
38+
{ path: 'vendor-wechat-mp', component: vendorPages.WeChatMp, name: 'user:vendor/wechat-mp' },
3839
]
3940
};
4041

routes/new-admin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@
6969
// 微博配置
7070
$route->get('setting/vendor/weibo', AdminControllers\Setting\Weibo::class.'@getConfigure');
7171
$route->put('setting/vendor/weibo', AdminControllers\Setting\Weibo::class.'@setConfigure');
72+
73+
// 微信公众平台
74+
$route->get('setting/vendor/wechat-mp', AdminControllers\Setting\WeChatMp::class.'@getConfigure');
75+
$route->put('setting/vendor/wechat-mp', AdminControllers\Setting\WeChatMp::class.'@setConfigure');
7276
});

0 commit comments

Comments
 (0)