<?php
class ApplyForm
{
public $version = '1.0'; //接口版本号
public $orderNo; //订单编号
public $orgId; //机构号
public $ecTypeCode; //合同类别
public $certType = 'RESIDENT_ID'; //证件类型
public $certName; //证件名称
public $certNo; //证件号
public $mobile; //手机号
public $businessLicenseNo; //营业执照号
public $businessLicenseName ; //营业执照名称
public $openningBankCode; //开户行号
public $openningBankName; //开户行名称
public $clearingBankCode; //结算账户清算行号
public $acctTypeCode; //结算账户性质( 57 对公 58 对私)
public $acctNo; //结算账户账号
public $acctName; //结算账户名称
public $retUrl; //回调地址
public $ecContentParameters; //电子合同内容参数集合
public $remark;
/**
* @return string
*/
public function getVersion()
{
return $this->version;
}
/**
* @param string $version
* @return ApplyForm
*/
public function setVersion($version)
{
$this->version = $version;
return $this;
}
/**
* @return mixed
*/
public function getOrderNo()
{
return $this->orderNo;
}
/**
* @param mixed $orderNo
* @return ApplyForm
*/
public function setOrderNo($orderNo)
{
$this->orderNo = $orderNo;
return $this;
}
/**
* @return mixed
*/
public function getOrgId()
{
return $this->orgId;
}
/**
* @param mixed $orgId
* @return ApplyForm
*/
public function setOrgId($orgId)
{
$this->orgId = $orgId;
return $this;
}
/**
* @return mixed
*/
public function getEcTypeCode()
{
return $this->ecTypeCode;
}
/**
* @param mixed $ecTypeCode
* @return ApplyForm
*/
public function setEcTypeCode($ecTypeCode)
{
$this->ecTypeCode = $ecTypeCode;
return $this;
}
/**
* @return string
*/
public function getCertType()
{
return $this->certType;
}
/**
* @param string $certType
* @return ApplyForm
*/
public function setCertType($certType)
{
$this->certType = $certType;
return $this;
}
/**
* @return mixed
*/
public function getCertName()
{
return $this->certName;
}
/**
* @param mixed $certName
* @return ApplyForm
*/
public function setCertName($certName)
{
$this->certName = $certName;
return $this;
}
/**
* @return mixed
*/
public function getCertNo()
{
return $this->certNo;
}
/**
* @param mixed $certNo
* @return ApplyForm
*/
public function setCertNo($certNo)
{
$this->certNo = $certNo;
return $this;
}
/**
* @return mixed
*/
public function getMobile()
{
return $this->mobile;
}
/**
* @param mixed $mobile
* @return ApplyForm
*/
public function setMobile($mobile)
{
$this->mobile = $mobile;
return $this;
}
/**
* @return mixed
*/
public function getBusinessLicenseNo()
{
return $this->businessLicenseNo;
}
/**
* @param mixed $businessLicenseNo
* @return ApplyForm
*/
public function setBusinessLicenseNo($businessLicenseNo)
{
$this->businessLicenseNo = $businessLicenseNo;
return $this;
}
/**
* @return mixed
*/
public function getBusinessLicenseName()
{
return $this->businessLicenseName;
}
/**
* @param mixed $businessLicenseName
* @return ApplyForm
*/
public function setBusinessLicenseName($businessLicenseName)
{
$this->businessLicenseName = $businessLicenseName;
return $this;
}
/**
* @return mixed
*/
public function getOpenningBankCode()
{
return $this->openningBankCode;
}
/**
* @param mixed $openningBankCode
* @return ApplyForm
*/
public function setOpenningBankCode($openningBankCode)
{
$this->openningBankCode = $openningBankCode;
return $this;
}
/**
* @return mixed
*/
public function getOpenningBankName()
{
return $this->openningBankName;
}
/**
* @param mixed $openningBankName
* @return ApplyForm
*/
public function setOpenningBankName($openningBankName)
{
$this->openningBankName = $openningBankName;
return $this;
}
/**
* @return mixed
*/
public function getClearingBankCode()
{
return $this->clearingBankCode;
}
/**
* @param mixed $clearingBankCode
* @return ApplyForm
*/
public function setClearingBankCode($clearingBankCode)
{
$this->clearingBankCode = $clearingBankCode;
return $this;
}
/**
* @return mixed
*/
public function getAcctTypeCode()
{
return $this->acctTypeCode;
}
/**
* @param mixed $acctTypeCode
* @return ApplyForm
*/
public function setAcctTypeCode($acctTypeCode)
{
$this->acctTypeCode = $acctTypeCode;
return $this;
}
/**
* @return mixed
*/
public function getAcctNo()
{
return $this->acctNo;
}
/**
* @param mixed $acctNo
* @return ApplyForm
*/
public function setAcctNo($acctNo)
{
$this->acctNo = $acctNo;
return $this;
}
/**
* @return mixed
*/
public function getAcctName()
{
return $this->acctName;
}
/**
* @param mixed $acctName
* @return ApplyForm
*/
public function setAcctName($acctName)
{
$this->acctName = $acctName;
return $this;
}
/**
* @return mixed
*/
public function getRetUrl()
{
return $this->retUrl;
}
/**
* @param mixed $retUrl
* @return ApplyForm
*/
public function setRetUrl($retUrl)
{
$this->retUrl = $retUrl;
return $this;
}
/**
* @return mixed
*/
public function getEcContentParameters()
{
return $this->ecContentParameters;
}
/**
* @param mixed $ecContentParameters
* @return ApplyForm
*/
public function setEcContentParameters($ecContentParameters)
{
$this->ecContentParameters = $ecContentParameters;
return $this;
}
/**
* @return mixed
*/
public function getRemark()
{
return $this->remark;
}
/**
* @param mixed $remark
* @return ApplyForm
*/
public function setRemark($remark)
{
$this->remark = $remark;
return $this;
}
public function toArray() {
$array = (array) $this;
foreach ($array as $key => $value) {
if ($value === null || $value === '') {
unset($array[$key]);
}
}
return $array;
}
}
?>
<?php
use commonlibrarieslakalamerchantUtilsService;
use commonlibrarieslakalaRequestService;
use commonlibrariesWriteLogSrv;
use commonmodelsdbMerchantElectronicContract;
/**
* 电子合同
* document文档 http://106.14.112.9:5000/wiki/docs/openplatform/openplatform-1d998u56244t9
* Class ElectronicContractService
*/
class ElectronicContractService
{
protected $returnUrl = 'http://xx/api/lakala/electronic-notify';
/**
* 构造商户入网请求参数
* @param MerchantElectronicContract $electronicContract
* @return ApplyForm
*/
public function merchantNetApplyToArray(MerchantElectronicContract $electronicContract) {
$applyForm = new ApplyForm();
$applyForm->setOrderNo($electronicContract->order_no);
$applyForm->setEcTypeCode($electronicContract->type_code);
$applyForm->setCertName($electronicContract->cert_name);
$applyForm->setCertNo($electronicContract->cert_no);
$applyForm->setMobile($electronicContract->mobile);
$applyForm->setBusinessLicenseNo($electronicContract->business_license_no);
$applyForm->setBusinessLicenseName($electronicContract->business_license_name);
$applyForm->setAcctName($electronicContract->acct_name);
$applyForm->setAcctNo($electronicContract->acct_no);
$applyForm->setAcctTypeCode($electronicContract->acct_type_code);
$applyForm->setOpenningBankCode($electronicContract->openning_bank_code);
$applyForm->setOpenningBankName($electronicContract->openning_bank_name);
$applyForm->setRemark($electronicContract->remark);
return $applyForm;
}
/**
* 电子合同申请
* @param MerchantElectronicContract $electronicContract
*/
public function apply(MerchantElectronicContract $electronicContract) {
$requestService = new RequestService();
$applyForm = $this->merchantNetApplyToArray($electronicContract);
$applyForm->setOrgId($requestService->orgCode);
$applyForm = $applyForm->toArray();
$applyForm['retUrl'] = $this->returnUrl;
if($result = $requestService->send('api/v2/mms/openApi/ec/apply', $this->commonData($applyForm))) {
$electronicContract->apply_id = $result['data']['ecApplyId'];
$electronicContract->status = 1;
$electronicContract->update_time = date('Y-m-d H:i:s');
if (!$electronicContract->save()) {
throw new RuntimeException('保存失败'.implode('', $electronicContract->getFirstErrors()));
}
} else {
throw new RuntimeException($requestService->getErrorMessage(), '-1');
}
}
/**
* 电子合同查询
* @param MerchantElectronicContract $electronicContract
*/
public function query(MerchantElectronicContract $electronicContract) {
$requestService = new RequestService();
$data = [];
$data['version'] = '1.0.0';
$data['orderNo'] = UtilsService::uniqueStr();
$data['orgId'] = $requestService->orgCode;
$data['ecApplyId'] = $electronicContract->apply_id;
if($result = $requestService->send('api/v2/mms/openApi/ec/qStatus', $this->commonData($data))) {
if($result['respData']['ecStatus'] == 'COMPLETED') {
$electronicContract->status = 2;
$electronicContract->update_time = date('Y-m-d H:i:s');
if (!$electronicContract->save()) {
throw new RuntimeException('保存失败'.implode('', $electronicContract->getFirstErrors()));
}
}
} else {
throw new RuntimeException($requestService->getErrorMessage(), '-1');
}
}
/**
* 处理电子合同回调
* @param $orderNo
* @param $applyId
*/
public function handleApply($orderNo, $applyId) {
if (empty($orderNo) || empty($applyId)) {
return;
}
$merchantElectronicContract = MerchantElectronicContract::find()->where(['order_no' => $orderNo])->one();
if (!$merchantElectronicContract) {
WriteLogSrv::writeLog("=====电子合同通知====== 没有相关记录");
return;
}
$merchantElectronicContract->status = 2;
$merchantElectronicContract->apply_id = $applyId;
$merchantElectronicContract->update_time = date('Y-m-d H:i:s');
if (!$merchantElectronicContract->save()) {
WriteLogSrv::writeLog("=====电子合同通知======".implode("", $merchantElectronicContract->getFirstErrors()));
return;
}
}
/**
* 电子合同下载
* @param MerchantElectronicContract $electronicContract
* @return string
*/
public function download(MerchantElectronicContract $electronicContract) {
$requestService = new RequestService();
$data = [];
$data['version'] = '1.0.0';
$data['orderNo'] = UtilsService::uniqueStr();
$data['orgId'] = $requestService->orgCode;
$data['ecApplyId'] = $electronicContract->apply_id;
if($result = $requestService->send('api/v2/mms/openApi/ec/download', $this->commonData($data))) {
if($result['respData']['ecStatus'] == 'COMPLETED') {
return base64_decode($result['respData']['ecContractFile']);
}
} else {
throw new RuntimeException($requestService->getErrorMessage(), '-1');
}
}
/**
* 商户公共请求参数
* @param $data
* @return array
*/
private function commonData($data) {
return [
"ver" => "1.0.0",
"timestamp" => time(),
"rnd" => UtilsService::uniqueStr(),
"reqId" => "baff59de4694438ca9089862253517a5",
"reqData" => $data
];
}
}
?>下一篇:没有营业执照怎么开通线上支付