Commit 3e6ce91c by 陈思聪

feat:阿里双呼接入

parent 14bb2dbc
var APIBase = require("../../api.base");
var system = require("../../../system");
class AliyunApi extends APIBase {
constructor() {
super();
this.aliclient = system.getObject("util.aliyunClient");
}
/**
* 接口跳转-POST请求
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = await this.opActionProcess(pobj, pobj.actionProcess, pobj.actionType, pobj.actionBody, req);
return result;
}
async opActionProcess(pobj, action_process, action_type, action_body, req) {
pobj.requestId = req.requestId;
var opResult = null;
switch (action_type) {
case "queryAvailabelNumbers":// 获取可用外呼号码列表
opResult = await this.aliclient.queryAvailabelNumbers(pobj.actionBody.bizType);
break;
case "startBackToBackCall":// 发起双呼接口
opResult = await this.aliclient.startBackToBackCall(pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
}
return opResult;
}
}
module.exports = AliyunApi;
\ No newline at end of file
...@@ -68,11 +68,15 @@ class UtilsNeedService extends AppServiceBase { ...@@ -68,11 +68,15 @@ class UtilsNeedService extends AppServiceBase {
pobj.actionBody.type = "ali.tmd"; pobj.actionBody.type = "ali.tmd";
pobj.actionBody.idempotentSource = "tmd_ali"; pobj.actionBody.idempotentSource = "tmd_ali";
}else if (pobj.actionBody.channel_type_code == 1) { }else if (pobj.actionBody.channel_type_code == 1) {
// 阿里商标交易
pobj.actionBody.type = "ali.tmd"; pobj.actionBody.type = "ali.tmd";
pobj.actionBody.idempotentSource = "tmd_ali"; pobj.actionBody.idempotentSource = "tmd_ali";
pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId;
}else if (pobj.actionBody.channel_type_code == 2) { }else if (pobj.actionBody.channel_type_code == 2) {
// 阿里商标注册
pobj.actionBody.type = "ali.tm"; pobj.actionBody.type = "ali.tm";
pobj.actionBody.idempotentSource = "tm_ali"; pobj.actionBody.idempotentSource = "tm_ali";
pobj.actionBody.contactsDingtalk = pobj.actionBody.idempotentId;
}else if (pobj.actionBody.channel_type_code == 'esp.companyreg'){ }else if (pobj.actionBody.channel_type_code == 'esp.companyreg'){
pobj.actionBody.type = "ali.ic"; pobj.actionBody.type = "ali.ic";
pobj.actionBody.idempotentSource = "ic_ali"; pobj.actionBody.idempotentSource = "ic_ali";
......
...@@ -3,7 +3,7 @@ var RPCClient = require('@alicloud/pop-core').RPCClient; ...@@ -3,7 +3,7 @@ var RPCClient = require('@alicloud/pop-core').RPCClient;
const system = require("../system"); const system = require("../system");
class aliyunClient { class aliyunClient {
constructor() { constructor() {
this.execClientNew = system.getObject("util.execClientNew");
this.pushlogSve = system.getObject("service.common.pushlogSve"); this.pushlogSve = system.getObject("service.common.pushlogSve");
} }
getAliClient() { getAliClient() {
...@@ -95,6 +95,77 @@ class aliyunClient { ...@@ -95,6 +95,77 @@ class aliyunClient {
} }
} }
//-----------阿里云双呼能力接口接入------start--------chensicong----2022.01.17----------------------
getAliDoubleCallClient() {
return new RPCClient({
accessKeyId: 'LTAI1pJs7KQizBe2',
accessKeySecret: 'MMNibebAPqR9AnX5YWHnSL2tHMSIoL',
endpoint: "https://companyreg.aliyuncs.com",
apiVersion: '2020-03-06'
});
}
// 获取可用外呼号码列表
async queryAvailabelNumbers(bizType){
let res = null;
try{
console.log(`开始调用阿里云-获取可用外呼号码列表接口。参数bizType=${bizType}`)
// let reqAliclient = this.getAliDoubleCallClient()
var client = new RPCClient({
accessKeyId: 'LTAI1pJs7KQizBe2',
accessKeySecret: 'MMNibebAPqR9AnX5YWHnSL2tHMSIoL',
endpoint: "https://companyreg.aliyuncs.com",
apiVersion: '2020-03-06'
});
let obj = { bizType:bizType }
res = await client.request("QueryAvailableNumbers", obj, {
timeout: 3000, // default 3000 ms
formatAction: true, // default true, format the action to Action
formatParams: true, // default true, format the parameter name to first letter upper case
method: 'POST', // set the http method, default is GET
headers: {}, // set the http request headers
});
console.log(`结束调用阿里云-获取可用外呼号码列表接口。参数bizType=${bizType},结果=${res}`)
this.execClientNew.execLogs(`获取可用外呼号码列表成功`, {bizType:bizType}, "center-channel-aliyunClient-queryAvailabelNumbers", res, null);
return system.getResultSuccess(res.data);
}catch (e){
console.log(`调用异常:阿里云-获取可用外呼号码列表接口。参数bizType=${bizType},结果=${res},异常信息=${e.stack}`)
this.execClientNew.execLogs(`获取可用外呼号码列表失败接口`, {bizType:bizType}, "center-channel-aliyunClient-queryAvailabelNumbers", res, JSON.stringify(e.stack));
return system.getResultFail(-200, "api调用出现异常,error:" + e.stack);
}
}
/**
* 发起双呼
* @param reqbody
* @returns {Promise<{msg: *, data: *, status: *}|{msg: *, data, status: number}>}
*/
async startBackToBackCall(reqbody){
let res = null;
try{
console.log(`开始调用阿里云-发起双呼接口。参数reqbody`,reqbody)
let reqAliclient = this.getAliDoubleCallClient()
res = await reqAliclient.request("StartBackToBackCall",reqbody, {
timeout: 10000, // default 3000 ms 2020 0916 lin修改3000为10000,原因ConfirmIcpIntention BizIds 超过5条会超时
formatAction: true, // default true, format the action to Action
formatParams: true, // default true, format the parameter name to first letter upper case
method: 'POST', // set the http method, default is GET
headers: {}, // set the http request headers
});
console.log(`结束调用阿里云-发起双呼接口。参数reqbody=`,reqbody,'结果=',res)
this.execClientNew.execLogs(`获取可用外呼号码列表成功`, reqbody, "center-channel-aliyunClient-queryAvailabelNumbers", res, null);
return system.getResultSuccess(res.data);
}catch (e){
console.log(`调用异常:阿里云-发起双呼接口。参数reqbody=`,reqbody,'结果=',res,`异常信息=${e.stack}`)
this.execClientNew.execLogs(`调用阿里云发起双呼接口失败`, reqbody, "center-channel-aliyunClient-startBackToBackCall", res, JSON.stringify(e.stack));
return system.getResultFail(-200, "api调用出现异常,error:" + e.stack);
}
}
//-----------阿里云双呼能力接口接入------start--------chensicong----2022.01.17----------------------
// 2020 0924 lin 新增 // 2020 0924 lin 新增
async reqbyLTget(obj, cbk) { async reqbyLTget(obj, cbk) {
var action = obj.action; var action = obj.action;
......
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