驾驶舱添加getToken接口

This commit is contained in:
lingwentao 2023-08-02 18:32:38 +08:00
parent 118b224748
commit 074b113a91
2 changed files with 33 additions and 0 deletions

View File

@ -16,6 +16,11 @@ import Base from "../utils/base";
export class OpenDataController {
constructor(private readonly openDataService: OpenDataService) {}
@Post('/getToken')
getToken(@Body() {clientId,clientSecret}) {
return this.openDataService.getToken(clientId,clientSecret);
}
@Post('/hcc/queryNum')
homeData(@Body() {areaCode}) {
return this.openDataService.homeData(areaCode);

View File

@ -2,9 +2,37 @@ import { Injectable } from '@nestjs/common';
const dayjs = require("dayjs");
import OpenDataMapper from "../open-data/open-data.mapper";
import Base from "../utils/base";
import { v4 } from 'uuid';
import clientMapper from "../client/client.mapper";
@Injectable()
export class OpenDataService {
/**
* /访
* @returns
* @param clientId
* @param clientSecret
*/
async getToken(clientId, clientSecret) {
console.log('getToken:', clientId, clientSecret);
const info = await clientMapper.getClientInfo(clientId, clientSecret);
if (!info?.length) {
// 不存在平台数据 直接返回
return Base.error();
}
const token = v4().replace(/-/g, '');
const expireTime = new Date(new Date().valueOf() + 360 * 60 * 1000);
// token应用服务平台数据入库
await Promise.all([
clientMapper.addClientToken(clientId, token, expireTime),
clientMapper.addClientInfo(clientId, clientSecret),
]);
return Base.success({
token: token,
expiresIn: 360,
});
}
async homeData(areaCode) {
const homeData = await OpenDataMapper.getHomeData(areaCode);
if (homeData?.length){