完成普通授权账号列表开发

master
李春波 2 years ago
parent 08ab5e024a
commit da1ac1e02e
  1. 38
      app/admin/controller/AuthorizerController.php
  2. 29
      app/admin/model/Authorizers.php
  3. 20
      app/common/model/Authorizers.php
  4. 65
      app/common/service/wechat/Authorizer.php
  5. 3
      app/common/service/wechat/OpenPlatform.php
  6. 5
      composer.json
  7. 2
      config/plugin/tinywan/exception-handler/app.php
  8. 22
      front/src/api/authorizer.js
  9. 40
      front/src/config/data.js
  10. 10
      front/src/utils/request.js
  11. 169
      front/src/views/authorizedAccountManage/authorizerList.vue
  12. 3
      front/vue.config.js

@ -0,0 +1,38 @@
<?php
namespace app\admin\controller;
use app\admin\model\Authorizers;
use app\common\service\wechat\Authorizer;
use support\Request;
use support\Response;
use think\db\exception\DbException;
use Tinywan\ExceptionHandler\Exception\BadRequestHttpException;
/**
* 授权账号管理
*/
class AuthorizerController extends BaseController
{
/**
* @throws BadRequestHttpException
*/
public function refresh(Request $request)
{
$appId = 'wx3a67b967164b59d1';
$openPlatformConfig = config("wechat.open_platform.$appId");
$authorizer = new Authorizer($openPlatformConfig);
$authorizer->refresh($request);
return success();
}
/**
* @param Request $request
* @return array|Response
* @throws DbException
*/
public function list(Request $request)
{
return success(Authorizers::list($request));
}
}

@ -0,0 +1,29 @@
<?php
namespace app\admin\model;
use app\common\model\Authorizers as AuthorizersModel;
use support\Request;
use think\db\exception\DbException;
/**
* @property mixed $id
*/
class Authorizers extends AuthorizersModel
{
/**
* @param Request $request
* @return array
* @throws DbException
*/
public static function list(Request $request): array
{
$params = self::buildWhere($request);
return self::where($params['where'])
->order('auth_time', 'desc')
->paginate([
'page' => $params['current_page'],
'list_rows' => $params['page_size']
])->toArray();
}
}

@ -0,0 +1,20 @@
<?php
namespace app\common\model;
/**
* 开放平台参数
*/
class Authorizers extends BaseModel
{
static protected array $column = [
['key' => 'name', 'name' => '公司名称'],
['key' => 'app_id', 'name' => 'app_id'],
];
protected $table = 'authorizers';
public function getAuthTimeAttr($value)
{
return date('Y-m-d H:i:s', $value);
}
}

@ -0,0 +1,65 @@
<?php
namespace app\common\service\wechat;
use app\admin\model\Authorizers;
use app\common\service\BaseServices;
use EasyWeChat\Factory;
use EasyWeChat\OpenPlatform\Application;
use think\facade\Db;
use Tinywan\ExceptionHandler\Exception\BadRequestHttpException;
class Authorizer extends BaseServices
{
public Application $app;
public function __construct($config)
{
$this->app = Factory::openPlatform($config);
}
/**
* 重新获取授权账号列表
* @param $request
* @throws BadRequestHttpException
*/
public function refresh($request)
{
try {
Db::startTrans();
$model = new Authorizers();
$model->where(true)->delete();
$list = $this->app->getAuthorizers();
$insert_data = [];
foreach ($list['list'] as $item) {
$program = $this->app->getAuthorizer($item['authorizer_appid']);
$program_authorizer_info = $program['authorizer_info'];
$program_authorization_info = $program['authorization_info'];
$insert_data[] = [
'appid' => $item['authorizer_appid'] ?? '',
'refreshtoken' => $item['refresh_token'] ?? '',
'auth_time' => $item['auth_time'] ?? '',
'app_type' => isset($program_authorizer_info['MiniProgramInfo']),
'nick_name' => $program_authorizer_info['nick_name'] ?? '',
'user_name' => $program_authorizer_info['user_name'] ?? '',
'head_img' => $program_authorizer_info['head_img'] ?? '',
'qrcode_url' => $program_authorizer_info['qrcode_url'] ?? '',
'principal_name' => $program_authorizer_info['principal_name'] ?? '',
'register_type' => $program_authorizer_info['register_type'] ?? '',
'verify_info' => $program_authorizer_info['verify_type_info']['id'] ?? '',
'service_type' => $program_authorizer_info['service_type_info']['id'] ?? '',
'account_status' => $program_authorizer_info['account_status'] ?? '',
'is_phone' => $program_authorizer_info['basic_config']['is_phone_configured'] ?? '',
'is_email' => $program_authorizer_info['basic_config']['is_email_configured'] ?? '',
'func_info' => $program_authorization_info['func_info'] ? json_encode($program_authorization_info['func_info'], JSON_UNESCAPED_UNICODE) : '',
'json_data' => json_encode($program, true),
];
}
$model->saveAll($insert_data);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
throw new BadRequestHttpException($e->getMessage());
}
}
}

