Commit e48ddc1d by 赵庆

易云接口调试

parent 3d4f57f5
var system = require("../../system")
class ecloudsignApi {
constructor() {
this.ecloudsignSev = system.getObject("service.ecloudsignSve");
this.ecloudClient = system.getObject("util.ecloudClient");
this.restClient = system.getObject("util.restClient");
this.APIURL = "https://testapi.ecloudsign.com";//"https://api.ecloudsign.com";
}
//申请证书
async applyCert(qobj) {
var result = {};
try {
var params = await this.ecloudClient.rformat(qobj);
params.info = qobj;
var url = this.APIURL + "/ecs/account/applyCert.jspa";
try {
var rs = await this.restClient.execPost(params, url);
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.message;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '申请证书接口返回空';
}
} catch (error) {
result.code = 500;
result.msg = '申请证书接口异常';
}
} catch (error) {
result.code = 500;
result.msg = '申请证书接口异常';
}
return result;
}
//添加签名/印章
// mobilePhone string Y 用户手机
// signImg String Y 签名/印章图片(base64编码),建议用背景透明的png图片
// signType String Y 类型:1签名 2印章
async addSignOrSeal(qobj) {
var result = {};
try {
var params = await this.ecloudClient.rformat(qobj);
params.mobilePhone = qobj.mobilePhone;
params.signImg = qobj.signImg;
params.signType = 1;
var url = this.APIURL + "/ecs/signInfo/addSign.jspa";
try {
var rs = await this.restClient.execPost(params, url);
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.meta.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.meta.message;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '添加签名/印章接口返回空';
}
} catch (error) {
result.code = 500;
result.msg = '添加签名/印章接口异常';
}
} catch (error) {
result.code = 500;
result.msg = '添加签名/印章接口异常';
}
return result;
}
//添加模板
// templateName string Y 模板调用名称
// templateNumber string N 模板ID号,唯一,如果调用方不填写,那么易云章平台自动生成,字符长度最大64
// html string Y 模板html内容,html结构完整,指定编码utf-8,例如:<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8”>
// signPosition json N 签章位置列表,json字符串
async addTemplate(qobj) {
var result = {};
try {
var params = await this.ecloudClient.rformat(qobj);
params.templateName = qobj.templateName;
// params.templateNumber = qobj.templateNumber;
params.html = qobj.html;
// params.signPosition = qobj.signPosition;
var url = this.APIURL + "/ecs/template/addHtmlTemplate.jspa";
try {
var rs = await this.restClient.execPost(params, url);
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.meta.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.meta.message;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '添加模板接口返回空';
}
} catch (error) {
result.code = 500;
result.msg = '添加模板接口异常';
}
} catch (e) {
result.code = 500;
result.msg = '添加模板接口异常';
}
return result;
}
//生成合同
// templateNumber string Y 模板编号
// contractNum string N 合同编号,唯一,如果用户不填写,易云章讲自动生成,最大长度64
// replaceVal string Y 模板变量值,例如{a:1312},或者{“{a}”:1312},即,变量名称完全和模板中的一致,提供规则由用户自己定义
async createPact(qobj) {
var result = {};
try {
var params = await this.ecloudClient.rformat(qobj);
params.templateNumber = qobj.templateNumber;
// params.contractNum = qobj.contractNum;
params.replaceVal = qobj.replaceVal;
var url = this.APIURL + "/ecs/template/createContractByTemplate.jspa";
try {
var rs = await this.restClient.execPost(params, url);
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.meta.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.meta.message;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '生成合同接口返回空';
}
} catch (error) {
result.code = 500;
result.msg = '生成合同接口异常';
}
} catch (e) {
result.code = 500;
result.msg = '生成合同接口异常';
}
return result;
}
//发送短信验证码
// contractNum string Y 合同编号唯一标识
// mobilePhone String Y 必须是用户签署所用手机号码,发送验证码后,在用户签署的时候需要进行验证
// smsTemplate String N 可不填,默认安装易云章通用格式进行发送,如果需要定制,需要申请
async sendVerify(qobj) {
var result = {};
try {
var params = await this.ecloudClient.rformat(qobj);
params.contractNum = qobj.contractNum;
params.mobilePhone = qobj.mobilePhone;
//params.smsTemplate = qobj.smsTemplate;
var url = this.APIURL + "/ecs/contract/sendSms.jspa";
try {
var rs = await this.restClient.execPost(params, url);
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.meta.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.meta.message;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '合同签署动态验证码发送接口返回空';
}
} catch (error) {
result.code = 500;
result.msg = '合同签署动态验证码发送接口异常';
}
} catch (e) {
result.code = 500;
result.msg = '合同签署动态验证码发送接口异常';
}
return result;
}
//验证验证码并签署
// signerInfo string Y 签署人信息 格式json
// contractNum string Y 合同编号唯一标识
// dynamicCode string Y 动态验证码
// isFinish int Y 合同是否签署完成(0:是,1:否),例如合同属于双方合同,第一个人签署时,isFinish 否,当第二个签署时候,参数isFinish为是
// signInfo json N 签章信息,如果指定,则用户必须已经上传签章或者签字,并且在对应的模板中指定位置
async authorizeSign(qobj) {
var result = {};
try {
var params = await this.ecloudClient.rformat(qobj);
params.signerInfo = qobj.signerInfo;
params.contractNum = qobj.contractNum;
params.dynamicCode = qobj.dynamicCode;
params.isFinish = qobj.isFinish;
//params.signInfo = qobj.signInfo;
var url = this.APIURL + "/ecs/contract/authorizeSign.jspa";
try {
var rs = await this.restClient.execPost(params, url);
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.meta.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.meta.message;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '验证验证码并签署接口返回空';
}
} catch (error) {
result.code = 500;
result.msg = '验证验证码并签署接口异常';
}
} catch (e) {
result.code = 500;
result.msg = '验证验证码并签署接口异常';
}
return result;
}
//合同下载
// contractNum string Y 合同编号
// mobilePhone string Y 合同发起人的手机号码
async downloadCont(qobj) {
var result = {};
try {
var params = await this.ecloudClient.rformat(qobj);
params.contractNum = qobj.contractNum;
params.mobilePhone = qobj.mobilePhone;
var url = this.APIURL + "/ecs/contract/downloadCont.jspa";
try {
var rs = await this.restClient.execPost(params, url);
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.meta.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.meta.message;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '合同下载接口返回空';
}
} catch (error) {
result.code = 500;
result.msg = '合同下载接口异常';
}
} catch (e) {
result.code = 500;
result.msg = '合同下载接口异常';
}
return result;
}
}
module.exports = ecloudsignApi;
\ No newline at end of file
var system = require("../../system")
const CtlBase = require("../ctl.base");
class ecloudsignCtl extends CtlBase {
constructor() {
super(CtlBase.getServiceName(ecloudsignCtl));
}
// 申请证书
async applyCertificate(qobj, pobj, req) {
//state为p_app表中appkey
//var existedUser = await this.service.applyCertificate();
return system.getResult2("ok");
}
}
module.exports = ecloudsignCtl;
\ No newline at end of file
const system=require("../../system");
const Dao=require("../dao.base");
class ecloudsignDao extends Dao{
constructor(){
super(Dao.getModelName(ecloudsignDao));
}
}
module.exports=ecloudsignDao;
const system = require("../../system");
const ServiceBase = require("../sve.base");
class ecloudsignService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(ecloudsignService));
}
//申请证书
async applyCert(pobj,req){
}
}
module.exports = ecloudsignService;
\ No newline at end of file
const moment = require("moment");
class ecloudClient {
constructor() {
this.appKey = "9999"
this.secret = "8888";
}
//获取请求参数
async rformat(qobj) {
var data = {
timestamp: await this.getNewDate(),
appKey: this.appKey,
v: '1.2.14',
nonce: await this.getRandomCode(6),
signature: await this.signature(qobj, this.secret),
}
return data;
}
//获取当前时间
async getNewDate() {
let date = moment().format("YYYY-MM-DD HH:mm:ss");
return date;
}
//随机生成数字
async getRandomCode(iun) {
var randStr = "";
for (var i = 0; i < iun; i++) {//此处的12为生成12位数字,可随即更改
var randItem = Math.floor(Math.random() * 10);
randStr += randItem;
}
return randStr;
}
async signature(args, secret) {
var keys = Object.keys(args);
keys = keys.sort();
var newArgs = {};
keys.forEach(function (key) {
newArgs[key] = args[key];
});
var string = '';
for (var k in newArgs) {
// string += '&' + k + '=' + newArgs[k];
string += newArgs[k];
}
string = string.substr(1);
var string = secret + string + secret;
var crypto = require('crypto');
return crypto.createHash('md5').update(string, 'utf8').digest('hex').toUpperCase();
}
async returnRu(rs) {
var result = {};
if (rs && rs.stdout) {
var stdout = JSON.parse(rs.stdout) || {};
var code = stdout.code;
if (code == 0) {
code = 1;
} else if (code == 1) {
code = 0;
} else {
}
result.code = code;
result.msg = stdout.msg;
result.data = stdout.data;
} else {
result.code = 0;
result.msg = '结算接口返回空';
}
return result;
}
}
module.exports = ecloudClient;
\ No newline at end of file
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