Skip to content

Commit

Permalink
feat(后台): 增加微信公众平台配置面板
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Nov 28, 2018
1 parent 08b2b9b commit be33d38
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 1 deletion.
59 changes: 59 additions & 0 deletions app/Admin/Controllers/Setting/WeChatMp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to version 2.0 of the Apache license, |
* | that is bundled with this package in the file LICENSE, and is |
* | available through the world-wide-web at the following url: |
* | http://www.apache.org/licenses/LICENSE-2.0.html |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <[email protected]> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/

namespace Zhiyi\Plus\Admin\Controllers\Setting;

use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SetWeChatMpConfigure as SetWeChatMpConfigureRequest;

class WeChatMp extends Controller
{
/**
* Get configure.
* @return \Illuminate\Http\JsonResponse
*/
public function getConfigure(): JsonResponse
{
$settings = setting('user', 'vendor:wechat-mp', [
'appid' => '',
'secret' => '',
]);

return new JsonResponse($settings, Response::HTTP_OK);
}

/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SetWeChatMpConfigure $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SetWeChatMpConfigureRequest $request)
{
setting('user')->set('vendor:wechat-mp', [
'appid' => $request->input('appid'),
'secret' => $request->input('secret'),
]);

return new Response('', Response::HTTP_NO_CONTENT);
}
}
51 changes: 51 additions & 0 deletions app/Admin/Requests/SetWeChatMpConfigure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to version 2.0 of the Apache license, |
* | that is bundled with this package in the file LICENSE, and is |
* | available through the world-wide-web at the following url: |
* | http://www.apache.org/licenses/LICENSE-2.0.html |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <[email protected]> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/

namespace Zhiyi\Plus\Admin\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SetWeChatMpConfigure extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <[email protected]>
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <[email protected]>
*/
public function rules(): array
{
return [
'appid' => 'required|string',
'secret' => 'required|string',
];
}
}
1 change: 1 addition & 0 deletions resources/assets/admin/api/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export const easemob = new VendorRequestGenerator('setting/vendor/easemob');
export const qq = new VendorRequestGenerator('setting/vendor/qq');
export const wechat = new VendorRequestGenerator('setting/vendor/wechat');
export const weibo = new VendorRequestGenerator('setting/vendor/weibo');
export const wechatMp = new VendorRequestGenerator('setting/vendor/wechat-mp');

3 changes: 3 additions & 0 deletions resources/assets/admin/component/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/weibo' }">
<a href="#">微博登录</a>
</router-link>
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/wechat-mp' }">
<a href="#">微信公众平台</a>
</router-link>
<li class="divider"></li>
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/easemob' }">
<a href="#">环信即时聊天</a>
Expand Down
3 changes: 2 additions & 1 deletion resources/assets/admin/pages/user-vendor/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as Easemob } from './easemob';
export { default as QQ } from './qq';
export { default as WeChat } from './wechat';
export { default as Weibo } from './weibo';
export { default as Weibo } from './weibo';
export { default as WeChatMp } from './wechat-mp';
79 changes: 79 additions & 0 deletions resources/assets/admin/pages/user-vendor/wechat-mp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div class="container-fluid">
<div class="row">
<div class="col-md-7">
<div class="panel panel-default">
<div class="panel-heading">微信公众平台</div>
<div class="panel-body">
<sb-ui-loading v-if="loading" />
<form class="form-horizontal" v-else>

<!-- app id -->
<div class="form-group">
<label class="col-sm-3 control-label">APP ID</label>
<div class="col-sm-9">
<input type="text" class="form-control" v-model="form.appid">
</div>
</div>

<!-- Secret -->
<div class="form-group">
<label class="col-sm-3 control-label">Secret</label>
<div class="col-sm-9">
<input type="text" class="form-control" v-model="form.secret">
</div>
</div>

<!-- 提交按钮 -->
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<ui-button type="button" class="btn btn-primary" @click="onSubmit" />
</div>
</div>

</form>
</div>
</div>
</div>
<div class="col-md-5">
<div class="panel panel-default">
<div class="panel-heading">帮助</div>
<div class="panel-body">
请前往「<a target="_blank" href="https://mp.weixin.qq.com/">微信公众平台</a>」进行申请。
</div>
</div>
</div>
</div>
</div>
</template>

<script>
import { wechatMp } from '../../api/vendor';
export default {
data: () => ({
form: {
appid: '',
secret: '',
},
loading: true,
}),
methods: {
onSubmit(event) {
wechatMp.update(this.form).then(() => {
this.$store.dispatch("alert-open", { type: "success", message: '提交成功' });
}).catch(({ response: { data: message = "提交失败,请刷新页面重试!" } }) => {
this.$store.dispatch("alert-open", { type: "danger", message });
}).finally(event.stopProcessing);
}
},
created() {
wechatMp.get().then(({ data }) => {
this.loading = false;
this.form = data;
}).catch(({ response: { data: message = "获取失败,请刷新页面重试!" } }) => {
this.$store.dispatch("alert-open", { type: "danger", message });
});
}
}
</script>

1 change: 1 addition & 0 deletions resources/assets/admin/router/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const routers = {
{ path: 'vendor-qq', component: vendorPages.QQ, name: 'user:vendor/qq' },
{ path: 'vendor-wechat', component: vendorPages.WeChat, name: 'user:vendor/wechat' },
{ path: 'vendor-weibo', component: vendorPages.Weibo, name: 'user:vendor/weibo' },
{ path: 'vendor-wechat-mp', component: vendorPages.WeChatMp, name: 'user:vendor/wechat-mp' },
]
};

Expand Down
4 changes: 4 additions & 0 deletions routes/new-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@
// 微博配置
$route->get('setting/vendor/weibo', AdminControllers\Setting\Weibo::class.'@getConfigure');
$route->put('setting/vendor/weibo', AdminControllers\Setting\Weibo::class.'@setConfigure');

// 微信公众平台
$route->get('setting/vendor/wechat-mp', AdminControllers\Setting\WeChatMp::class.'@getConfigure');
$route->put('setting/vendor/wechat-mp', AdminControllers\Setting\WeChatMp::class.'@setConfigure');
});

0 comments on commit be33d38

Please sign in to comment.