银联条码支付小微商户进件PHP版DEMO

本示例依赖于银联条码支付【统一】扫码支付PHP版DEMO,此DEMO可在银联官网下载(https://up.95516.com/open/openapi/doc?index_1=1&index_2=1&chapter_1=238&chapter_2=268),新增内容已在代码中标注说明。

<?php
/**
 * 支付接口调测例子
 * ================================================================
 * index 进入口,方法中转
 * submitOrderInfo 提交订单信息
 * queryOrder 查询订单
 * 
 * ================================================================
 */
require('Utils.class.php');
require('config/config.php');
require('class/RequestHandler.class.php');
require('class/ClientResponseHandler.class.php');
require('class/PayHttpClient.class.php');

Class Request{
  

    private $resHandler = null;
    private $reqHandler = null;
    private $pay = null;
    private $cfg = null;
    
    public function __construct(){
        $this->Request();
    }

    public function Request(){
        $this->resHandler = new ClientResponseHandler();
        $this->reqHandler = new RequestHandler();
        $this->pay = new PayHttpClient();
        $this->cfg = new Config();

        $this->reqHandler->setGateUrl($this->cfg->C('url'));

        $sign_type = $this->cfg->C('sign_type');
        
        if ($sign_type == 'MD5') {
            $this->reqHandler->setKey($this->cfg->C('key'));
            $this->resHandler->setKey($this->cfg->C('key'));
            $this->reqHandler->setSignType($sign_type);
        } else if ($sign_type == 'RSA_1_1' || $sign_type == 'RSA_1_256') {
            $this->reqHandler->setRSAKey($this->cfg->C('private_rsa_key'));
            $this->resHandler->setRSAKey($this->cfg->C('public_rsa_key'));
            $this->reqHandler->setSignType($sign_type);
        }
    }
	
	/* ------------------------------------------------- 新增内容 start ------------------------------------------------- */
	
    /**
     * 图片上传 2020-3-14 By Ken (http://ken.01h.net/) QQ:2480990710
     */
	public function picUpload($path){
		$post_data['partner'] = $this->cfg->C('sign_agentno');//合作伙伴ID即机构号
		$post_data['serviceName'] = 'pic_upload';//服务名称
		$post_data['signType'] = $this->cfg->C('sign_type');//签名类型
		$post_data['data'] = '';//请求数据
		//签名
		$signPars = "";
		ksort($post_data);
		foreach($post_data as $k => $v) {
			if("" != $v &amp;&amp; "dataSign" != $k &amp;&amp; "signType" != $k) {
				$signPars .= $k . "=" . $v . "&amp;";
			}
		}
		$signPars = substr($signPars, 0, -1) . $this->reqHandler->getKey();
		$post_data['dataSign'] = strtolower(md5($signPars));
		//图片
		if(substr(PHP_VERSION, 0, 3)<5.5){  //PHP5.5以下版本
			$post_data['picFile'] = '@'.$path;
		}else{  //PHP5.5及以上版本
			$post_data['picFile'] = new CURLFile($path);
		}
		$this->pay->setReqContent($this->cfg->C('up_url'), $post_data);
		if($this->pay->call()){
			$res = json_decode(json_encode(simplexml_load_string($this->pay->getResContent(), 'SimpleXMLElement', LIBXML_NOCDATA)), true);  //将XML转为array
			if($res['isSuccess'] == 'T'){  //成功
				return $res['pic'];
			}else{
				return array('status'=>500,'msg'=>'Error Code:'.$res['errorCode'].' Error Message:'.$res['errorMsg']);
			}
		}else{
			return array('status'=>500,'msg'=>'Response Code:'.$this->pay->getResponseCode().' Error Info:'.$this->pay->getErrInfo());
		}
	}
	
    /**
     * 小微商户进件 2020-3-14 By Ken (http://ken.01h.net/) QQ:2480990710
     */
	public function smallMchAdd($merchant){  //merchantName 、 outMerchantId  、 chPayAuth 、 limitCreditPay  、 merchantDetail['merchantShortName'] \ ['industrId'] \ ['province'] \ ['city'] \ ['county'] \ ['address'] \ ['email'] \ ['customerPhone'] \ ['principal'] \ ['principalMobile'] \ ['idCode'] \ ['indentityPhoto'] 、 bankAccount['accountCode'] \ ['bankId'] \ ['accountName'] \ ['accountType'] \ ['contactLine'] \ ['bankName'] \ ['province'] \ ['city'] \ ['idCardType'] \ ['idCard'] \ ['tel'] 、 mchPayConfs[0]['nodename'] \ ['payTypeId'] \ ['billRate'] 、 mchPayConfs[1]['nodename'] \ ['payTypeId'] \ ['billRate'] 、 mchPayConfs[2]['nodename'] \ ['payTypeId'] \ ['billRate'] \ ['billRate1'] ……
		$post_data['partner'] = $this->cfg->C('sign_agentno');//合作伙伴ID即机构号
		$post_data['serviceName'] = 'small_mch_add';//服务名称
		$post_data['signType'] = $this->cfg->C('sign_type');//签名类型
		//数组转XML
		$merchant_xml = simplexml_load_string('<merchant />');
		$this->create_xml($merchant, $merchant_xml);
		$data = $merchant_xml->saveXML();
		$post_data['data'] = str_replace('<?xml version="1.0"?>', '', $data);//请求数据
		//签名
		$signPars = "";
		ksort($post_data);
		foreach($post_data as $k => $v) {
			if("" != $v &amp;&amp; "dataSign" != $k &amp;&amp; "signType" != $k) {
				$signPars .= $k . "=" . $v . "&amp;";
			}
		}
		$signPars = substr($signPars, 0, -1) . $this->reqHandler->getKey();
		$post_data['dataSign'] = strtolower(md5($signPars));
		//组装请求串
        $o = "";
        foreach ($post_data as $k => $v) {
            $o.= "$k=" . urlencode($v) . "&amp;";
        }
        $post_data = substr($o, 0, -1);
		$this->pay->setReqContent($this->cfg->C('up_url'), $post_data);
		if($this->pay->call()){
			$res = json_decode(json_encode(simplexml_load_string($this->pay->getResContent(), 'SimpleXMLElement', LIBXML_NOCDATA)), true);  //将XML转为array
			if($res['isSuccess'] == 'T'){  //成功
				return $res['merchant'];
			}else{
				return array('status'=>500,'msg'=>'Error Code:'.$res['errorCode'].' Error Message:'.$res['errorMsg']);
			}
		}else{
			return array('status'=>500,'msg'=>'Response Code:'.$this->pay->getResponseCode().' Error Info:'.$this->pay->getErrInfo());
		}
	}
	private function create_xml($arr, $xml) {
		foreach($arr as $k=>$v) {
			if(is_array($v)) {  //数组
				if(array_keys($v) !== range(0, count($v)-1)) {  //关联数组
					$x = $xml->addChild($k);
					$this->create_xml($v, $x);
				} else {  //索引数组
					$x = $xml->addChild($k);
					foreach ($v as $vv) {
						$y = $x->addChild($vv['nodename']);
						unset($vv['nodename']);
						$this->create_xml($vv, $y);
					}
				}
			} else {
				$xml->addChild($k, $v);
			}
		}
	}
	
	/* ------------------------------------------------- 新增内容 end ------------------------------------------------- */
	
    /**
     * 提交订单
     */
    public function submitOrderInfo($info){
		
	}

?>

调用示例如下:

<?php
//调取接口
include './request.php';
$req = new Request();
//上传身份证图片
$indentityPhoto = array();
$card_front = $req->picUpload(dirname(__FILE__).'/upload/card_front.png');
$indentityPhoto[] = $card_front;
$card_back = $req->picUpload(dirname(__FILE__).'/upload/card_back.png');
$indentityPhoto[] = $card_back;
//上传收款银行卡照片
$accountCodePhoto = $req->picUpload(dirname(__FILE__).'/upload/bankPhoto.png');
//上传门头照
$mainPhoto = $req->picUpload(dirname(__FILE__).'/upload/shopPhoto.png');
//商户信息
$info = array();
//商户基本信息
$info['merchantName'] = '商户_张三';  //商户名称
$info['outMerchantId'] = 'UP_' . date('YmdHis') . rand(10, 99);  //外商户号
$info['chPayAuth'] = '1';  //授权机构交易
$info['limitCreditPay'] = '2';  //是否可用信用卡支付, 0:是   1:否   2:不限制
//商户详情信息
$info['merchantDetail']['merchantShortName'] = $info['merchantName'];  //商户简称
$info['merchantDetail']['industrId'] = '5331';  //行业类别: 5331 杂货便利店
$info['merchantDetail']['province'] = '3900';  //省份: 3900 福建
$info['merchantDetail']['city'] = '3930';  //城市: 3930 厦门
$info['merchantDetail']['county'] = '3933';  //区县: 3933 湖里
$info['merchantDetail']['address'] = '高新软件园华骏国际大厦七楼702单元';  //地址
$info['merchantDetail']['email'] = '2480990710@qq.com';  //邮箱
$info['merchantDetail']['customerPhone'] = '13600010002';  //客服电话
$info['merchantDetail']['principal'] = '张三';  //负责人
$info['merchantDetail']['principalMobile'] = '13600010002';  //负责人手机号
$info['merchantDetail']['idCode'] = '350604198705281012';  //证件号码
$info['merchantDetail']['indentityPhoto'] = implode(';', $indentityPhoto);  //身份证图片,多张图片以分号;隔开
$info['merchantDetail']['accountCodePhoto'] = $accountCodePhoto;  //收款银行卡照片
$info['merchantDetail']['mainPhoto'] = $mainPhoto;  //门头照
//银行账户信息
$info['bankAccount']['accountCode'] = '6222021402018746261';  //银行卡号
$info['bankAccount']['bankId'] = '1';  //开户银行名编号
$info['bankAccount']['accountName'] = '张三';  //开户人
$info['bankAccount']['accountType'] = '1';  //帐户类型  1:个人
$info['bankAccount']['contactLine'] = '102100099996';  //联行号
$info['bankAccount']['bankName'] = '中国工商银行厦门支行';  //开户支行名称
$info['bankAccount']['province'] = '3900';  //开户支行所在省
$info['bankAccount']['city'] = '3930';  //开户支行所在市
$info['bankAccount']['idCardType'] = '1';  //持卡人证件类型  1:身份证
$info['bankAccount']['idCard'] = '350604198705281012';  //持卡人证件号码
$info['bankAccount']['tel'] = '13600010002';  //银行账户手机号
//商户支付类型信息
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10014751', 'billRate'=>'3.8');  //支付宝
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10014761', 'billRate'=>'3.8');
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10014771', 'billRate'=>'3.8');
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10002016', 'billRate'=>'6', 'billRate1'=>'6', 'billRate2'=>'6', 'billRate3'=>'6');  //云闪付
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10000973', 'billRate'=>'6', 'billRate1'=>'6', 'billRate2'=>'6', 'billRate3'=>'6');
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10000974', 'billRate'=>'6', 'billRate1'=>'6', 'billRate2'=>'6', 'billRate3'=>'6');
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10000959', 'billRate'=>'3.8');  //微信
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10000960', 'billRate'=>'3.8');
$info['mchPayConfs'][] = array('nodename'=>'mchPayConf', 'payTypeId'=>'10000961', 'billRate'=>'3.8');
//发送请求
$result = $req->smallMchAdd($info);
if($result['merchantId']){  //进件成功
	//
}else{
	//
}
?>

发表评论

邮箱地址不会被公开。 必填项已用*标注