| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 'use strict';
- /**
- * weapp控制器
- *
- * @author Lan
- * @date 2025/12/22
- * @version
- */
- module.exports = app => {
- class WeappController extends app.BaseController {
- async login(ctx) {
- try {
- const {
- code,
- } = ctx.request.body;
- if (!code) {
- throw '微信授权失败, 请检查';
- }
- const token = await ctx.service.weapp.weappLogin(code);
- ctx.body = { err: 0, msg: '登录成功', data: { access_token: token } };
- } catch (error) {
- this.log(error);
- ctx.body = { err: 1, msg: error.toString(), data: null };
- }
- }
- async refresh(ctx) {
- const { refresh_token } = ctx.request.body;
- if (!refresh_token) {
- ctx.body = { err: 1, msg: '缺少 refresh_token', data: null };
- return;
- }
- try {
- const token = await ctx.service.weapp.refresh(refresh_token);
- ctx.body = { err: 0, msg: '刷新成功', data: { access_token: token } };
- } catch (error) {
- this.log(error);
- ctx.body = { err: 1, msg: '刷新失败', data: null };
- }
- }
- }
- return WeappController;
- };
|