217 lines
7.2 KiB
PHP
Executable File
217 lines
7.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: lcc
|
|
* Date: 2018/11/21
|
|
* Time: 15:12
|
|
*/
|
|
require_once COMMPATH."/third_party/esign/eSignOpenAPI.php";
|
|
|
|
class Esign{
|
|
|
|
protected $sign;
|
|
protected $pdf2img_url = 'https://open.xiaoyu.com/jar/pdf2img/index';
|
|
|
|
public function __construct(){
|
|
try {
|
|
$this->sign = new \tech\core\eSign();
|
|
$iRet = $this->sign->init();
|
|
if (0 !== $iRet) {
|
|
dir('初始化失败');
|
|
}
|
|
} catch (Exception $e) {
|
|
die('初始化出错:'.$e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成模板文件
|
|
* @param $array 填充内容array('域名'=>'值')
|
|
* @param $file_path 模板文件地址
|
|
* @param $save_path 生成合同保存路径
|
|
* @param $changeImg 是否转换成图片
|
|
* @return array
|
|
*/
|
|
public function createFromTemplate($array,$file_path,$save_path='',$changeImg=false){
|
|
$res['code'] = 1;
|
|
$tmpFile=array(
|
|
'srcFileUrl' =>$file_path,
|
|
'dstFileUrl' => ''
|
|
);
|
|
$ret = $this->sign->createFromTemplate($tmpFile,true,$array,true);
|
|
if($ret['errCode']!==0){
|
|
$res['code'] = 0;
|
|
$res['message']= $ret['msg'];
|
|
return $res;
|
|
}
|
|
if(!$save_path){
|
|
$filename = md5(uniqid().time());
|
|
$save_path = "temp/$filename.pdf";
|
|
}
|
|
file_put_contents($save_path, base64_decode($ret['stream']), true);
|
|
$res['data']['path']=$save_path;
|
|
if($changeImg){
|
|
$slhttp = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
|
$pdfurl =$slhttp.$_SERVER['SERVER_NAME'].'/'.$save_path;
|
|
$res['data']['imgs']=$this->pdfimg($pdfurl);
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 用户签名
|
|
* @param $mobile 用户手机号码
|
|
* @param $name 用户名字
|
|
* @param $id_card 用户身份证
|
|
* @param $sealData 签名信息
|
|
* @param $path 签名文件地址
|
|
* @param $signPos 签名位置array('posPage' => 5, 'posX' => 180, 'posY' => 230, 'key' => '', 'width' => 0, 'isQrcodeSign' => false)
|
|
* @param $savePath 保存文件地址
|
|
* @return array
|
|
*/
|
|
public function userSignPDF($mobile,$name,$id_card,$sealData,$path,$signPos,$savePath=''){
|
|
$res['code']=1;
|
|
//创建个人用户信息
|
|
$ret = $this->sign->addPersonAccount($mobile, $name, $id_card);
|
|
if($ret['errCode']!==0){
|
|
$res['code'] = 0;
|
|
$res['message']= $ret['msg'];
|
|
return $res;
|
|
}
|
|
if(!$savePath){
|
|
$savePath=$path;
|
|
}
|
|
$accountId = $ret['accountId'];
|
|
//新建模版印章
|
|
if(!$sealData){
|
|
$ret = $this->sign->addTemplateSeal($accountId);
|
|
if($ret['errCode']!==0){
|
|
$res['code'] = 0;
|
|
$res['message']= $ret['msg'];
|
|
return $res;
|
|
}
|
|
$sealData = $ret['imageBase64'];
|
|
}
|
|
//用户签署
|
|
$signType = 'Single';
|
|
$signFile = array(
|
|
'srcPdfFile' => $path,
|
|
'dstPdfFile' => $_SERVER['DOCUMENT_ROOT'].'/'.$savePath,
|
|
'fileName' => '',
|
|
'ownerPassword' => ''
|
|
);
|
|
$ret = $this->sign->userSignPDF($accountId, $signFile, $signPos, $signType, $sealData, $stream = true);
|
|
if($ret['errCode']!==0){
|
|
$res['code'] = 0;
|
|
$res['message']= $ret['msg'];
|
|
return $res;
|
|
}
|
|
$res['data']['path'] = $savePath;
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 商家签名
|
|
* @param $organMobile 商家电话
|
|
* @param $organName 商家名字
|
|
* @param $organCode 商家代码
|
|
* @param $orginSignPos 签名位置array('posPage' => 5, 'posX' => 400, 'posY' => 230, 'key' => '', 'width' => 0, 'isQrcodeSign' => false);
|
|
* @param $path 签名文件地址
|
|
* @param $savePath 保存文件地址
|
|
* @return array
|
|
*/
|
|
public function orginSignPDF($organMobile,$organName,$organCode,$orginSignPos,$path,$savePath){
|
|
$res['code']=1;
|
|
//企业模板印章,返回印章imgbase64
|
|
$organType = '0';
|
|
$email = '';
|
|
$regType = \tech\constants\OrganRegType::MERGE;
|
|
$legalArea = tech\constants\PersonArea::MAINLAND;
|
|
|
|
$ret = $this->sign->addOrganizeAccount($organMobile,
|
|
$organName,
|
|
$organCode,
|
|
$regType ,
|
|
$email,
|
|
$organType,
|
|
$legalArea );
|
|
if($ret['errCode']!==0){
|
|
$res['code'] = 0;
|
|
$res['message']= $ret['msg'];
|
|
return $res;
|
|
}
|
|
$accountId = $ret['accountId'];
|
|
$ret = $this->sign->addTemplateSeal(
|
|
$accountId,
|
|
$templateType = \tech\constants\OrganizeTemplateType::STAR,
|
|
$color = \tech\constants\SealColor::RED,
|
|
$hText = '合同专用',
|
|
$qText = '正式章'
|
|
);
|
|
if($ret['errCode']!==0){
|
|
$res['code'] = 0;
|
|
$res['message']= $ret['msg'];
|
|
return $res;
|
|
}
|
|
//企业签署
|
|
$sealData=$ret['imageBase64'];
|
|
$signType = 'Single';
|
|
$signFile = array(
|
|
'srcPdfFile' => $path,
|
|
'dstPdfFile' => $_SERVER['DOCUMENT_ROOT'].'/'.$savePath,
|
|
'fileName' => '',
|
|
'ownerPassword' => ''
|
|
);
|
|
$ret = $this->sign->userSignPDF($accountId, $signFile, $orginSignPos, $signType, $sealData, $stream = true);
|
|
if($ret['errCode']===0){
|
|
$res['code'] = 1;
|
|
$res['data']['path']= $savePath;
|
|
return $res;
|
|
}else{
|
|
$res['code'] = 0;
|
|
$res['message']= $ret['msg'];
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* pdf 转图片
|
|
* @param $pdfurl
|
|
* @return mixed
|
|
*/
|
|
public function pdfimg($pdfurl){
|
|
$post_data['furl'] =$pdfurl;
|
|
$url = $this->pdf2img_url."?furl=".$pdfurl;
|
|
$result = $this->post_json($url);
|
|
$result = json_decode($result,true);
|
|
if($result['data']){
|
|
return $result['data'];
|
|
}
|
|
}
|
|
|
|
public function delUserAccount($idNo){
|
|
$ret = $this->sign->getAccountInfoByIdNo($idNo, 11);
|
|
$accountId = $ret['accountInfo']['accountUid'];
|
|
$res = $this->sign->delUserAccount($accountId);
|
|
var_dump($res);
|
|
}
|
|
private function post_json($url){
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
|
|
//关闭https验证
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
$result = curl_exec($ch);
|
|
if (curl_errno($ch)) {
|
|
print curl_error($ch);
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
|
|
public function get_esign(){
|
|
return $this->sign;
|
|
}
|
|
} |