驾驶舱添加getToken接口
This commit is contained in:
parent
118b224748
commit
074b113a91
|
@ -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);
|
||||
|
|
|
@ -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){
|
||||
|
|
Loading…
Reference in New Issue
Block a user