data_center/app/common/controller/JunziqianController.php

491 lines
21 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\controller;
use app\common\model\contract\VehicleContract;
use junziqian\sdk\bean\req\sign\ApplySignReq;
use junziqian\sdk\bean\req\user\OrganizationCreateReq;
use junziqian\sdk\bean\req\user\OrganizationFaceCreateReq;
use junziqian\sdk\util\exception\ResultInfoException;
use junziqian\sdk\util\RequestUtils;
use junziqian\sdk\util\ShaUtils;
use CURLFile;
use think\facade\Db;
class JunziqianController extends BaseLikeAdminController
{
public array $notNeedLogin = ['download_file'];
/**请求地址*/
private $serviceUrl;
/**appkey*/
private $appkey;
/**secret*/
private $appSecret;
public function initialize()
{
$this->serviceUrl=env('junzi.url_prefix');
$this->appkey=env('junzi.app_key');
$this->appSecret=env('junzi.app_secret');
parent::initialize();
}
/**请求地址*/
// private $serviceUrl = 'https://api.junziqian.com';
// /**appkey*/
// private $appkey = '62dc4ab579153712';
// /**secret*/
// private $appSecret = 'b7f65acc62dc4ab579153712fc9ebfc5';
/**默认加密方式:不输入使用sha256,其它可选择项md5,sha1,sha3-256*/
private $encryMethod;
/**默认ts单位:1毫秒,2秒*/
private $tsType;
/**
* 填充签名数据
* @param $req array
*/
public function fillSign($req)
{
/**默认加密方式:不输入使用sha256,其它可选择项md5,sha1,sha3-256*/
$ts = time();
if ($this->tsType == 1) {
$ts = $ts * 1000;
}
$sign = null;
$nonce = md5($ts . "");
$signSrc = "nonce" . $nonce . "ts" . $ts . "app_key" . $this->appkey . "app_secret" . $this->appSecret;
if ($this->encryMethod == null || $this->encryMethod == "sha256") {
$sign = ShaUtils::getSha256($signSrc);
} else if ($this->encryMethod == "sha1") {
$sign = ShaUtils::getSha1($signSrc);
} else if ($this->encryMethod == "md5") {
$sign = md5($signSrc);
} else {
throw new ResultInfoException($this->encryMethod . ",必须为md5,sha1,sha256之一", "PARAM_ERROR");
}
$req['ts'] = $ts;
$req['app_key'] = $this->appkey;
$req['sign'] = $sign;
$req['nonce'] = $nonce; //这只是为了生成一个随机值
if ($this->encryMethod != null) {
$req['encry_method'] = $this->encryMethod; //为''也不能传
}
return $req;
}
//企业实名认证上传
public function EnterpriseCertification($data)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = new OrganizationCreateReq();
$request->name = $data['name'];
$request->identificationType = 1; //证件类型0多证,1多证合一
$request->organizationType = 0; //组织类型 0企业,1事业单位
$request->organizationRegNo = $data['organization_code'];
$request->organizationRegImg = $data['business_license']; //new CURLFile('D:/tmp/test.png',null,"test.png");
$request->legalName = $data["master_name"]; //法人
// $request->legalIdentityCard = $data["master_id_card"]; // 法人身份证 签约时人脸识别需要
// $request->legalMobile = $data["master_phone"]; // 法人手机号 预留 签约时短信验证需要
if (isset($data['master_email'])) {
$request->emailOrMobile = $data['master_email']; //邮箱
}
// $request->notifyUrl = env('url.url_prefix').'/notifyAuthentication?ids=22222';
$request->notifyUrl = env('url.url_prefix') . '/notifyAuthentication?id=' . $data['id'];
// halt($request);
//发起创建企业请求
$response = $requestUtils->doPost("/v2/user/organizationCreate", $request);
return $response;
}
/**
* @param $data
* @return object
* 商城商户入驻,实名认证
*/
public function ShopMerchantCertification($data)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = new OrganizationCreateReq();
$request->name = $data['name'];
$request->identificationType = 1; //证件类型0多证,1多证合一
$request->organizationType = 0; //组织类型 0企业,1事业单位
$request->organizationRegNo = $data['organization_code'];
$request->organizationRegImg = $data['business_license'];
$request->legalName = $data["master_name"]; //法人
if (isset($data['master_email'])) {
$request->emailOrMobile = $data['master_email']; //邮箱
}
$request->notifyUrl = env('url.url_prefix') . '/notifyAuthentication?id=' . $data['id'].'&type=shop_merchant'; // 回调增加type参数用于回调是辨别是商户认证会带
//发起创建企业请求
$response = $requestUtils->doPost("/v2/user/organizationCreate", $request);
return $response;
}
//重新提交企业实名认证
public function organizationReapply($data)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = new OrganizationCreateReq();
$request->name = $data['name'];
$request->identificationType = 1; //证件类型0多证,1多证合一
$request->organizationType = 0; //组织类型 0企业,1事业单位
$request->organizationRegNo = $data['organization_code'];
$request->organizationRegImg = $data['business_license']; //new CURLFile('D:/tmp/test.png',null,"test.png");
$request->legalName = $data["master_name"]; //法人
// $request->legalIdentityCard = $data["master_id_card"]; // 法人身份证 签约时人脸识别需要
// $request->legalMobile = $data["master_phone"]; // 法人手机号 预留 短信验证需要
$request->emailOrMobile = $data['master_email']; //邮箱
//发起创建企业请求
$response = $requestUtils->doPost("/v2/user/organizationReapply", $request);
return $response;
// return $this->success('', (array)$response);
}
//企业实名认证状态查询
public function StatusQuery()
{
$param = Request()->param();
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
//初始化合同参数
$request = array(
"emailOrMobile" => $param['master_email'], //TODO *
);
//发起请求
$response = $requestUtils->doPost("/v2/user/organizationAuditStatus", $request);
return $response;
}
public function shopMerchantStatusQuery($email)
{
$param = Request()->param();
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
//初始化合同参数
$request = array(
"emailOrMobile" => $email, //TODO *
);
//发起请求
$response = $requestUtils->doPost("/v2/user/organizationAuditStatus", $request);
return $response;
}
//企业自定义公章
public function Custom_seal()
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
//初始化合同参数
$request = array(
"signName" => "500XXXXXXXXXXXX", //TODO *
"email" => "500XXXXXXXXXXXX", //TODO 不传则保存在商户下,传入注册的邮箱则上传到指定邮箱企业名下
"signImgFile" => new CURLFile('D:/tmp/test.png', null, "test.png"),
);
$response = $requestUtils->doPost("/v2/user/uploadEntSign", $request);
return $this->success('', (array)$response);
}
//签约
public function Signing($data, $id, $notify = '')
{
if ($notify == '') {
$notify = env('url.url_prefix') . '/notify_url';
}
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = new ApplySignReq();
$request->contractName = $data['name'];
$request->signatories = $data['signatories']; //签约方
// $request->faceThreshold = 79; // 人脸识别阀值:默认等级(1-100之间整数),建议范围(60-79)
$request->serverCa = 1; //是否需要服务端云证书
$request->fileType = 1; //合同上传方式 url
$request->url = $data['url'];
$request->notifyUrl = $notify . '?id=' . $id;
$request->needQifengSign = 1;
//发起PING请求
// halt($request);
$response = $requestUtils->doPost("/v2/sign/applySign", $request);
return $response;
}
public function shopContractSigning($data, $id, $notify = '')
{
if ($notify == '') {
$notify = env('url.url_prefix') . '/shop_contract_notify_url';
}
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = new ApplySignReq();
$request->contractName = $data['name'];
$request->signatories = $data['signatories']; //签约方
// $request->faceThreshold = 79; // 人脸识别阀值:默认等级(1-100之间整数),建议范围(60-79)
$request->serverCa = 1; //是否需要服务端云证书
$request->fileType = 1; //合同上传方式 url
$request->url = $data['url'];
$request->notifyUrl = $notify . '?id=' . $id;
$request->needQifengSign = 1;
//发起PING请求
// halt($request);
$response = $requestUtils->doPost("/v2/sign/applySign", $request);
return $response;
}
// 企业人脸校验上传
public function OrganizationFaceCreate($data)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = new OrganizationFaceCreateReq();
$request->orderNo = $data['id'];
$request->email = $data['master_email'];
$request->enterpriseName = $data['company_name'];
$request->identityNo = $data['organization_code'];
// $request-> facePerType = 0;
$request->legalPersonName = $data['master_name'];
$request->legalIdentityCard = $data['master_id_card']; //法人证件号
$request->legalMobile = $data['master_phone'];
$request->faceAgantIdenName = $data['master_name'];
$request->faceAgantIdenCard = $data['master_id_card'];
$request->backUrl = env('url.url_prefix') . '/api/Hetong/notifyOrganizationFaceCreate';
$response = $requestUtils->doPost("/v2/user/organizationFaceCreate", $request);
return $response;
}
public function VehicleRentSigning($data, $id, $notify)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = new ApplySignReq();
$request->contractName = $data['name'];
$request->signatories = $data['signatories']; //签约方
$request->serverCa = 1; //是否需要服务端云证书
$request->fileType = 1; //合同上传方式 url
$request->url = $data['url'];
$request->notifyUrl = $notify . '?id=' . $id;
$request->needQifengSign = 1;
//发起PING请求
// halt($request);
$response = $requestUtils->doPost("/v2/sign/applySign", $request);
return $response;
}
public function downloadVehicleContractFile($applyNo)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$contract_url = VehicleContract::where('contract_no', $applyNo)->value('contract_url');
if ($contract_url && !empty($contract_url)) {
return $contract_url;
}
//初始化请求参数
$request = array(
"applyNo" => $applyNo, //TODO +
);
$response = $requestUtils->doPost("/v2/sign/linkFile", $request);
if ($response->success) {
$this->getDownload($response->data, root_path() . 'public/uploads/vehicle_contract/' . $applyNo . '.pdf');
return env('project.website_domain') . '/uploads/vehicle_contract/' . $applyNo . '.pdf';
} else {
return false;
}
}
public function downloadVehicleContractEvidence($applyNo, $companyName, $companyCode)
{
//构建请求工具
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
//初始化合同参数
$request = array(
"applyNo" => $applyNo,
"fullName" => $companyName, //签约人名称(合同发起接口中传入的签署人姓名)
"identityCard" => $companyCode, //统一社会信用代码
"identityType" => 12, //证件类型 1身份证, 2护照, 3台胞证, 4港澳居民来往内地通行证, 11营业执照, 12统一社会信用代码, 20子账号, 99其他
"dealType" => 1
);
$response = $requestUtils->doPost("/v2/sign/presLinkFile", $request);
if ($response->success) {
$this->getDownload($response->data, root_path().'public/uploads/vehicle_contract_evidence/'.$applyNo.'_'.$companyCode.'.zip');
return env('project.website_domain').'/uploads/vehicle_contract_evidence/'.$applyNo.'_'.$companyCode.'.zip';;
} else {
return false;
}
}
public function SigningLink($data)
{
//构建请求工具
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
//初始化合同参数
$response = $requestUtils->doPost("/v2/sign/link", $data);
return $response;
}
public function sms($data)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
//初始化请求参数
$request = array(
"applyNo" => $data['applyNo'], //TODO +
//"businessNo" => "0000XXXXXXXXX", //TODO +
"fullName" => $data['fullName'], //TODO *
"identityCard" => $data['identityCard'], //TODO *
"identityType" => 12, //TODO *
"signNotifyType" => 1 //默认为1
);
$response = $requestUtils->doPost("/v2/sign/notify", $request);
return $response;
}
//html模板
public function html_contract($data, $id)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
//CURLFile 可以传url或filePath但必须保证文件存在且有效否则php不会报错只会导致http请求返回null并没有调到服务端
//初始化合同参数
$request = new ApplySignReq();
$request->contractName = $data['name'];
$request->signatories = $data['signatories']; //签约方
$request->serverCa = 1; //是否需要服务端云证书
$request->fileType = 3;
$request->htmlContent = $data['content'];
$request->notifyUrl = env('url.url_prefix') . '/notify_url?id=' . $id;
$request->needQifengSign = 1;
//发起PING请求
$response = $requestUtils->doPost("/v2/sign/applySign", $request);
return $response;
}
/**
* 下载合同
*/
public function download_file($applyNo)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$find = Db::connect('mysql2')->name('la_contract')->where('contract_no', $applyNo)->value('contract_url');
if ($find) {
return $this->success('获取成功', ['url' => env('url.url_prefix') . $find]);
}
//初始化请求参数
$request = array(
"applyNo" => $applyNo, //TODO +
);
$response = $requestUtils->doPost("/v2/sign/linkFile", $request);
if ($response->success == true) {
$this->getDownload($response->data, root_path() . 'public/uploads/contract/' . $applyNo . '.pdf');
Db::connect('mysql2')->name('la_contract')->where('contract_no', $applyNo)->update(['contract_url' => '/uploads/contract/' . $applyNo . '.pdf']);
return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/contract/' . $applyNo . '.pdf']);
} else {
return $this->fail('获取失败');
}
}
public function download_shop_file($applyNo)
{
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$find = Db::connect('mysql2')->name('la_contract')->where('contract_no', $applyNo)->value('contract_url');
if ($find) {
return $this->success('获取成功', ['url' => env('url.url_prefix') . $find]);
}
//初始化请求参数
$request = array(
"applyNo" => $applyNo, //TODO +
);
$response = $requestUtils->doPost("/v2/sign/linkFile", $request);
if ($response->success == true) {
$this->getDownload($response->data, root_path() . 'public/uploads/contract/' . $applyNo . '.pdf');
Db::connect('mysql2')->name('la_shop_contract')->where('contract_no', $applyNo)->update(['contract_url' => '/uploads/contract/' . $applyNo . '.pdf']);
return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/contract/' . $applyNo . '.pdf']);
} else {
return $this->fail('获取失败');
}
}
/**
* 保全后合同文件及证据包下载
*/
public function EvidenceDownload($param)
{
//初始化请求参数
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = array(
"applyNo" => $param['applyNo'],
"fullName" => $param['fullName'],
"identityCard" => $param['identityCard'],
"identityType" => 12,
"dealType" => 1,
);
$response = $requestUtils->doPost("/v2/sign/presLinkFile", $request);
if ($response->success == true) {
$this->getDownload($response->data, root_path() . 'public/uploads/evidence/' . $param['applyNo'] . '.zip');
Db::connect('mysql2')->name('la_contract')->where('contract_no', $param['applyNo'])->update(['evidence_url' => '/uploads/evidence/' . $param['applyNo'] . '.zip']);
return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/evidence/' . $param['applyNo'] . '.zip']);
} else {
return $this->fail('获取失败');
}
}
/**
* 保全后合同文件及证据包下载
*/
public function EvidenceShopDownload($param)
{
//初始化请求参数
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
$request = array(
"applyNo" => $param['applyNo'],
"fullName" => $param['fullName'],
"identityCard" => $param['identityCard'],
"identityType" => 12,
"dealType" => 1,
);
$response = $requestUtils->doPost("/v2/sign/presLinkFile", $request);
if ($response->success == true) {
$this->getDownload($response->data, root_path() . 'public/uploads/evidence_shop_contract/' . $param['applyNo'] . '.zip');
Db::connect('mysql2')->name('la_shop_contract')->where('contract_no', $param['applyNo'])->update(['evidence_url' => '/uploads/evidence_shop_contract/' . $param['applyNo'] . '.zip']);
return $this->success('获取成功', ['url' => env('url.url_prefix') . '/uploads/evidence_shop_contract/' . $param['applyNo'] . '.zip']);
} else {
return $this->fail('获取失败');
}
}
public function getDownload($url, $publicDir = '', $fileName = '', $type = 0)
{
//获取文件路径
$newOneDir = substr($publicDir, 0, strrpos($publicDir, "/"));
if (trim($url) == '') {
return false;
}
//检验访问url是否有效
$array = get_headers($url, 1);
if (!preg_match('/200/', $array[0])) {
return false;
}
if (trim($publicDir) == '') {
return false;
}
//创建保存目录
if (!file_exists($newOneDir) && !mkdir($newOneDir, 0777, true)) {
return false;
}
//获取远程文件所采用的方法
if ($type) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$content = curl_exec($ch);
curl_close($ch);
} else {
ob_start();
readfile($url);
$content = ob_get_contents();
ob_end_clean();
}
$size = strlen($content);
//文件大小
$fp2 = @fopen($publicDir, 'a');
fwrite($fp2, $content);
fclose($fp2);
unset($content, $url);
}
}