@ -3,12 +3,11 @@ namespace app\common\service\wechat;
use app\common\service\BaseServices;
use EasyWeChat\Factory;
use EasyWeChat\OpenPlatform\Application;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class OpenPlatform extends BaseServices {
public Application $app;
public $app;
public function __construct($config)
{

@ -24,7 +24,7 @@
"source": "https://github.com/walkor/webman"
},
"require": {
"php": ">=7.2",
"php": ">=7.4",
"workerman/webman-framework": "^1.5.0",
"monolog/monolog": "^2.0",
"overtrue/wechat": "5.9.1",
@ -32,7 +32,8 @@
"ext-simplexml": "*",
"webman/think-orm": "^1.1",
"tinywan/jwt": "^1.8",
"tinywan/exception-handler": "^1.2"
"tinywan/exception-handler": "^1.2",
"ext-json": "*"
},
"suggest": {
"ext-event": "For better performance. "

@ -32,7 +32,7 @@ return [
],
// 事件,event 与 webman/event 存在冲突,event 重命名为 event_trigger
'event_trigger' => [
'enable' => true,
'enable' => false,
// 钉钉机器人
'dingtalk' => [
'accessToken' => '85b834cadc3905ee57ff6807f3b65eee1cac7a1f29296635d81c24f9850aa5ad',

@ -0,0 +1,22 @@
import request from '@/utils/request'
const api = {
Refresh: '/authorizer/refresh',
list: '/authorizer/list'
}
export function getAuthorizer(parameter) {
return request({
url: api.list,
method: 'post',
data: parameter
})
}
export function refresh(parameter) {
return request({
url: api.Refresh,
method: 'get',
params: parameter
})
}

@ -0,0 +1,40 @@
export default {
// 应用类型
app_type: {
0: '公众号',
1: '小程序'
},
// 注册方式
register_type: {
'-1': '未知',
0: '普通方式注册',
2: '通过复用公众号创建小程序api注册',
6: '通过法人扫脸创建企业小程序api注册',
13: '通过创建试用小程序api注册',
15: '通过联盟控制台注册',
16: '通过创建个人小程序api注册',
17: '通过创建个人交易小程序api注册',
19: '通过试用小程序转正api注册',
22: '通过复用商户号创建企业小程序api注册',
23: '通过复用商户号转正api注册'
},
// 账号状态
account_status: {
1: "正常",
14: "已注销",
16: "已封禁",
18: "已告警",
19: "已冻结"
},
// 是否
true_or_false: {
0: '否',
1: '是'
},
// 认证类型
verify_info: {
'-1': '未认证',
'0': '微信认证'
}
}

@ -10,7 +10,7 @@ import {ACCESS_TOKEN} from '@/store/mutation-types'
const request = axios.create({
// API 请求的默认前缀
baseURL: process.env.VUE_APP_API_BASE_URL,
timeout: 6000 // 请求超时时间
timeout: 60000 // 请求超时时间
})
// 异常拦截处理器
@ -19,10 +19,16 @@ const errorHandler = (error) => {
const data = error.response.data
// 从 localstorage 获取 token
const token = storage.get(ACCESS_TOKEN)
if (error.response.status === 400) {
notification.error({
message: 'Error',
description: data.msg || '请求异常 400'
})
}
if (error.response.status === 403) {
notification.error({
message: 'Forbidden',
description: data.message
description: data.msg || '请求异常 403'
})
} else if (error.response.status === 404) {
notification.error({

@ -30,7 +30,7 @@
</div>
<div class="table-operator">
<a-button icon="plus" type="primary" @click="handleAdd"></a-button>
<a-button :disabled="refreshButton" icon="plus" type="primary" @click="refresh"></a-button>
</div>
<s-table
@ -40,14 +40,33 @@
rowKey="id"
showPagination="auto"
size="default"
:scroll="{ x: 1000 }"
>
<span slot="action" slot-scope="text, record">
<span slot="app_type" slot-scope="text">
{{ enumData["app_type"][text] }}
</span>
<span slot="register_type" slot-scope="text">
{{ enumData["register_type"][text] }}
</span>
<span slot="account_status" slot-scope="text">
{{ enumData["account_status"][text] }}
</span>
<span slot="is_phone" slot-scope="text">
{{ enumData["true_or_false"][text] }}
</span>
<span slot="is_email" slot-scope="text">
{{ enumData["true_or_false"][text] }}
</span>
<span slot="verify_info" slot-scope="text">
{{ enumData["verify_info"][text] }}
</span>
<span slot="action" slot-scope="text">
<template>
<a @click="handleEdit(record)">编辑</a>
<a>获取token</a>
<a-divider type="vertical"/>
<a-popconfirm title="确定删除该记录吗?" @confirm="handleDel(record.id)">
<a>删除</a>
</a-popconfirm>
<a>复制refresh_token</a>
<a-divider type="vertical"/>
<a>原始报文</a>
</template>
</span>
</s-table>
@ -56,39 +75,85 @@
</template>
<script>
import data from "@/config/data";
import {Ellipsis, STable} from '@/components'
import {addPlatform, deletePlatform, editPlatform, getPlatform} from '@/api/platform'
import {getAuthorizer, refresh} from '@/api/authorizer'
import Message from "ant-design-vue/lib/message";
const columns = [
{
title: 'AppId',
dataIndex: 'appid',
width: 180
},
{
title: '名称',
dataIndex: 'name'
dataIndex: 'nick_name',
width: 200
},
{
title: 'app_id',
dataIndex: 'app_id'
title: '账号类型',
dataIndex: 'app_type',
scopedSlots: {customRender: 'app_type'},
width: 100
},
{
title: 'secret',
dataIndex: 'secret'
title: '授权时间',
dataIndex: 'auth_time',
width: 200
},
{
title: 'token',
dataIndex: 'token'
title: '主体信息',
dataIndex: 'principal_name',
width: 250
},
{
title: 'aes_key',
dataIndex: 'aes_key'
title: '账号状态',
dataIndex: 'account_status',
width: 200,
scopedSlots: {customRender: 'account_status'}
},
{
title: '注册类型',
dataIndex: 'register_type',
width: 200,
ellipsis: true,
scopedSlots: {customRender: 'register_type'}
},
{
title: '已绑手机号',
dataIndex: 'is_phone',
width: 200,
scopedSlots: {customRender: 'is_phone'}
},
{
title: '已绑邮箱',
dataIndex: 'is_email',
width: 200,
scopedSlots: {customRender: 'is_email'}
},
{
title: '认证类型',
dataIndex: 'verify_info',
width: 200,
scopedSlots: {customRender: 'verify_info'}
},
{
title: '原始ID',
dataIndex: 'user_name',
width: 180
},
{
title: '更新时间',
dataIndex: 'update_time',
sorter: true
width: 200
},
{
title: '操作',
dataIndex: 'action',
width: '150px',
width: 300,
fixed: 'right',
scopedSlots: {customRender: 'action'}
}
]
@ -100,9 +165,10 @@ export default {
Ellipsis
},
data() {
this.columns = columns
return {
// create model
enumData: data,
columns: columns,
visible: false,
confirmLoading: false,
mdl: null,
@ -113,13 +179,15 @@ export default {
// Promise
loadData: parameter => {
const requestParameters = Object.assign({}, parameter, this.queryParam)
return getPlatform(requestParameters)
return getAuthorizer(requestParameters)
.then(res => {
return res.data
})
},
selectedRowKeys: [],
selectedRows: []
selectedRows: [],
//
refreshButton: false,
}
},
created() {
@ -127,59 +195,12 @@ export default {
},
computed: {},
methods: {
handleAdd() {
this.mdl = null
this.visible = true
},
handleEdit(record) {
this.visible = true
this.mdl = {...record}
},
handleOk() {
const form = this.$refs.createModal.form
this.confirmLoading = true
form.validateFields((errors, values) => {
if (!errors) {
if (values.id > 0) {
editPlatform(values).then(res => {
this.visible = false
form.resetFields()
this.$refs.table.refresh()
this.$message.success(res['msg'])
}).catch(e => {
console.log(e)
}).finally(() => {
this.confirmLoading = false
})
} else {
addPlatform(values).then(res => {
this.visible = false
form.resetFields()
this.$refs.table.refresh()
this.$message.success(res['msg'])
}).catch(e => {
console.log(e)
}).finally(() => {
this.confirmLoading = false
})
}
} else {
this.confirmLoading = false
}
})
},
handleCancel() {
this.visible = false
const form = this.$refs.createModal.form
form.resetFields() //
},
handleDel(id) {
deletePlatform({id}).then(res => {
//
this.$refs.table.refresh()
this.$message.success(res['msg'])
}).catch(e => {
console.log(e)
refresh() {
this.refreshButton = true
refresh().then(res => {
this.refreshButton = false
Message.success(res['msg'])
this.loadData()
})
}
}

@ -131,6 +131,9 @@ const vueConfig = {
ws: false,
changeOrigin: true
}
},
client: {
overlay: false
}
},

Loading…
Cancel
Save