政采云如何生成合同 完整生成一个云合同实例
下面是好好范文网小编收集整理的政采云如何生成合同 完整生成一个云合同实例,仅供参考,欢迎大家阅读!
<?php
header("Content-Type: text/html;charset=utf-8");
获取长效令牌
$appId="20185454500018";//应用APPID
$appKey="qvegfhgfhG0qDei";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADER => true,//false时,取得code
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{n"appId":"$appId",n"appKey":"$appKey"n}",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err.die;
} else {
//echo $response;
$headArr = explode("rn", $response);
foreach ($headArr as $loop) {
if(strpos($loop, "token") !== false){
$token = trim(substr($loop, 6));
//$token = trim($loop);
}
if(strpos($loop, "code") !== false){
//$code = trim(substr($loop, 6));
$rp = trim($loop);
}
}
}
$arr = json_decode($rp, true);
$code = $arr['code'];//code=200 说明成功
$msg = $arr['msg'];
//不成功
if($code!="200" || !$token){
print_r( "获取长效令牌,原因:".$msg).die;
}
$token="eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1MjQ0NzI5MjEsImp0aSI6ImcxSlJHdDJzeHRNMXFMOU9ta2hVUVFkdXVsSzh4Sk5NcUlIbkE5eUgvYkJwbk5yeHEvYVY4TDVia0VQY051QzQyTlZicWhzKzByUjVHeDV6WGZ3N2d3PT0ifQ.NQd0ujuYk5ZrBHmmMvgx9JaVPH3qSXxcxlMNvkkp7zq3-d67wo5lubT_wkGqRukNmii7IoWM-vjxx8ax681abg";
//print_r($code).die;
//创建个人用户
$userName = "钟安志";用户姓名(最长 15 字符)成采南
$identityRegion = 0;身份地区:0 大陆,1 香港,2 台湾,3 澳门
$certifyNum = "422827199911149418";身份证号码,应用内唯一 520181198002175907
$phoneRegion = 0;手机号地区:0 大陆,1 香港、澳门,2 台湾
$phoneNo = "13640550035";//手机号:1.大陆,首位为 1,长度 11 位纯数字;2.香港、澳门,长度为 8 的纯数字;3.台湾,长度为 10 的纯数字
$caType = "B1";//证书类型:A1 CFCA 场景,A2 CFCA 长效,B1 ZJCA 场景,B2 ZJCA 长效
$curl2 = curl_init();
curl_setopt_array($curl2, array(
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{n"caType": "$caType",n"certifyNum": "$certifyNum",n"identityRegion": "$identityRegion",n"phoneNo": "$phoneNo",n"phoneRegion": "$phoneRegion",n"userName": "$userName"n}",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
"token: $token"
),
));
$response2 = curl_exec($curl2);
$err2 = curl_error($curl2);
curl_close($curl2);
if ($err2) {
echo "cURL Error #:" . $err2.die;
} else {
//echo $response2;
$arr2 = json_decode($response2, true);
$code2 = $arr2['code'];//code=200 说明成功
$msg2 = $arr2['msg'];
//不成功
if($code2!=200){
print_r( "创建个人用户失败,原因:".$msg2).die;
}
$signerId = $arr2['data']['signerId'];
}
// $signerId=60;
// echo $signerId;
//创建个人印模
$curl3 = curl_init();
curl_setopt_array($curl3, array(
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{n"signerId": "$signerId",n"borderType": "B2",n"fontFamily": "F1"n}",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
"token: $token"
),
));
$response3 = curl_exec($curl3);
$err3 = curl_error($curl3);
curl_close($curl3);
if ($err3) {
echo "cURL Error #:" . $err3.die;
} else {
// echo $response3;
$arr3 = json_decode($response3, true);
$code3 = $arr3['code'];//code=200 说明成功
$msg3 = $arr3['msg'];
//不成功
if($code3!=200){
print_r( "创建个人印模失败,原因:".$msg3).die;
}
$moulageId = $arr3['data']['moulageId'];
}
//$moulageId=82;
print_r($moulageId);
//根据模版生成合同
$contractTitle="测试合同标题";
$templateId="TEM1001231";
$curl4 = curl_init();
curl_setopt_array($curl4, array(
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{n"contractTitle": "$contractTitle",n"templateId": "$templateId"n}",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
"token: $token"
),
));
$response4 = curl_exec($curl4);
$err4 = curl_error($curl4);
curl_close($curl4);
if ($err4) {
echo "cURL Error #:" . $err4.die;
} else {
// echo $response4;
$arr4 = json_decode($response4, true);
$code4 = $arr4['code'];//code=200 说明成功
$msg4 = $arr4['msg'];
//不成功
if($code4!=200){
print_r( "创建个人印模失败,原因:".$msg4).die;
}
$contractId = $arr4['data']['contractId'];
$contractId=str_replace(",","",number_format($contractId));
}
print_r($contractId);
//$contractId="1804232025535010";
//添加签署者
$curl5 = curl_init();
curl_setopt_array($curl5, array(
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
//CURLOPT_POSTFIELDS => "{n"contractTitle": "$contractTitle",n"templateId": "$templateId"n}",
CURLOPT_POSTFIELDS => "{"idType": "0",n"idContent": "$contractId",n"signers": [{"signerId": "$signerId",n"signPositionType": "1",n"positionContent": "88046",n"signValidateType": "0"}n]n}",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
"token: $token"
),
));
$response5 = curl_exec($curl5);
$err5 = curl_error($curl5);
curl_close($curl5);
if ($err5) {
echo "cURL Error #:" . $err5.die;
} else {
//echo $response5;
$arr5 = json_decode($response5, true);
$code5 = $arr5['code'];//code=200 说明成功
$msg5 = $arr5['msg'];
}
//不成功
if($code5!=200){
print_r( "创建个人印模失败,原因:".$msg5).die;
}
// print_r($code5);
//合同签署
$curl6 = curl_init();
curl_setopt_array($curl6, array(
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{n"idType": "0",n"idContent": "$contractId",n"signerId": "$signerId",n"moulageId": "$moulageId"n}",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
"token: $token"
),
));
$response6 = curl_exec($curl6);
$err6 = curl_error($curl6);
curl_close($curl6);
if ($err6) {
echo "cURL Error #:" . $err6.die;
} else {
echo $response6;
$arr6 = json_decode($response6, true);
$code6 = $arr6['code'];//code=200 说明成功
$msg6 = $arr6['msg'];
}
//不成功
if($code6!=200){
print_r( "合同签署失败,原因:".$msg6).die;
}
// print_r($code6);
?>