短报文教学
This commit is contained in:
96
app/controller/home.js
Normal file
96
app/controller/home.js
Normal file
@@ -0,0 +1,96 @@
|
||||
const BaseController = require('../core/base_controller.js');
|
||||
|
||||
const fileName = "home";
|
||||
|
||||
class HomeController extends BaseController {
|
||||
// token状态查询接口
|
||||
async tokenStatus() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const uid = this.decryptRequest(ctx.request.body.uid).split('?')[0];
|
||||
let rdmcode = await this.checkUid(ctx, uid);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token 过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const result = await ctx.service.home.tokenStatus(uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, 'token 状态查询成功', "deconstruction", result);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, 'token 状态查询失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "tokenStatus";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户获取短期token的接口
|
||||
async getUserToken() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const uid = this.decryptRequest(ctx.request.body.uid).split('?')[0];
|
||||
if (uid == "") {
|
||||
this.setResponse(ctx, 404, '获取临时 token 失败', "none");
|
||||
return;
|
||||
}
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token 过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const result = await ctx.service.home.getUserToken(uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '获取临时 token 成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '获取临时 token 失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "getUserToken";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 用户延续短期token有效时间的接口
|
||||
async lifeHold() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const uid = this.decryptRequest(ctx.request.body.uid).split('?')[0];
|
||||
if (uid == "") {
|
||||
this.setResponse(ctx, 404, '延续临时 token 有效时间失败', "none");
|
||||
return;
|
||||
}
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token 过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const result = await ctx.service.home.lifeHold(uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '延续临时 token 有效时间成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '延续临时 token 有效时间失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "lifeHold";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HomeController;
|
||||
Reference in New Issue
Block a user