电子合同API开发文档 v5

创建合同

请求地址:/v5/Contracts/create.json

请求方式:POST

接口版本: 5.2.3

接口描述:

/*
 * post请求方法(推荐)
 * objUrl obj 主机名,路径
 * objParam obj 附加数据对象
 */
function requestPost(objUrl, objParam)
{
    var http = require('http');				//载入https模块
    var qs = require('querystring');		//载入Query String模块
    var fs = require('fs'); 		//载入fs模块读取文件

    var content = qs.stringify(objParam);	//url编码参数

    var options = {
        hostname: objUrl.hostname,
        port: 80,
        path: objUrl.path,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
    };

    var reqCallBack = function (res) {
        console.log('STATUS: ' + res.statusCode);
        console.log('HEADERS: ' + JSON.stringify(res.headers));
        res.setEncoding('utf8');
        res.on('data', function (chunk) {		//有数据时读数据
            console.log('POST返回结果: ' + chunk);
        });
    };

    var req = http.request(options, reqCallBack);
    req.write(content);		//POST方法传输数据
    req.on('error', function (e) {
        console.log('problem with request: ' + e.message);
    });

    req.end();
}

/*
 * get请求方法
 * objUrl obj 主机名,路径
 * objParam obj 附加数据对象
 */
function requestGet(objUrl, objParam)
{
    var http = require('http');				//载入http模块
    var qs = require('querystring');		//载入Query String模块
    var fs = require('fs'); 		//载入fs模块读取文件

    var content = qs.stringify(objParam);	//url编码参数

    var options = {
        hostname: objUrl.hostname,
        port: 80,
        path: objUrl.path + '?' + content,
        method: 'GET'
    };

    var reqCallBack = function (res) {
        console.log('STATUS: ' + res.statusCode);
        console.log('HEADERS: ' + JSON.stringify(res.headers));
        res.setEncoding('utf8');
        res.on('data', function (chunk) {		//有数据时读数据
            console.log('GET返回结果: ' + chunk);
        });
    };

    var req = http.request(options, reqCallBack);

    req.on('error', function (e) {
        console.log('problem with request: ' + e.message);
    });

    req.end();

}


/*
 *
 * @requestType string 请求方式,POST或者GET,推荐POST
 */
function getContent(requestType)
{
    
    var objUrl = {
        hostname: 'api.1dq.com',	//主机名
        path: '/v5/Contracts/create.json',	//api路径
    }
    var objParam = {
        'easy_id' : '175592531139104768',
'file_id' : 'signed-ce5858499044c9b8fbbaa272754c145a-108d9e29-0001',
'name' : '项目合同协议',
'signed_data' : '175592531139104768, 175592531139104768',
'attachment' : '[ { "file_id" : "signed-efb2124360fb5f8b109220e27f99ae35-73ff845c-0006", "file_name" : "附件1" }, { "file_id" : "signed-efb2124360fb5f8b109220e27f99ae35-73ff845c-0006", "file_name" : "附件2" } ]',
'ca_type' : '1',
'channel' : 'api',
'copy_custom_user' : '[
    {
        "sign_role":"甲方",
        "sign_name":"姓名",
        "sign_number":"电话",
        "sign_company":"选填项,公司名",
        "sign_seal_hand":1,
        "sign_seal_tpl":1,
        "sign_class":1
    }
]',
'copy_data' : '',
'deposit_certificate_type' : '1',
'file_end_date' : '',
'notice_signed' : '',
'pdf_password' : '',
'sign_end_date' : '',
'signed_custom_user' : '[
    {
        "sign_role":"甲方",
        "sign_name":"姓名",
        "sign_number":"电话",
        "sign_company":"选填项,公司名",
        "seal_require":["印章要求"],
        "sign_class":1
    }
]',
'tpl_data' : '{
    "自定义参数": "需要替换的内容1",
    "自定义参数2": "需要替换的内容2"
}',
'tpl_id' : '',

    }

    if(requestType == 'GET'){
        requestGet(objUrl,objParam);
    }else{
        requestPost(objUrl,objParam);
    }
}

console.log('Hello,www.APIStore.cn');
getContent('POST');