Commit f2f5206c by linboxuan

增加优客免登接口

parent d80042b4
var WEBBase = require("../../web.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class ProductAPI extends WEBBase {
constructor() {
super();
this.utilsUcommuneSve = system.getObject("service.utilsSve.utilsUcommuneSve");
}
/**
* 优客工厂
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = await this.opActionProcess(pobj, pobj.actionType, req);
return result;
}
async opActionProcess(pobj, action_type, req) {
var opResult = null;
switch (action_type) {
case "getUserInfo":// 根据优客token获取用户信息,生成userPin返回前端
opResult = await this.utilsUcommuneSve.getUserInfo(pobj, pobj.actionBody);
break;
case "getOrderList":// 优客调取订单列表用
opResult = await this.utilsUcommuneSve.getOrderList(pobj, pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
}
return opResult;
}
}
module.exports = ProductAPI;
\ No newline at end of file
...@@ -2,6 +2,7 @@ const system = require("../system"); ...@@ -2,6 +2,7 @@ const system = require("../system");
const moment = require('moment') const moment = require('moment')
const settings = require("../../config/settings"); const settings = require("../../config/settings");
const md5 = require("MD5"); const md5 = require("MD5");
const uuidv4 = require('uuid/v4');
class AppServiceBase { class AppServiceBase {
constructor() { constructor() {
this.restClient = system.getObject("util.restClient"); this.restClient = system.getObject("util.restClient");
...@@ -93,6 +94,29 @@ class AppServiceBase { ...@@ -93,6 +94,29 @@ class AppServiceBase {
return system.getResult(null, errorMsg); return system.getResult(null, errorMsg);
} }
} }
async restPostWithHAuthorizationUrl(pobj, userToken, url) {//curl请求带请求头信息
try {
var rtn = await this.restClient.restPostWithHAuthorizationUrl(userToken, url);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restPostWithHAuthorizationUrl 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/restPostWithHAuthorizationUrl",
content: errorMsg,
// clientIp: pobj.clientIp,
optitle: pobj.opType + "推送操作异常->restPostWithHAuthorizationUrl",
});
return system.getResult(null, errorMsg);
}
}
async execPostUrl(pobj, url) { async execPostUrl(pobj, url) {
try { try {
var rtn = await this.execClient.execPost(pobj, url); var rtn = await this.execClient.execPost(pobj, url);
...@@ -378,5 +402,10 @@ class AppServiceBase { ...@@ -378,5 +402,10 @@ class AppServiceBase {
} }
return uuid.join(''); return uuid.join('');
} }
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
} }
module.exports = AppServiceBase; module.exports = AppServiceBase;
var system = require("../../../system");
var settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base");
//产品操作类
class UtilsUcommuneService extends AppServiceBase {
constructor() {
super();
this.utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
}
//--------------------------------优客工厂相关接口-start-----------------------------------------------------
/**
* 通过产品类别编码路径获取产品列表
* @param {*} pobj
* @param {*} actionBody userToken 为优客工厂的userToken
*/
async getUserInfo(pobj, actionBody) {
if (!actionBody.userToken) {
return system.getResult(null, "actionBody.token can not be empty,100410");
}
var url = settings.ucommuneUrl() + "third/getUserInfo"; // 调用优客工场接口 获取用户信息
// 拼接规则curl -k -H 'Content-type: application/json' -H 'authorization:{token}' -X POST {url} pobj作为发生错误时记录日志用
let result = await this.restPostWithHAuthorizationUrl(pobj, actionBody.userToken, url);
if(result.retCode == 0) { // 0成功 1失败
pobj.actionType = "getLoginByUserName";
pobj.actionBody.channelUserId = result.data.mobile;
pobj.actionBody.userpin = pobj.actionBody.userpin || this.getUUID();
var tmpOpResult = await this.utilsAuthSve.getLoginByUserName(pobj, pobj.actionBody);
if (tmpOpResult.status != 0 && tmpOpResult.status != 2060) {
return tmpOpResult;
}
return system.getResultSuccess({ userpin: tmpOpResult.data.userpin })
} else {
return system.getResult(null, "Failed to get user information, 100420");
}
}
/**
* 获取产品详情
* @param {*} pobj
* @param {*} actionBody channelItemCode 渠道产品编码
*/
async getOrderList(pobj, actionBody) {
if (!actionBody.channelItemCode) {
return system.getResult(null, "actionBody.channelItemCode can not be empty,100340");
}
var url = settings.centerAppUrl() + "action/opProduct/springBoard";
return await this.restPostUrl(pobj, url);
}
//--------------------------------优客工厂相关接口--end----------------------------------------------------
}
module.exports = UtilsUcommuneService;
...@@ -17,6 +17,8 @@ class RestClient { ...@@ -17,6 +17,8 @@ class RestClient {
this.cmdPostPattern2 = "curl -k -H 'Content-type: application/x-www-form-urlencoded' -d '{data}' {url}"; this.cmdPostPattern2 = "curl -k -H 'Content-type: application/x-www-form-urlencoded' -d '{data}' {url}";
// form-data形式post data参数类型 md5=2&data=1 // form-data形式post data参数类型 md5=2&data=1
this.cmdPostPattern5 = "curl -k --data '{data}' {url}"; this.cmdPostPattern5 = "curl -k --data '{data}' {url}";
// authorization=[token]
this.cmdPostpatternToken = "curl -k -H 'Content-type: application/json' -H 'authorization:{token}' -X POST {url}"
} }
getUUID() { getUUID() {
...@@ -48,6 +50,10 @@ class RestClient { ...@@ -48,6 +50,10 @@ class RestClient {
data).replace(/\{url\}/g, url).replace(/\{ak\}/g, hValue); data).replace(/\{url\}/g, url).replace(/\{ak\}/g, hValue);
return cmd; return cmd;
} }
FetchrestPostWithHAuthorizationUrl(userToken, url) {
var cmd = this.cmdPostpatternToken.replace(/\{url\}/g, url).replace(/\{token\}/g, userToken);
return cmd;
}
FetchPostCmd2(subData, url) { FetchPostCmd2(subData, url) {
var data = subData; var data = subData;
var cmd = this.cmdPostPattern2.replace(/\{data\}/g, var cmd = this.cmdPostPattern2.replace(/\{data\}/g,
...@@ -122,6 +128,14 @@ class RestClient { ...@@ -122,6 +128,14 @@ class RestClient {
}); });
return result; return result;
} }
async restPostWithHAuthorizationUrl(userToken, url) {
let cmd = this.FetchrestPostWithHAuthorizationUrl(userToken, url);
console.log(cmd, "cmd............");
var result = await this.exec(cmd, {
maxBuffer: 1024 * 1024 * 15
});
return result;
}
async execPost2(subData, url) { async execPost2(subData, url) {
let cmd = this.FetchPostCmd2(subData, url); let cmd = this.FetchPostCmd2(subData, url);
console.log(cmd); console.log(cmd);
......
...@@ -126,6 +126,13 @@ var settings = { ...@@ -126,6 +126,13 @@ var settings = {
return "https://fqgirl.gongsibao.com/"; return "https://fqgirl.gongsibao.com/";
} }
}, },
ucommuneUrl: function () {
if (this.env == "dev") {
return "https://m-dev.ucommune.com/"// 优客测试环境
} else {
return "https://m.ucommune.com/"// 优客正式环境
}
},
apiconfig: { apiconfig: {
opLogUrl: function () { opLogUrl: function () {
return settings.reqEsAddr() + "center_channel_log/_doc?pretty"; return settings.reqEsAddr() + "center_channel_log/_doc?pretty";
......
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