Commit 572c733c by 宋毅

tj

parent 4329ec54
......@@ -67,6 +67,32 @@ class AppServiceBase {
return system.getResult(null, errorMsg);
}
}
async restPostWithHValueUrl(pobj, url, hValue) {//curl请求带请求头信息
try {
if (!hValue) {
hValue = "YLc6GsgLtuRGaVA5Om848x18NxLtHlyA";
}
var rtn = await this.restClient.execPostWithHValue(pobj, url, hValue);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPostWithHValue data is empty");
}
var result = JSON.parse(rtn.stdout);
return result;
} catch (e) {
var errorMsg = "error:" + e.stack;
//日志记录
this.logCtl.error({
appid: pobj.appInfo ? pobj.appInfo.uapp_id || "" : "",
appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "",
requestId: pobj.requestId || "",
op: "service/app.base.js/restPostWithHValueUrl",
content: errorMsg,
// clientIp: pobj.clientIp,
optitle: pobj.opType + "推送操作异常->restPostWithHValueUrl",
});
return system.getResult(null, errorMsg);
}
}
async execPostUrl(pobj, url) {
try {
var rtn = await this.execClient.execPost(pobj, url);
......@@ -296,6 +322,21 @@ class AppServiceBase {
var productItemInterfaceResult = await this.restPostUrl(getProductInterfaceObj, getProductInterfaceUrl);
return productItemInterfaceResult;
}
async getConvertSemiangleStr(str) {//去除空格及全角转半角
var result = "";
str = str.replace(/\s+/g, "");
var len = str.length;
for (var i = 0; i < len; i++) {
var cCode = str.charCodeAt(i);
//全角与半角相差(除空格外):65248(十进制)
cCode = (cCode >= 0xFF01 && cCode <= 0xFF5E) ? (cCode - 65248) : cCode;
//处理空格
cCode = (cCode == 0x03000) ? 0x0020 : cCode;
result += String.fromCharCode(cCode);
}
return result;
}
/*
返回20位业务订单号
prefix:业务前缀
......
......@@ -53,6 +53,16 @@ class UtilsFgbusinesschancService extends AppServiceBase {
if (!actionBody.companyName) {
return system.getResult(null, "actionBody.companyName can not be empty,100290");
}
actionBody.companyName = await this.getConvertSemiangleStr(actionBody.companyName);
var url = settings.entProfileUrl() + "lable";
var reqParam = {
company_name: actionBody.companyName
}
var result = await this.restPostWithHValueUrl(reqParam, url);
if (result.code != 200) {
return system.getResult(null, result.message || "req is error");
}
return system.getResultSuccess(result.data);
}
async getRecommendProducts(pobj, actionBody) {
......
......@@ -11,6 +11,8 @@ class RestClient {
this.cmdPostPatternWithAK = "curl -k -H 'Content-type: application/json' -H 'AccessKey:{ak}' -H 'request-id:{requestId}' -d '{data}' {url}";
this.cmdPostWithHValue = "curl -k -H 'Content-type: application/json' -H 'ak:{ak}' -d '{data}' {url}";
this.cmdDownLoadFilePattern = "curl -G -o {fileName} {url}";
this.cmdPostPattern2 = "curl -k -H 'Content-type: application/x-www-form-urlencoded' -d '{data}' {url}";
// form-data形式post data参数类型 md5=2&data=1
......@@ -40,6 +42,12 @@ class RestClient {
data).replace(/\{url\}/g, url).replace(/\{ak\}/g, acck).replace(/\{requestId\}/g, requestId);
return cmd;
}
FetchPostCmdWithHValue(subData, url, hValue) {
var data = JSON.stringify(subData);
var cmd = this.cmdPostWithHValue.replace(/\{data\}/g,
data).replace(/\{url\}/g, url).replace(/\{ak\}/g, hValue);
return cmd;
}
FetchPostCmd2(subData, url) {
var data = subData;
var cmd = this.cmdPostPattern2.replace(/\{data\}/g,
......@@ -88,7 +96,7 @@ class RestClient {
}
async execPost(subData, url) {
let cmd = this.FetchPostCmd(subData, url);
console.log(cmd,"cmd............");
console.log(cmd, "cmd............");
var result = await this.exec(cmd, {
maxBuffer: 10000 * 1024
});
......@@ -106,6 +114,14 @@ class RestClient {
return null;
}
}
async execPostWithHValue(subData, url, hValue) {
let cmd = this.FetchPostCmdWithHValue(subData, url, hValue);
console.log(cmd, "cmd............");
var result = await this.exec(cmd, {
maxBuffer: 1024 * 1024 * 15
});
return result;
}
async execPost2(subData, url) {
let cmd = this.FetchPostCmd2(subData, url);
console.log(cmd);
......
......@@ -20,6 +20,13 @@ var settings = {
usertimeout: 3600,//单位秒
basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 4012,
entProfileUrl: function () {
if (this.env == "dev") {
return "https://entprofile.gongsibao.com/";
} else {
return "https://entprofile.gongsibao.com/";
}
},
aliossjavaUrl: function () {
if (this.env == "dev") {
return "http://192.168.2.109:8080/uploadfile";
......
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