Commit 07ffb29e by 王栋源

wdy

parent 4c1fd1c4
......@@ -118,12 +118,7 @@ class APIBase {
req.headers["request-id"] = requestid;
}
try {
//验证accesskey或验签
var isPassResult = await this.checkAcck(gname, methodname, pobj, query, req);
if (isPassResult.status != 0) {
isPassResult.requestId = "";
return isPassResult;
}
req.requestId = requestid;
var rtn = await this[methodname](pobj, query, req);
if (rtn && !rtn.requestId) {
......
const system = require("../../../system");
var settings = require("../../../../config/settings");
var APIBase = require("../../api.base");
class TradetransferAPI extends APIBase {
constructor() {
super();
this.execlient = system.getObject("util.execClient");
this.channelApiUrl = settings.channelApiUrl();
}
async getToken() {
var self = this;
var reqTokenUrl = this.channelApiUrl + "/auth/accessAuth/getToken";
var reqParam = self.appInfo["aliyuntmtransfer"];
if (!reqParam.appkey || !reqParam.secret) {
return system.getResult(null, "reqType类型有误,请求失败");
}
var rtn = await this.execlient.execPost(reqParam, reqTokenUrl);
if (!rtn.stdout) {
return system.getResult(null, "获取token失败");
}
var tokenResult = JSON.parse(rtn.stdout);
if (tokenResult.status == 0) {
tokenResult.data.secret = reqParam.secret;
}
return tokenResult;
}
//订单创建
async createtransfer(obj) {
var sobj = {
"actionProcess": "aliyuntmtransfer",
"actionType": "aliclient",
"sign": "2FviZ9PGws8Pt1fBhq0t90mjUvI",
"actionBody": obj
}
// var tokenInfo = await this.getToken();
var url = this.channelApiUrl + "/api/transfer/tradeApi/createtransfer";
// var rtn = await this.execlient.execPostTK(sobj, reqUrl, tokenInfo.data.token);
var rtn = await this.execlient.execPostTK(sobj, url,"token");
return rtn;
}
//订单查询
async ordersel(obj) {
var sobj = {
"actionProcess": "aliyuntmtransfer",
"actionType": "aliclient",
"sign": "2FviZ9PGws8Pt1fBhq0t90mjUvI",
"actionBody": obj
}
// var tokenInfo = await this.getToken();
var url = this.channelApiUrl + "/api/transfer/tradeApi/ordersel";
// var rtn = await this.execlient.execPostTK(sobj, reqUrl, tokenInfo.data.token);
var rtn = await this.execlient.execPostTK(sobj, url,"token");
return rtn;
}
//订单关闭
async orderclose(obj) {
var sobj = {
"actionProcess": "aliyuntmtransfer",
"actionType": "aliclient",
"sign": "2FviZ9PGws8Pt1fBhq0t90mjUvI",
"actionBody": obj
}
// var tokenInfo = await this.getToken();
var url = this.channelApiUrl + "/api/transfer/tradeApi/orderclose";
// var rtn = await this.execlient.execPostTK(sobj, reqUrl, tokenInfo.data.token);
var rtn = await this.execlient.execPostTK(sobj, url,"token");
return rtn;
}
}
module.exports = TradetransferAPI;
var childproc = require('child_process');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const uuidv4 = require('uuid/v4');
class ExecClient {
constructor() {
this.cmdPostPattern = "curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}";
this.cmdGetPattern = "curl -G -X GET '{url}'";
this.cmdPostTK = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {url}";
}
async exec(cmd) {
......@@ -15,6 +16,31 @@ class ExecClient {
return {stdout, stderr};
}
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
async execPostTK(subData, url, token) {
let cmd = this.FetchPostTK(subData, url, token);
var result = await this.exec(cmd, {
maxBuffer: 1024 * 1024 * 15
});
var rtn = result.stdout;
if (rtn) {
return JSON.parse(rtn);
} else {
return null;
}
}
FetchPostTK(subData, url, token) {
var data = JSON.stringify(subData);
var requestId = this.getUUID();
var cmd = this.cmdPostTK.replace(/\{data\}/g,
data).replace(/\{url\}/g, url).replace(/\{tk\}/g, token).replace(/\{requestId\}/g, requestId);
return cmd;
}
async exec2(cmd) {
return exec(cmd, {encoding: "base64"});
......
......@@ -38,6 +38,14 @@ var settings = {
return "http://43.247.184.94:7200/";
}
},
channelApiUrl: function () {
if (this.env == "dev") {
return "http://192.168.18.61:4003";
} else {
return "http://zc-channel-service";
}
},
apiconfig: {
opLogUrl: function () {
return settings.reqEsAddr() + "bigdata_zc_op_log/_doc?pretty";
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment