个人认证流程
- 注册个人账户
- 发起实名认证
企业实名认证流程
- 注册个人账户(可法人或代理人)
- 发起个人实名认证
- 注册企业账户
- 发起企业认证
电子签
- 创建合同模板
- 配置签署区/填充区
- 开启签约流程
- 配置签约流程
- 配置签署人
- 发起签约
详细查看E签宝文档
例子:
个人实名认证
1.注册个人账户
$objEsign = new Esign();
$arrEsignRes = $objEsign->addIndiviDual(“用户ID,自己自定义的,要确保唯一”, “真实名字”, “身份证号”, “手机号”);
2.发起实名认证
$objEsign = new Esign();
$arrEsignRes = $objEsign->authIndiviDual(“回调参数”,”注册时E签宝返回的个人ID”, “真实名字”,”身份证号”, “手机号”);
3.回调,自行参照官方文档即可,我这里回调使用ID进行区分回调参数直接填写用户ID 再补全身份即可 $intUserId . ‘_’ . ‘individual’
企业实名认证
1.完成个人实名认证后
2.注册组织
//注册组织
$objEsign = new Esign();
$arrEsignResult = $objEsign->addOrganizations(“用户ID”,”个人E签宝ID”,”企业名称”,”证件类型”,”证件号”, “法人身份证,选填”, “法人姓名选填”);
3.发起实名认证
$arrEsignResult = $objEsign->authOrganizations(“用户ID”, ”
E签宝注册的组织ID”, “E签宝注册的个人ID”, “组织名称”, “组织识别号”, “法人身份证”, “法人姓名”);
5.回调,自行参照官方文档即可,我这里回调使用ID进行区分回调参数直接填写用户ID 再补全身份即可 $intUserId . ‘_’ . ‘company’
发起签约:
自行对照官方文档进行流程操作,以及提供扩展库进行发起,注释还是很详细的
扩展代码
<?php
namespace esign;
use finfo;
use think\facade\Cache;
error_reporting(E_ERROR | E_PARSE);
class Esign
{
/**
* 私有函数,从E签宝获取TOKEN
*
* @return void
* @author 一颗大萝北 [email protected]
*/
private function getToken()
{
$strSignToken = Cache::get(‘esignToken’);
$strSignTokenTime = Cache::get(‘esignTokenSetTime’);
if (!empty($strSignToken) && !empty($strSignTokenTime) && time() – intval($strSignTokenTime) < 7000) return $strSignToken;
$strEsignBackToenJson = curl_http(config(‘esign.apiBasrUrl’) . config(‘esign.apiAccessTokenUrl’) . ‘?appId=’ . config(‘esign.appId’) . ‘&secret=’ . config(‘esign.secret’) . ‘&grantType=client_credentials’);
if ($strEsignBackToenJson == “curl=error”) return ”;
try {
$arrEsignBackToen = json_decode($strEsignBackToenJson, true);
if ($arrEsignBackToen[‘code’] != 0) return “”;
Cache::set(‘esignToken’, $arrEsignBackToen[‘data’][‘token’], 7000);
Cache::set(‘esignTokenSetTime’, time(), 7000);
return $arrEsignBackToen[‘data’][‘token’];
} catch (\Throwable $e) {
return “”;
}
}
/**
* 添加个人用户
*
* @param string/int $intId 用户唯一ID,数据库中的ID
* @param string $strRealName 用户真实名字
* @param string $strIdNumber 用户身份证号
* @param string $strMobile 用户手机号 可选,如果留空将无法接收合同签署通知和实名认证短信通知
* @param string $strMail 用户邮箱 可选
* @return void
* @author 一颗大萝北 [email protected]
*/
public function addIndiviDual($intId, $strRealName, $strIdNumber, $strMobile = ”, $strMail = ”)
{
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlData = array();
$arrCurlData[‘thirdPartyUserId’] = $intId;
$arrCurlData[‘name’] = $strRealName;
$arrCurlData[‘idNumber’] = $strIdNumber;
$arrCurlData[‘idType’] = “CRED_PSN_CH_IDCARD”;
if (!empty($strMail)) $arrCurlData[’email’] = $strMail;
if (!empty($strMobile)) $arrCurlData[‘mobile’] = $strMobile;
$strCurlResJson = curl_http(config(‘esign.apiBasrUrl’) . config(‘esign.apiAddUserUrlIndiviDual’), $arrCurlData, true, $arrCurlHeader, ‘POST’);
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [“ok” => false, “msg” => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [“ok” => true, “accountId” => $arrCurlRes[‘data’][‘accountId’], ‘result’ => $arrCurlRes[‘code’]];
} catch (\Throwable $e) {
return [“ok” => false, “msg” => ‘JSON解码失败!’];
}
}
/**
* 删除E签宝注册的个人用户
*
* @param [type] $strEsignUidpersonal E签宝注册返回的用户ID
* @return void
* @author 一颗大萝北 [email protected]
*/
public function delIndiviDual($strEsignUidpersonal)
{
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiDelUserUrlIndiviDual’);
$strUrl = str_replace(“{accountId}”, $strEsignUidpersonal, $strUrl);
$strCurlResJson = curl_http($strUrl, [], false, $arrCurlHeader, ‘DELETE’);
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [“ok” => false, “msg” => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [“ok” => true, “accountId” => $arrCurlRes[‘data’][‘accountId’], ‘result’ => $arrCurlRes[‘code’]];
} catch (\Throwable $e) {
return [“ok” => false, “msg” => ‘JSON解码失败!’,];
}
}
/**
* 进行个人实名认证
*
* @param [type] $intUserId 用户ID 必须唯一,给异步回调判断使用
* @param [type] $strName 用户真实姓名
* @param [type] $strCertNo 用户身份证
* @param string $strMobileNo 用户手机号,可选
* @return void 返回数组DATA,具体查看,https://open.esign.cn/doc/detail?id=opendoc%2Fidentity_service%2Feaug1b&namespace=opendoc%2Fidentity_service
* @author 一颗大萝北 [email protected]
*/
public function authIndiviDual($intUserId, $strEsignUidpersonal, $strName, $strCertNo, $strMobileNo = ”)
{
$arrCurlData = array();
$arrCurlData[‘authType’] = “PSN_BANK4_AUTHCODE”; //指定默认认证类型(打开认证页面所展示的第一个认证类型)
$arrCurlData[‘availableAuthTypes’] = [‘PSN_TELECOM_AUTHCODE’, ‘PSN_BANK4_AUTHCODE’, ‘PSN_FACEAUTH_BYURL’]; //指定页面显示认证方式
$arrCurlData[‘contextInfo’] = [
“contextId” => $intUserId . ‘_’ . ‘individual’, //发起方业务上下文标识在异步通知时发送回发起方,可填写业务ID和其他参数等,需要string,可以拼接形式返回,参数不宜过长
‘notifyUrl’ => config(‘esign.notifyUrl’), //异步回调URL,回调内容详看https://open.esign.cn/doc/detail?namespace=opendoc%2Fidentity_service&id=opendoc%2Fidentity_service%2Fawa4m6
‘origin’ => ‘BROWSER’, //认证发起来源,BROWSER – 浏览器;APP – 移动端APP。不填默认为为BROWSER
‘redirectUrl’ => config(‘esign.redirectUrlPersonal’), //认证结束后跳转地址,
“showResultPage” => config(‘esign.showResultPage’), //认证完成是否显示结果页,默认显示
];
$arrCurlData[‘indivInfo’] = [
“name” => $strName, //真实姓名
“nationality” => “”, //个人证件号所属地区/国籍,默认留空
“certType” => “”,
/*
|—————————————————————————
+个人证件类型
+INDIVIDUAL_CH_IDCARD中国大陆身份证INDIVIDUAL_CH_TWCARD台湾来往大陆通行证
+INDIVIDUAL_CH_HONGKONG_MACAO港澳来往大陆通行证
+INDIVIDUAL_PASSPORT护照
|—————————————————————————
*/
“certNo” => $strCertNo, //证件号
“mobileNo” => $strMobileNo, //手机号
“bankCardNo” => “” //银行卡号
];
$arrCurlData[“repeatIdentity”] = true; //重名允许
//发起
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) return false;
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiRealIndiviDual’);
$strUrl = str_replace(“{accountId}”, $strEsignUidpersonal, $strUrl);
$strCurlResJson = curl_http($strUrl, $arrCurlData, true, $arrCurlHeader, ‘POST’);
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [“ok” => false, “msg” => $arrCurlRes[‘message’]];
return [“ok” => true, “data” => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [“ok” => false, “msg” => ‘JSON解码失败!’];
}
}
/**
* 注册企业账户
*
* @param [type] $intUserId 注册的用户ID,
* @param [type] $strCreator 创建人E签宝账户ID
* @param [type] $strName 机构名称
* @param [type] $intIdType 证件类型,1=统一社会信用代码,2=工商注册号
* @param [type] $strIdNumber 证件号
* @param string $strOrgLegalIdNumber 法人身份证号,选填
* @param string $strOrgLegalName 法人姓名,选填
* @return void
* @author 一颗大萝北 [email protected]
*/
public function addOrganizations($intUserId, $strCreator, $strName, $intIdType, $strIdNumber, $strOrgLegalIdNumber = “”, $strOrgLegalName = “”)
{
/*
|———————————————————-
|thirdPartyUserId 机构唯一标识,不能和个人一致
|creator 创建人个人账号id(调用个人账号创建接口返回的accountId)
|name 机构名称
|idType 证件类型,CRED_ORG_USCC统一社会信用代码(默认值),CRED_ORG_REGCODE工商注册号
|idNumber 证件号
|orgLegalIdNumber 企业法人证件号
|orgLegalName 企业法人名称
|———————————————————-
*/
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strIdType = ‘CRED_ORG_USCC’;
if (intval($intIdType) != 1) $strIdType = ‘CRED_ORG_REGCODE’;
$arrCurlData = array();
$arrCurlData[‘thirdPartyUserId’] = $intUserId . ‘_organizations’;
$arrCurlData[‘creator’] = $strCreator;
$arrCurlData[‘name’] = $strName;
$arrCurlData[‘idType’] = $strIdType;
$arrCurlData[‘idNumber’] = $strIdNumber;
$arrCurlData[‘orgLegalIdNumber’] = $strOrgLegalIdNumber;
$arrCurlData[‘orgLegalName’] = $strOrgLegalName;
$strCurlResJson = curl_http(config(‘esign.apiBasrUrl’) . config(‘esign.apiAddUserEnterprise’), $arrCurlData, true, $arrCurlHeader, ‘POST’);
/* 返回示例
|——————————————————————
+ {
+ “code”: 0,
+ “message”: “成功”,
+ “data”: {
+ “orgId”: “277f63ca9c0a43b594b40b28a1614aff”
+ }
+ }
|——————————————————————
*/
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [“ok” => false, “msg” => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [“ok” => true, “orgId” => $arrCurlRes[‘data’][‘orgId’], ‘result’ => $arrCurlRes[‘code’]];
} catch (\Throwable $e) {
return [“ok” => false, “msg” => ‘JSON解码失败!’];
}
}
/**
* 删除注册的企业账户
*
* @param [type] $strOrgId
* @return void
* @author 一颗大萝北 [email protected]
*/
public function delOrganizations($strOrgId)
{
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiDelUserEnterprise’);
$strUrl = str_replace(“{accountId}”, $strOrgId, $strUrl);
$strCurlResJson = curl_http($strUrl, [], false, $arrCurlHeader, ‘DELETE’);
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [“ok” => false, “msg” => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [“ok” => true, “accountId” => $arrCurlRes[‘data’][‘accountId’], ‘result’ => $arrCurlRes[‘code’]];
} catch (\Throwable $e) {
return [“ok” => false, “msg” => ‘JSON解码失败!’,];
}
}
/**
* 发起企业认证
*
* @param [type] $intUserId 用户ID
* @param [type] $strAccountId E签宝注册的组织ID
* @param [type] $strAgentAccountId E签宝注册的个人ID
* @param [type] $strName 组织名称
* @param [type] $strCertNo 组织识别号
* @param string $strLegalRepCertNo 法人身份证
* @param string $strLegalRepName 法人姓名
* @return void
* @author 一颗大萝北 [email protected]
*/
public function authOrganizations($intUserId, $strAccountId, $strAgentAccountId, $strName, $strCertNo, $strLegalRepCertNo = “”, $strLegalRepName = “”)
{
/*
|————————————————
|accountId 待认证e签宝企业账号Id
|agentAccountId 办理人账号Id
|contextInfo 业务方交互上下文信息[数组]
|->contextId 发起方业务上下文标识,在异步通知时发送回发起方
|->notifyUrl 发起方接收实名认证状态变更通知的地址,异步通知
|->origin 认证发起来源
|->redirectUrl 完成认证后跳转地址
|->showResultPage 实名完成是否显示结果页,默认显示
|orgEntity 组织机构基本信息[数组]
|->name 机构名称
|->certNo 组织机构证件号
|->legalRepCertNo 法定代表人身份证号
|->legalRepName 法定代表人姓名
|————————————————
*/
$arrCurlData = array();
$arrCurlData[‘agentAccountId’] = $strAgentAccountId;
$arrCurlData[‘contextInfo’] = [];
$arrCurlData[‘contextInfo’][‘contextId’] = $intUserId . ‘_company’;
$arrCurlData[‘contextInfo’][‘notifyUrl’] = config(‘esign.notifyUrl’);
$arrCurlData[‘contextInfo’][‘redirectUrl’] = config(‘esign.redirectUrlCompany’);
$arrCurlData[‘contextInfo’][‘origin’] = config(‘esign.origin’);
$arrCurlData[‘contextInfo’][‘redirectUrl’] = config(‘esign.redirectUrlCompany’);
$arrCurlData[‘contextInfo’][‘showResultPage’] = config(‘esign.showResultPage’);
$arrCurlData[‘orgEntity’] = [];
$arrCurlData[‘orgEntity’][‘name’] = $strName;
$arrCurlData[‘orgEntity’][‘certNo’] = $strCertNo;
$arrCurlData[‘orgEntity’][‘legalRepCertNo’] = $strLegalRepCertNo;
$arrCurlData[‘orgEntity’][‘legalRepName’] = $strLegalRepName;
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiRealEnterprise’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$strCurlResJson = curl_http($strUrl, $arrCurlData, true, $arrCurlHeader, ‘POST’);
/*
*响应示例
|————————————————————–
| {
| “code”: 0,
| “data”: {
| “flowId”: “业务号”,
| “shortLink”: “短连接”,
| “url”: “完整URL”
| },
| “message”: “成功”
| }
|————————————————————–
*/
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [“ok” => false, “msg” => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [“ok” => true, “data” => $arrCurlRes[‘data’], ‘result’ => $arrCurlRes[‘code’]];
} catch (\Throwable $e) {
return [“ok” => false, “msg” => ‘JSON解码失败!’];
}
}
/**
* 私有函数,设置请求头
*
* @return void
* @author 一颗大萝北 [email protected]
*/
private function getHeader()
{
$strSignToken = $this->getToken();
if (empty($strSignToken)) return false;
$arrCurlHeader = array();
$arrCurlHeader[‘X-Tsign-Open-App-Id’] = config(‘esign.appId’);
$arrCurlHeader[‘X-Tsign-Dns-App-Id’] = config(‘esign.appId’);
$arrCurlHeader[‘X-Tsign-Open-Token’] = $strSignToken;
$arrCurlHeader[‘Content-Type’] = ‘application/json’;
return $arrCurlHeader;
}
/**
* 创建个人印章模板
*
* @param [type] $strAccountId 用户ID
* @param string $strAlias 别名,选填
* @param integer $intColor 颜色,1=红色,2=蓝色,其他=黑色
* @param integer $intHeight 高度,默认95px 整数型
* @param integer $intWidth 宽度,默认95px 整数型
* @param integer $intType 样式,1=正方形,2=矩形印章,其他=无框矩形印章
* @return void
* @author 一颗大萝北 [email protected]
*/
public function newPersonalTemplate($strAccountId, $strAlias = “”, $intColor = 1, $intHeight = 95, $intWidth = 95, $intType = 1)
{
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiPersonalTemplate’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$arrCurlData = array();
$arrCurlData[‘alias’] = $strAlias;
switch ($intColor) {
case 1:
$arrCurlData[‘color’] = ‘RED’; //红色
break;
case 2:
$arrCurlData[‘color’] = ‘BLUE’; //蓝色
break;
default:
$arrCurlData[‘color’] = ‘BLACK’; //黑色
break;
}
$arrCurlData[‘height’] = $intHeight;
$arrCurlData[‘width’] = $intWidth;
switch ($intType) {
case 1:
$arrCurlData[‘type’] = ‘SQUARE’; //正方形
break;
case 2:
$arrCurlData[‘type’] = ‘RECTANGLE’; //矩形印章
break;
default:
$arrCurlData[‘type’] = ‘BORDERLESS’; //无框矩形印章
break;
}
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 创建企业印章模板
*
* @param [type] $strAccountId 用户ID
* @param integer $intType 类型,默认1=圆章,其他=椭圆章
* @param integer $intCentral 中心图案类型,1=中间有五角星,其他=没有五角星
* @param string $strAlias 别名,选填
* @param integer $intColor 颜色,1=红色,2=蓝色,其他=黑色
* @param integer $intHeight 高度,默认159px 整数型
* @param integer $intWidth 宽度,默认159px 整数型
* @param integer $strHtext 横向文,可设置0-8个字,企业名称超出25个字后,不支持设置横向文
* @param integer $strQtext 下弦文,可设置0-20个字,企业企业名称超出25个字后,不支持设置下弦文
* @return void
* @author 一颗大萝北 [email protected]
*/
public function newOfficialTemplate($strAccountId, $intType = 1, $intCentral = 1, $strAlias = “”, $intColor = 1, $intHeight = 159, $intWidth = 159, $strHtext = “”, $strQtext = “”)
{
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiOfficialTemplate’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$arrCurlData = array();
$arrCurlData[‘central’] = ‘STAR’; //圆形有五角星
if ($intCentral != 1) $arrCurlData[‘central’] = ‘NONE’; //圆形无五角星
$arrCurlData[‘type’] = ‘TEMPLATE_ROUND’; //圆章
if ($intType != 1) $arrCurlData[‘type’] = ‘TEMPLATE_OVAL’; //椭圆章
$arrCurlData[‘alias’] = $strAlias;
$arrCurlData[‘height’] = $intHeight;
$arrCurlData[‘width’] = $intWidth;
$arrCurlData[‘htext’] = $strHtext;
$arrCurlData[‘qtext’] = $strQtext;
switch ($intColor) {
case 1:
$arrCurlData[‘color’] = ‘RED’; //红色
break;
case 2:
$arrCurlData[‘color’] = ‘BLUE’; //蓝色
break;
default:
$arrCurlData[‘color’] = ‘BLACK’; //黑色
break;
}
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 创建个人/机构印章
*
* @param [type] $strAccountId 用户ID
* @param [type] $strImgPath 图片路径
* @param string $strAlias 别名,选填
* @param integer $intHeight 高,默认159,选填
* @param integer $intWidth 宽,默认159,选填
* @return void
* @author 一颗大萝北 [email protected]
*/
public function newSeal($strAccountId, $strImgPath, $strAlias = “”, $intHeight = 159, $intWidth = 159)
{
if (!is_file($strImgPath)) return [‘ok’ => false, ‘msg’ => ‘图片路径错误/不存在’];
if (!isImg($strImgPath)) return [‘ok’ => false, ‘msg’ => ‘传入的文件路径不是图片类型,仅允许jpg,png,gif’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSealsImage’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$arrCurlData = array();
$arrCurlData[‘alias’] = $strAlias;
$arrCurlData[‘height’] = $intHeight;
$arrCurlData[‘width’] = $intWidth;
$arrCurlData[‘type’] = ‘BASE64’;
$arrCurlData[‘data’] = imageToBase64($strImgPath, false);
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 查询个人印章
*
* @param [type] $strAccountId E签宝用户ID
* @param integer $intOffset 起始页
* @param integer $intSize 每页几条
* @return void
* @author 一颗大萝北 [email protected]
*/
public function checkPersonalSeals($strAccountId, $intOffset = 1, $intSize = 10)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiCheckPersonalSeals’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$strUrl .= ‘?offset=’ . $intOffset . ‘&size=’ . $intSize;
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘GET’, [], $arrCurlHeader);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 查询企业印章
*
* @param [type] $strAccountId E签宝用户ID
* @param integer $intOffset 起始页
* @param integer $intSize 每页几条
* @return void
* @author 一颗大萝北 [email protected]
*/
public function checkOfficialSeals($strAccountId, $intOffset = 1, $intSize = 10)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiCheckOfficialSeals’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$strUrl .= ‘?offset=’ . $intOffset . ‘&size=’ . $intSize;
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘GET’, [], $arrCurlHeader);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 删除个人印章
*
* @param [type] $strAccountId 用户E签宝ID
* @param [type] $strSealId 印章ID
* @return void
* @author 一颗大萝北 [email protected]
*/
public function delPersonalSeals($strAccountId, $strSealId)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiDelPersonalSeals’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$strUrl = str_replace(“{sealId}”, $strSealId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘DELETE’, [], $arrCurlHeader);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘msg’ => $arrCurlRes[‘message’], ‘data’ => $arrCurlRes];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 删除企业印章
*
* @param [type] $strAccountId 用户E签宝ID
* @param [type] $strSealId 印章ID
* @return void
* @author 一颗大萝北 [email protected]
*/
public function delOfficialSeals($strAccountId, $strSealId)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiDelOfficialSeals’);
$strUrl = str_replace(“{accountId}”, $strAccountId, $strUrl);
$strUrl = str_replace(“{sealId}”, $strSealId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘DELETE’, [], $arrCurlHeader);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘msg’ => $arrCurlRes[‘message’], ‘data’ => $arrCurlRes];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 创建新的模板获取上传链接,获取到连接在一个小时内可以重复只用,但会覆盖上次上传的合同文件
*
* @param [string] $strFileName 文件名称后缀名需要和文件类型的后缀一致,建议直传PDF,避免E签宝那边出现的转换错误或耗时过长
* @param [string] $strContentMd5 模板文件md5的BASE64的编码
* @param [string] $strContentType 文件类型,支持PDF和DOC/X参数application/octet-stream = DOC/X ,application/pdf = PDF
* @param [string] $boolConvert2Pdf 是否转换为PDF,文件类型不为PDF时使用
* @return void
* @author 一颗大萝北 [email protected]
*/
public function newContractTemplate($strFileName, $strContentMd5, $strContentType = ‘application/octet-stream’, $boolConvert2Pdf = true)
{
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
if ($strContentType != ‘application/octet-stream’) {
$boolConvert2Pdf = false;
}
$arrCurlData = array();
$arrCurlData[‘contentMd5’] = $strContentMd5;
$arrCurlData[‘contentType’] = $strContentType;
$arrCurlData[‘fileName’] = $strFileName;
$arrCurlData[‘convert2Pdf’] = $boolConvert2Pdf;
$strCurlResJson = curl_http(config(‘esign.apiBasrUrl’) . config(‘esign.apiNewContractTemplate’), $arrCurlData, true, $arrCurlHeader, ‘POST’);
/*
|—————————————————
|响应示例
|—————————————————
|{
| “code”: 0,
| “data”: {
| “templateId”: “adfadfadfweweafadfadfa”,
| “uploadUrl”: “https://esignoss.oss-cn-hangzhou.aliyuncs.com/1111563786/5d45dc91-470b-41dd-8e6f-9663ee9641db/%E6%89%B9%E9%87%8F%E5%AF%BC%E5%85%A5-%E9%94%99%E8%AF%AF%E6%95%B0%E6%8D%AE.xls?Expires=1559294245&OSSAccessKeyId=LTAIdvHfiVrzDKbE&Signature=hBEuUHAC7TVxzRIr/BihG1m3QEQ%3D”
| },
| “message”: “成功”
|}
|—————————————————
*/
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘创建模板获取上传URL时JSON解码失败’];
}
}
/**
* 上传模板文件,前置为创建新模板获取上传连接
*
* @param [type] $strUrl 文件上传URL,通过newContractTemplate获取
* @param [type] $strFilePatn 文件路径
* @param [type] $strContentMd5 文件MD5的BASE64要和newContractTemplate传递的一致
* @param string $strContentType 文件类型,和newContractTemplate一致
* @return void
* @author 一颗大萝北 [email protected]
*/
public function uploadContractTemplate($strUrl, $strFilePatn, $strContentMd5, $strContentType = ‘application/octet-stream’)
{
$arrCurlHeader = array();
$arrCurlHeader[‘Content-MD5’] = $strContentMd5;
$arrCurlHeader[‘Content-Type’] = $strContentType;
$strCurlResJson = curl_http($strUrl, $strFilePatn, false, $arrCurlHeader, ‘PUT’);
return [‘ok’ => true, ‘data’ => $strCurlResJson];
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if (empty($arrCurlRes[‘code’]) && $arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘上传模板时JSON解析失败!’, ‘result’ => $strCurlResJson];
}
}
/**
* 获取文件上传的md5和文件类型
*
* @param [type] $strFilePatn 文件路径
* @return void
* @author 一颗大萝北 [email protected]
*/
public function getFileUpinfo($strFilePatn)
{
//获取文件MD5转为BASE64
$strFileMd5 = md5_file($strFilePatn, true);
$strBase64Md5 = base64_encode($strFileMd5);
//使用finfo获取文件mime
$objFinfo = new finfo(FILEINFO_MIME_TYPE);
$strMime = $objFinfo->file($strFilePatn); //这个返回的并不准确.doc/x会返回zip
return [‘ContentMd5’ => $strBase64Md5, ‘strMime’ => $strMime];
}
/**
* 查询模板状态及获取下载地址
*
* @param [type] $strTemplateId 模板ID
* @return void
* @author 一颗大萝北 [email protected]
*/
public function templateDown($strTemplateId)
{
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiTemplateDown’);
$strUrl = str_replace(“{templateId}”, $strTemplateId, $strUrl);
$strCurlResJson = curl_http($strUrl, [], false, $arrCurlHeader, ‘GET’);
/*
* |——————————————————————
* |响应示例
* |——————————————————————
* |{
* |”code”: 0,
* |”message”: “成功”,
* |”data”: {
* | “templateId”: “78f86dfe01f64d0382a05fb3ff36a9be”,
* | “fileSize”: 324292,
* | “templateName”: “个人借贷模板”,
* | “templateFileStatus”: 1,
* | “createTime”: 1546508768000,
* | “updateTime”: 1546508768000
* |}
* |——————————————————————
*/
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if (empty($arrCurlRes[‘code’]) && $arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘上传模板时JSON解析失败!’, ‘result’ => $strCurlResJson];
}
}
/**
* 设置合同模板组件
*
* @param [type] $strTemplateId 模板ID
* @param [type] $arrComponents 组件参数,格式如下
* |———————————————-
* | 格式二维数组
* |———————————————-
* |[[
* | ‘id’ => ”,//ID创建新组件必须为空,不为空为修改,如果修改必须保证本参数ID存在
* | ‘type’=>’1,2,3,6’,//组件类型,1-文本,2-数字,3-日期,6-签约区
* | ‘label’=>’组件标题’,
* | ‘required’=>true/false,//是否必填,默认true
* | ‘limit’=>’ yyyy-MM-dd’,//非必填,输入项组件type=2,type=3时填充格式校验规则;数字格式如:# 或者 #00.0# 日期格式如: yyyy-MM-dd
* | ‘width’=>’宽度’,//组件宽度 int,
* | ‘height’=>’高度’,//组件高度 int
* | ‘font’=>”,//填充字体,1-5,1-宋体,2-新宋体,3-微软雅黑,4-黑体,5-楷体,非必填
* | ‘fontSize’=>”,//填充字体大小,默认12,非必填
* | ‘textColor’=>”,//字体颜色,默认#000000黑色,非必填
* | ‘page’=>”,//组件页码,必填
* | ‘y’=>”,//组件存放Y坐标
* | ‘x’=>”,//组件存放x坐标
* |],[]…]
* @return void
* @author 一颗大萝北 [email protected]
*/
public function setTemplateComponents($strTemplateId, $arrComponents)
{
$arrCurlData = array();
$arrCurlData[‘structComponents’] = array();
foreach ($arrComponents as $k => $item) {
$arrItem = array();
if ($item[‘type’] != 1 && $item[‘type’] != 2 && $item[‘type’] != 3 && $item[‘type’] != 6) return [‘ok’ => false, ‘msg’ => ‘存在错误的组件类型’];
$arrItem[‘type’] = $item[‘type’];
if (!empty($item[‘id’])) $arrItem[‘id’] = $item[‘id’];
$arrItem[‘context’] = array();
if (empty($item[‘label’])) return [‘ok’ => false, ‘msg’ => ‘存在错误的组件标题’];
$arrItem[‘context’][‘label’] = $item[‘label’];
if ($item[‘type’] == 2) $arrItem[‘context’][‘limit’] = $item[‘limit’] ? $item[‘limit’] : ‘#’;
if ($item[‘type’] == 3) $arrItem[‘context’][‘limit’] = $item[‘limit’] ? $item[‘limit’] : ‘yyyy-MM-dd’;
$arrItem[‘context’][‘style’] = array();
if (empty($item[‘width’]) || $item[‘width’] < 0) return [‘ok’ => false, ‘msg’ => ‘存在错误的组件宽度’];
if (empty($item[‘height’]) || $item[‘height’] < 0) return [‘ok’ => false, ‘msg’ => ‘存在错误的组件高度’];
$arrItem[‘context’][‘style’][‘width’] = $item[‘width’];
$arrItem[‘context’][‘style’][‘height’] = $item[‘height’];
$arrItem[‘context’][‘style’][‘font’] = $item[‘font’] ? $item[‘font’] : 1;
if ($arrItem[‘context’][‘style’][‘font’] < 1 || $arrItem[‘context’][‘style’][‘font’] > 5) $arrItem[‘context’][‘style’][‘font’] = 1;
$arrItem[‘context’][‘style’][‘fontSize’] = $item[‘fontSize’] ? $item[‘fontSize’] : 12;
if ($arrItem[‘context’][‘style’][‘fontSize’] < 1 || $arrItem[‘context’][‘style’][‘fontSize’] > 5) $arrItem[‘context’][‘style’][‘fontSize’] = 12;
$arrItem[‘context’][‘style’][‘textColor’] = $item[‘textColor’] ? $item[‘textColor’] : ‘#000000’;
$arrItem[‘context’][‘pos’] = array();
if (empty($item[‘page’]) || $item[‘page’] < 1) return [‘ok’ => false, ‘msg’ => ‘存在错误的组件模板页码’];
$arrItem[‘context’][‘pos’][‘page’] = $item[‘page’];
if (empty($item[‘y’]) || $item[‘y’] < 1) return [‘ok’ => false, ‘msg’ => ‘存在错误的组件模板坐标’];
$arrItem[‘context’][‘pos’][‘y’] = $item[‘y’];
if (empty($item[‘x’]) || $item[‘x’] < 1) return [‘ok’ => false, ‘msg’ => ‘存在错误的组件模板坐标’];
$arrItem[‘context’][‘pos’][‘x’] = $item[‘x’];
$arrCurlData[‘structComponents’][] = $arrItem;
}
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSetTemplateComponents’);
$strUrl = str_replace(“{templateId}”, $strTemplateId, $strUrl);
$strCurlResJson = curl_http($strUrl, $arrCurlData, true, $arrCurlHeader, ‘POST’);
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
$arrResData = array();
foreach ($arrCurlRes[‘data’] as $k => $item) {
$arrComponents[$k][‘id’] = $item;
$arrResData[] = $arrComponents[$k];
}
return [‘ok’ => true, ‘data’ => $arrResData];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 删除模板的组件
*
* @param [type] $strTemplateId 模板ID
* @param [type] $arrComponents 组件ID,格式[‘模板ID’,….]
* @return void
* @author 一颗大萝北 [email protected]
*/
public function delTemplateComponents($strTemplateId, $arrComponents)
{
$strComponentsId = “”;
$intIndex = 1;
$intCountComponentsId = count($arrComponents);
foreach ($arrComponents as $k => $v) {
$strComponentsId .= $v;
if ($intIndex < $intCountComponentsId) $strComponentsId .= ‘,’;
$intIndex++;
}
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiDelTemplateComponents’);
$strUrl = str_replace(“{templateId}”, $strTemplateId, $strUrl);
$strUrl = str_replace(“{components}”, $strComponentsId, $strUrl);
$arrCurlHeader = $this->getHeader();
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strCurlResJson = curl_http($strUrl, [], false, $arrCurlHeader, ‘DELETE’);
try {
$arrCurlRes = json_decode($strCurlResJson, true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘msg’ => $arrCurlRes[‘message’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 签署流程创建
*
* @param [type] $strThemeName 主题名称
* @param [type] $intValidity 文件有效截止日期,毫秒,默认不失效;若时间到了该参数设置的时间,则会触发【流程文件过期通知】
* @param [type] $intRemind 文件到期前,提前多少小时回调提醒续签,小时(时间区间:1小时——15天),默认不提醒;若时间到了该参数设置的时间,则会触发【流程文件过期前通知】
* @param [type] $strNotifyParm 回调参数
* @param [type] $strAccountId 发起人账户id,即发起本次签署的操作人个人账号id;如不传,默认由对接平台发起
* @param [type] $strAuthorized 发起方主体id,如存在个人代机构发起签约,则需传入机构id;如不传,则默认是对接平台
* @param [type] $isAutoArchive 是否自动归档,默认true;如设置为true,则在调用签署流程开启后,当所有签署人签署完毕,系统自动将流程归档,状态变为“已完成”状态;如设置为false,则在调用流程开启后,需主动调用签署流程归档接口,将流程状态变更为“已完成”;已完成的流程才可下载签署后的文件
* @param [type] $strNoticeType 通知方式,逗号分割,1-短信,2-邮件 。默认值1,请务必请选择一个通知方式,,短信或者邮件获取到的签署链接,有效期默认30天
* @param [type] $strSignPlatform 签署平台,逗号分割,1-开放服务h5,2-支付宝签 ,默认值1,2
* @return void
* @author 一颗大萝北 [email protected]
*/
public function createSignFlows($strThemeName, $intValidity, $intRemind, $strNotifyParm = ”, $strAccountId = “”, $strAuthorized = “”, $isAutoArchive = true, $strNoticeType = “1,2”, $strSignPlatform = “1,2”)
{
$arrCurlData = array();
$arrCurlData[‘autoArchive’] = $isAutoArchive;
$arrCurlData[‘businessScene’] = $strThemeName;
$arrCurlData[‘configInfo’] = array();
$arrCurlData[‘configInfo’][‘noticeDeveloperUrl’] = config(‘esign.signFlowsNotifyUrl’) . $strNotifyParm;
$arrCurlData[‘configInfo’][‘noticeType’] = $strNoticeType;
$arrCurlData[‘configInfo’][‘redirectUrl’] = config(‘esign.signFlowsRedirectUrl’);
$arrCurlData[‘configInfo’][‘signPlatform’] = $strSignPlatform;
$arrCurlData[‘contractValidity’] = $intValidity;
$arrCurlData[‘signValidity’] = $intValidity;
$arrCurlData[‘contractRemind’] = $intRemind;
$arrCurlData[‘initiatorAccountId’] = $strAccountId;
$arrCurlData[‘initiatorAuthorizedAccountId’] = $strAuthorized;
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$strCurlResJson = curlRequest(config(‘esign.apiBasrUrl’) . config(‘esign.apiSignFlows’), ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$strCurlResJson[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $strCurlResJson];
/*
|—————————————————
|响应示例
|—————————————————
|{
| “code”:0,
| “message”:”成功”,
| “data”:{
| “flowId”:”429b1d3038854cabbcdac0a63d7e4c0d”
| }
|}
|—————————————————
*/
try {
$arrCurlRes = json_decode($strCurlResJson[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘flowId’ => $arrCurlRes[‘data’][‘flowId’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 撤销流程
*
* @param [type] $strFlowId 流程ID
* @param [type] $strRevokeReason 撤销原因
* @param string $strOperatorId 发起人ID,可留空,如不传,默认由对接平台发起
* @return void
* @author 一颗大萝北 [email protected]
*/
public function revokeSignFlows($strFlowId, $strRevokeReason, $strOperatorId = “”)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSignFlowsRevoke’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlData = array();
$arrCurlData[‘operatorId’] = $strOperatorId;
$arrCurlData[‘revokeReason’] = $strRevokeReason;
$strCurlResJson = curlRequest($strUrl, ‘PUT’, $arrCurlData, $arrCurlHeader, true);
if (!$strCurlResJson[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $strCurlResJson];
try {
$arrCurlRes = json_decode($strCurlResJson[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘flowId’ => $arrCurlRes[‘data’][‘flowId’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 创建合同文件
*
* @param [type] $strName 文件名称(必须带上文件扩展名,不然会导致后续发起流程校验过不去 示例:合同.pdf );
* @param [type] $strTmplateId E签宝模板编号(ID)
* @param [type] $arrSimpleFormFields 输入项填充内容[[‘模板ID’=>’填充内容’],….]
* @return void
* @author 一颗大萝北 [email protected]
*/
public function createByTemplate($strName, $strTmplateId, $arrSimpleFormFields)
{
$arrCurlData = array();
$arrCurlData[‘name’] = $strName;
$arrCurlData[‘templateId’] = $strTmplateId;
foreach ($arrSimpleFormFields as $k => $item) {
$arrCurlData[‘simpleFormFields’][$k] = $item;
}
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResJson = curlRequest(config(‘esign.apiBasrUrl’) . config(‘esign.apiCreateByTemplate’), ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$arrCurlResJson[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResJson];
try {
$arrCurlRes = json_decode($arrCurlResJson[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘fileId’ => $arrCurlRes[‘data’][‘fileId’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 流程文档添加
*
* @param [type] $strFlowId 流程ID
* @param [type] $strFileId 文档id
* @param [type] $strFileName 文件名称(必须带上文件扩展名,不然会导致后续发起流程校验过不去 示例:合同.pdf )
* @param boolean $isEncryption 是否加密
* @param string $strFilePassword 加密的密码
* @return void
* @author 一颗大萝北 [email protected]
*/
public function signFlowsAddDocuments($strFlowId, $strFileId, $strFileName, $isEncryption = false, $strFilePassword = ”)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSignFlowsAddDocuments’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$arrCurlData = array();
$arrCurlData[‘docs’] = array();
$arrCurlData[‘docs’][0][‘encryption’] = 0;
if ($isEncryption) $arrCurlData[‘docs’][0][‘encryption’] = 1;
if ($isEncryption) $arrCurlData[‘docs’][0][‘filePassword’] = $strFilePassword;
$arrCurlData[‘docs’][0][‘fileId’] = $strFileId;
$arrCurlData[‘docs’][0][‘fileName’] = $strFileName;
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 签署流程查询
*
* @param [type] $strFlowId 流程ID
* @return void
* @author 一颗大萝北 [email protected]
*/
public function signFlowsCheck($strFlowId)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSignFlowsCheck’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘GET’, [], $arrCurlHeader);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘CURL请求失败’, ‘result’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 签署流程开始
*
* @param [type] $strFlowId 流程ID
* @return void
* @author 一颗大萝北 [email protected]
*/
public function signflowsStart($strFlowId)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSignflowsStart’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘PUT’, [], $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 添加平台自动签署区
*
* @param [type] $strFlowId 流程ID
* @param [type] $strFileId 文档ID
* @param [type] $intPosPage自动签署区页面
* @param [type] $intPosY 签署区Y坐标
* @param string $intPosX 签署区X坐标
* @param string $strSeal 签署区印章
* @param string $intWidth 签署区宽度
* @return void
* @author 一颗大萝北 [email protected]
*/
public function addPlatformSign($strFlowId, $strFileId, $intPosPage, $intPosY, $intPosX, $strSeal = ”, $intWidth = ”)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiPlatformSign’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlData = array();
$arrCurlDataTmp = array();
$arrCurlData[‘signfields’] = array();
$arrCurlDataTmp[‘fileId’] = $strFileId;
$arrCurlDataTmp[‘sealId’] = $strSeal;
$arrCurlDataTmp[‘posBean’] = array();
$arrCurlDataTmp[‘posBean’][‘posPage’] = $intPosPage;
$arrCurlDataTmp[‘posBean’][‘posY’] = $intPosY;
$arrCurlDataTmp[‘posBean’][‘posX’] = $intPosX;
$arrCurlDataTmp[‘posBean’][‘width’] = $intWidth;
$arrCurlData[‘signfields’][] = $arrCurlDataTmp;
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’][‘signfieldBeans’][0]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 添加手动签署区
*
* @param [type] $strFlowId 流程ID
* @param [type] $strFileId 文件ID
* @param [type] $strUserEsignId 签署人E签宝ID
* @param string $strCUserEsignId 签署方(企业ID,选填,不留空为企业方填写)
* @param [type] $intPosPage 所在页码
* @param [type] $intPosY Y坐标
* @param string $intPosX X坐标
* @param string $intWidth 宽度
* @return void
* @author 一颗大萝北 [email protected]
*/
public function addHandSign($strFlowId, $strFileId, $strUserEsignId, $strCUserEsignId = “”, $intPosPage = “”, $intPosY = “”, $intPosX = ”, $intWidth = ”)
{
//apiHandSign
$arrCurlData = array();
$arrCurlDataTmp = array();
$arrCurlDataTmp[‘signerAccountId’] = $strUserEsignId;
$arrCurlDataTmp[‘authorizedAccountId’] = $strCUserEsignId;
if (!empty($strCUserEsignId)) $arrCurlDataTmp[‘actorIndentityType’] = 2;
$arrCurlDataTmp[‘fileId’] = $strFileId;
$arrCurlDataTmp[‘assignedPosbean’] = true;
$arrCurlDataTmp[‘posBean’] = array();
if (!empty($intPosPage)) $arrCurlDataTmp[‘posBean’][‘posPage’] = $intPosPage;
if (!empty($intPosX)) $arrCurlDataTmp[‘posBean’][‘posX’] = $intPosX;
if (!empty($intPosY)) $arrCurlDataTmp[‘posBean’][‘posY’] = $intPosY;
if (!empty($intWidth)) $arrCurlDataTmp[‘posBean’][‘width’] = $intWidth;
$arrCurlData[‘signfields’][] = $arrCurlDataTmp;
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiHandSign’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘POST’, $arrCurlData, $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’][‘signfieldBeans’][0]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 获取签署URL地址
*
* @param [type] $strFlowId 流程ID
* @param [type] $strAccountId 签署人ID
* @param string $strOrganizeId 企业ID(企业签时必须填写)
* @return void
* @author 一颗大萝北 [email protected]
*/
public function executeUrl($strFlowId, $strAccountId, $strOrganizeId = “”)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiExecuteUrl’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$strUrl .= ‘?accountId=’ . $strAccountId;
if (!empty($strOrganizeId)) $strUrl .= “&organizeId=” . $strOrganizeId;
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘GET’, [], $arrCurlHeader, false);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 查询签署区
*
* @param [type] $strFlowId 流程ID
* @param string $strAccountId 账号id,留空所有签署人
* @param string $strSignfieldIds 指定签署区id列表,逗号分割,留空所有签署区
* @return void
* @author 一颗大萝北 [email protected]
*/
public function signfields($strFlowId, $strAccountId = ”, $strSignfieldIds = ”)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSignfields’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$strUrl .= ‘?accountId=’ . $strAccountId . ‘&signfieldIds=’ . $strSignfieldIds;
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘GET’, [], $arrCurlHeader, false);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 查询文件详情/下载文件
*
* @param [type] $strFileId
* @return void
* @author 一颗大萝北 [email protected]
*/
public function downFiles($strFileId)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiDownFiles’);
$strUrl = str_replace(“{fileId}”, $strFileId, $strUrl);
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘GET’, [], $arrCurlHeader, false);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true, ‘data’ => $arrCurlRes[‘data’]];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
/**
* 下载合同文件
*
* @param [type] $strFlowId 流程ID
* @return void
* @author 一颗大萝北 [email protected]
*/
public function downSignFlowsDocuments($strFlowId)
{
$strUrl = config(‘esign.apiBasrUrl’) . config(‘esign.apiSignFlowsAddDocuments’);
$strUrl = str_replace(“{flowId}”, $strFlowId, $strUrl);
$arrCurlData = array();
$arrCurlHeader = $this->getHeader();;
if ($arrCurlHeader === false) [“ok” => false, “msg” => ‘header获取失败!’];
$arrCurlResInfo = curlRequest($strUrl, ‘GET’, [], $arrCurlHeader, true);
if (!$arrCurlResInfo[‘ok’]) return [‘ok’ => false, ‘msg’ => ‘curl请求失败’, ‘data’ => $arrCurlResInfo];
try {
$arrCurlRes = json_decode($arrCurlResInfo[‘data’], true);
if ($arrCurlRes[‘code’] != 0) return [‘ok’ => false, ‘msg’ => $arrCurlRes[‘message’], ‘result’ => $arrCurlRes[‘code’]];
return [‘ok’ => true,’data’=>$arrCurlRes[‘data’],’url’=>$strUrl];
} catch (\Throwable $e) {
return [‘ok’ => false, ‘msg’ => ‘JSON解码失败’];
}
}
}
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
一颗大萝北
本文地址: PHP/tp5~6封装了一个E签宝,实现个人实名认证,企业实名认证,电子签约
本文地址: PHP/tp5~6封装了一个E签宝,实现个人实名认证,企业实名认证,电子签约