|
@@ -6,7 +6,11 @@ namespace App\Servers\ESign;
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Firm;
|
|
use App\Models\Firm;
|
|
|
|
|
+use App\Models\FirmSeal;
|
|
|
use App\Models\Member;
|
|
use App\Models\Member;
|
|
|
|
|
+use App\Models\MemberSeal;
|
|
|
|
|
+use App\Models\SignContract;
|
|
|
|
|
+use App\Models\SignRecord;
|
|
|
use App\Servers\ESign\comm\EsignHttpHelper;
|
|
use App\Servers\ESign\comm\EsignHttpHelper;
|
|
|
use App\Servers\ESign\comm\EsignLogHelper;
|
|
use App\Servers\ESign\comm\EsignLogHelper;
|
|
|
use App\Servers\ESign\comm\EsignUtilHelper;
|
|
use App\Servers\ESign\comm\EsignUtilHelper;
|
|
@@ -123,4 +127,185 @@ class ESignContractServer
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ function setContractContract($sign_id,$fileId,$signJson,$file_name)
|
|
|
|
|
+ {
|
|
|
|
|
+ $signJson = '[{"keyword":"fisher", "auth_type":"PSN", "id_no","AAAAA"}, {"keyword":"lily", "auth_type":"ORG", "id_no","AAAAA"}, {"keyword":"bob", "auth_type":"PSN", "id_no","AAAAA"}]';
|
|
|
|
|
+ $signData = json_decode($signJson,true);
|
|
|
|
|
+
|
|
|
|
|
+ $keywords=[];
|
|
|
|
|
+ foreach ($signData as $k=>$v){
|
|
|
|
|
+ $keywords[]=$v['keyword'];
|
|
|
|
|
+ }
|
|
|
|
|
+ //获取对应关键字定位
|
|
|
|
|
+
|
|
|
|
|
+ $positionRet=ESignContractServer::creatServer()->getKeywordPositions($fileId,$keywords);
|
|
|
|
|
+ if(empty($positionRet['code'])){
|
|
|
|
|
+ return ['code'=>0,'msg'=>'签署区域定位失败'];
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $positionData=$positionRet['data'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $signers=[];
|
|
|
|
|
+ foreach ($signData as $value){
|
|
|
|
|
+ //对应关键字做xy坐标匹配
|
|
|
|
|
+ foreach ($positionData as $item){
|
|
|
|
|
+ if(count($item['positions'])<=0){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if($item['keyword']==$value['keyword']){
|
|
|
|
|
+
|
|
|
|
|
+ $position=end($item['positions']);
|
|
|
|
|
+ $coordinate=end($position['coordinates']);
|
|
|
|
|
+ $value['positionPage'] = $position['pageNum'];
|
|
|
|
|
+ $value['positionX'] = $coordinate['positionX'];
|
|
|
|
|
+ $value['positionY'] = $coordinate['positionY'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $signersData = [];
|
|
|
|
|
+ //签署方是机构还是个人
|
|
|
|
|
+ if ($value['auth_type'] == 'PSN'){
|
|
|
|
|
+ $signerType = 0;
|
|
|
|
|
+ $member = Member::where('psnId',$value['id_no'])->first();
|
|
|
|
|
+ //获取企业签章
|
|
|
|
|
+ $m_id = $member->{'id'};
|
|
|
|
|
+ $seal=MemberSeal::where('m_id',$m_id)->select(['id','seal_id'])->first();
|
|
|
|
|
+ //组装信息
|
|
|
|
|
+ $signersData[] = [
|
|
|
|
|
+ "psnSignerInfo" => [
|
|
|
|
|
+ "psnAccount" => $member->{'phone'},
|
|
|
|
|
+ 'psnInfo'=>[
|
|
|
|
|
+ 'psnName'=>$member->{'name'},
|
|
|
|
|
+ 'psnIDCardNum'=>$member->{'id_number'},
|
|
|
|
|
+ 'psnIDCardType'=>'CRED_PSN_CH_IDCARD',
|
|
|
|
|
+ ],
|
|
|
|
|
+ ],
|
|
|
|
|
+ ];
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $signerType = 1;
|
|
|
|
|
+ $firm = Firm::where('orgId',$value['id_no'])-first();
|
|
|
|
|
+ //获取用户签章
|
|
|
|
|
+ $firm_id = $firm->{'id'};
|
|
|
|
|
+ $seal=FirmSeal::where('firm_id',$firm_id)->where('seal_type','CONTRACT')->select(['id','seal_id'])->first();
|
|
|
|
|
+ $signersData[] = [
|
|
|
|
|
+ "orgSignerInfo" => [
|
|
|
|
|
+ "orgName" => $firm->{'firm_name'},
|
|
|
|
|
+ 'orgInfo'=>[
|
|
|
|
|
+ 'orgIDCardNum'=>$firm->{'license_number'},
|
|
|
|
|
+ 'orgIDCardType'=>'CRED_ORG_USCC',
|
|
|
|
|
+ ],
|
|
|
|
|
+ "transactorInfo"=>[
|
|
|
|
|
+ "psnAccount"=>$firm['phone'],
|
|
|
|
|
+ 'psnInfo'=>[
|
|
|
|
|
+ 'psnIDCardNum'=>$firm['legal_id_number'],
|
|
|
|
|
+ 'psnIDCardType'=>'CRED_PSN_CH_IDCARD'
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ ],
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ //印章ID
|
|
|
|
|
+ $assignedSealId=$seal->{'seal_id'};
|
|
|
|
|
+
|
|
|
|
|
+ $signersData[] = [
|
|
|
|
|
+ "signFields" =>[
|
|
|
|
|
+ [
|
|
|
|
|
+ "fileId" =>$fileId,
|
|
|
|
|
+ "normalSignFieldConfig" => [
|
|
|
|
|
+ "autoSign" =>false,
|
|
|
|
|
+ "signFieldStyle" =>1,
|
|
|
|
|
+ "assignedSealId"=>$assignedSealId, // 在signFields中设置 assignedSealId为授权企业印章id
|
|
|
|
|
+ "signFieldPosition" => [
|
|
|
|
|
+ "positionPage" =>$value['pageNum'].'',
|
|
|
|
|
+ "positionX" =>(int)$value['positionX'],
|
|
|
|
|
+ "positionY" =>(int)$value['positionY'],
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]
|
|
|
|
|
+ ],
|
|
|
|
|
+ "signerType" =>$signerType
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $signers[]=$signersData;
|
|
|
|
|
+ //对应签署方做记录
|
|
|
|
|
+ SignRecord::create([
|
|
|
|
|
+ 'sign_id' => $sign_id,
|
|
|
|
|
+ 'authType' => $value['auth_type'],
|
|
|
|
|
+ 'id_no' => $value['id_no'],
|
|
|
|
|
+ 'keyword' => $value['keyword'],
|
|
|
|
|
+ 'page_num' => $value['pageNum'],
|
|
|
|
|
+ 'position_x' => $value['positionX'],
|
|
|
|
|
+ 'position_y' => $value['positionY'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(empty($signers)){
|
|
|
|
|
+ return ['code'=>0,'msg'=>'暂无可执行电签印章'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $flowId= $this->createByFile($fileId,$file_name.'.pdf',$file_name,$signers);
|
|
|
|
|
+
|
|
|
|
|
+ if($flowId){
|
|
|
|
|
+ SignContract::where('id',$sign_id)->update(['flow_id'=>$flowId]);
|
|
|
|
|
+
|
|
|
|
|
+ return ['code'=>1,'msg'=>'发起签署成功'];
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return ['code'=>0,'msg'=>'发起签署失败'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 合同签署
|
|
|
|
|
+ * @param $fileId
|
|
|
|
|
+ * @return false
|
|
|
|
|
+ */
|
|
|
|
|
+ function createByFile($fileId,$fileName,$signFlowTitle,$signers)
|
|
|
|
|
+ {
|
|
|
|
|
+ EsignLogHelper::printMsg("**********基于文件发起签署调用开始**********");
|
|
|
|
|
+ $config=$this->config;
|
|
|
|
|
+ $apiaddr="/v3/sign-flow/create-by-file";
|
|
|
|
|
+ $requestType = HttpEmun::POST;
|
|
|
|
|
+
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ "docs" =>[
|
|
|
|
|
+ [
|
|
|
|
|
+ "fileId" =>$fileId,
|
|
|
|
|
+ "fileName" =>$fileName
|
|
|
|
|
+ ]
|
|
|
|
|
+ ],
|
|
|
|
|
+ "signFlowConfig" => [
|
|
|
|
|
+ "signFlowTitle" =>$signFlowTitle,
|
|
|
|
|
+ "autoStart"=>true,
|
|
|
|
|
+ "autoFinish"=>true,
|
|
|
|
|
+ 'notifyUrl'=>route('notify.esignNotify')
|
|
|
|
|
+ ],
|
|
|
|
|
+ "signers"=>$signers
|
|
|
|
|
+ ];
|
|
|
|
|
+// dd($data);
|
|
|
|
|
+ $paramStr = json_encode($data);
|
|
|
|
|
+
|
|
|
|
|
+ $signAndBuildSignAndJsonHeader = EsignHttpHelper::signAndBuildSignAndJsonHeader($config['eSignAppId'], $config['eSignAppSecret'], $paramStr, $requestType, $apiaddr);
|
|
|
|
|
+
|
|
|
|
|
+ EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
|
|
|
|
|
+ $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, $paramStr);
|
|
|
|
|
+ EsignLogHelper::printMsg($response->getStatus());
|
|
|
|
|
+ EsignLogHelper::printMsg($response->getBody());
|
|
|
|
|
+
|
|
|
|
|
+ $signFlowId = false;
|
|
|
|
|
+ if($response->getStatus() == 200){
|
|
|
|
|
+ $result = json_decode($response->getBody());
|
|
|
|
|
+ if($result->code==0){
|
|
|
|
|
+ $signFlowId = $result->data->signFlowId;
|
|
|
|
|
+ EsignLogHelper::printMsg("基于文件发起签署接口调用成功,flowId: ".$signFlowId);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ EsignLogHelper::printMsg("基于文件发起签署接口调用失败,错误信息: ".$result->message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ EsignLogHelper::printMsg("基于文件发起签署接口调用失败,HTTP错误码".$response->getStatus());
|
|
|
|
|
+ }
|
|
|
|
|
+ EsignLogHelper::printMsg("**********基于文件发起签署调用结束**********");
|
|
|
|
|
+ return $signFlowId;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|