190 lines
7.9 KiB
PHP
190 lines
7.9 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\Request;
|
||
use com\junziqian\sdk\bean\req\sign\ApplySignReq;
|
||
use com\junziqian\sdk\bean\req\user\OrganizationCreateReq;
|
||
use com\junziqian\sdk\util\exception\ResultInfoException;
|
||
use com\junziqian\sdk\util\RequestUtils;
|
||
use com\junziqian\sdk\util\ShaUtils;
|
||
use CURLFile;
|
||
|
||
class JunziqianController extends BaseApiController
|
||
{
|
||
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate'];
|
||
|
||
/**请求地址*/
|
||
private $serviceUrl = 'https://api.sandbox.junziqian.com';
|
||
/**appkey*/
|
||
private $appkey = '3121e0d911b7943d';
|
||
/**secret*/
|
||
private $appSecret = '1e66d8b73121e0d911b7943d82bba174';
|
||
|
||
|
||
/**默认加密方式:不输入使用sha256,其它可选择项md5,sha1,sha3-256*/
|
||
private $encryMethod;
|
||
/**默认ts单位:1毫秒,2秒*/
|
||
private $tsType;
|
||
|
||
public function index()
|
||
{
|
||
$data = [
|
||
'name' => '我的合同',
|
||
'signatories' => [['fullName' => '小米', 'identityType' => 1, 'identityCard' => '5002401XXXXXXXXX', 'mobile' => 18982406440, 'noNeedVerify' => 1, 'signLevel' => 1]],
|
||
'url' => "https://dev.lihaink.cn/storage/202307/acbba88e77392348d3a8a4a1fdf210f1.pdf"
|
||
];
|
||
halt($this->Signing($data));
|
||
}
|
||
/**
|
||
* 填充签名数据
|
||
* @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);
|
||
//CURLFile 可以传url或filePath,但必须保证文件存在且有效,否则php不会报错,只会导致http请求返回null(并没有调到服务端)。
|
||
//初始化合同参数
|
||
$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"]; //法人
|
||
if (isset($data['master_email'])) {
|
||
$request->emailOrMobile = $data['master_email']; //邮箱
|
||
}
|
||
// $request->emailOrMobile = ; //邮箱
|
||
//发起创建企业请求
|
||
$response = $requestUtils->doPost("/v2/user/organizationCreate", $request);
|
||
return $response;
|
||
// return $this->success('', (array)$response);
|
||
}
|
||
|
||
//重新提交企业实名认证
|
||
public function organizationReapply($data)
|
||
{
|
||
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
|
||
//CURLFile 可以传url或filePath,但必须保证文件存在且有效,否则php不会报错,只会导致http请求返回null(并没有调到服务端)。
|
||
//初始化合同参数
|
||
$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->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['email'], //TODO *
|
||
);
|
||
//发起请求
|
||
$response = $requestUtils->doPost("/v2/user/organizationAuditStatus", $request);
|
||
return $this->success('', (array)$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)
|
||
{
|
||
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
|
||
//CURLFile 可以传url或filePath,但必须保证文件存在且有效,否则php不会报错,只会导致http请求返回null(并没有调到服务端)。
|
||
//初始化合同参数
|
||
//[ ['fullName' => '小米', 'identityType' => 1, 'identityCard' => '5002401XXXXXXXXX', 'mobile' => 18982406440,'noNeedVerify'=>1,'signLevel'=>1] ]
|
||
$request = new ApplySignReq();
|
||
$request->contractName = $data['name'];
|
||
$request->signatories = $data['signatories']; //签约方
|
||
$request->serverCa = 1; //是否需要服务端云证书
|
||
$request->fileType = 1; //合同上传方式 url
|
||
$request->url = $data['url'];
|
||
//发起PING请求
|
||
// halt($request);
|
||
$response = $requestUtils->doPost("/v2/sign/applySign", $request);
|
||
return $response;
|
||
// return $this->success('', (array)$response);
|
||
}
|
||
|
||
public function SigningLink($data)
|
||
{
|
||
//构建请求工具
|
||
$requestUtils = new RequestUtils($this->serviceUrl, $this->appkey, $this->appSecret);
|
||
//初始化合同参数
|
||
$response = $requestUtils->doPost("/v2/sign/link", $data);
|
||
return $response;
|
||
|
||
// return $this->success('', (array)$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;
|
||
}
|
||
}
|