最近的一個(gè)網(wǎng)站項(xiàng)目,需要實(shí)現(xiàn)20萬(wàn)已上在線付款蹦狂,支付寶和微信都限額痊乾,于是只好想辦法搞大額支付了,演示你可以參考下這個(gè):http://www.erdangjiade.com/php/2751.html
1撩荣、先去申請(qǐng)https://www.95516.com2铣揉、支付參數(shù),提交到銀聯(lián)對(duì)應(yīng)接口的所有參數(shù) ? ? ? ? 支付 ? ?
跳轉(zhuǎn)中...
? ? %s? ? ? ? ? ? document.onreadystatechange =function(){if(document.readyState =="complete") {? ? ? ? ? ? ? ? document.pay_form.submit();? ? ? ? ? ? }? ? ? ? };? ? HTML;/**? ? ? * 構(gòu)建自動(dòng)提交HTML表單? ? ? *@returnstring? ? ? */publicfunctioncreatePostForm(){$this->params['signature'] =$this->sign();? ? ? ? $input ='';foreach($this->paramsas$key => $item) {? ? ? ? ? ? $input .="\t\t\n";? ? ? ? }returnsprintf($this->formTemplate,$this->config['frontUrl'], $input);? ? }/**? ? ? * 驗(yàn)證簽名? ? ? * 驗(yàn)簽規(guī)則:? ? ? * 除signature域之外的所有項(xiàng)目都必須參加驗(yàn)簽? ? ? * 根據(jù)key值按照字典排序餐曹,然后用&拼接key=value形式待驗(yàn)簽字符串逛拱;? ? ? * 然后對(duì)待驗(yàn)簽字符串使用sha1算法做摘要;? ? ? * 用銀聯(lián)公鑰對(duì)摘要和簽名信息做驗(yàn)簽操作? ? ? *? ? ? *@throws\Exception? ? ? *@returnbool? ? ? */publicfunctionverifySign(){? ? ? ? $publicKey =$this->getVerifyPublicKey();? ? ? ? $verifyArr =$this->filterBeforSign();? ? ? ? ksort($verifyArr);? ? ? ? $verifyStr =$this->arrayToString($verifyArr);? ? ? ? $verifySha1 = sha1($verifyStr);? ? ? ? $signature = base64_decode($this->params['signature']);? ? ? ? $result = openssl_verify($verifySha1, $signature, $publicKey);if($result ===-1) {thrownew\Exception('Verify Error:'.openssl_error_string());? ? ? ? }return$result ===1?true:false;? ? }/**? ? ? * 取簽名證書ID(SN)? ? ? *@returnstring? ? ? */publicfunctiongetSignCertId(){return$this->getCertIdPfx($this->config['signCertPath']);? ? }/**? ? ? * 簽名數(shù)據(jù)? ? ? * 簽名規(guī)則:? ? ? * 除signature域之外的所有項(xiàng)目都必須參加簽名? ? ? * 根據(jù)key值按照字典排序台猴,然后用&拼接key=value形式待簽名字符串朽合;? ? ? * 然后對(duì)待簽名字符串使用sha1算法做摘要;? ? ? * 用銀聯(lián)頒發(fā)的私鑰對(duì)摘要做RSA簽名操作? ? ? * 簽名結(jié)果用base64編碼后放在signature域? ? ? *? ? ? *@throws\InvalidArgumentException? ? ? *@returnmultitype|string? ? ? */privatefunctionsign(){? ? ? ? $signData =$this->filterBeforSign();? ? ? ? ksort($signData);? ? ? ? $signQueryString =$this->arrayToString($signData);if($this->params['signMethod'] ==01) {//簽名之前先用sha1處理//echo $signQueryString;exit;$datasha1 = sha1($signQueryString);? ? ? ? ? ? $signed =$this->rsaSign($datasha1);? ? ? ? }else{thrownew\InvalidArgumentException('Nonsupport Sign Method');? ? ? ? }return$signed;? ? ? ? ? ? ? }/**? ? ? * 數(shù)組轉(zhuǎn)換成字符串? ? ? *@paramarray $arr? ? ? *@returnstring? ? ? */privatefunctionarrayToString($arr){? ? ? ? $str ='';foreach($arras$key => $value) {? ? ? ? ? ? $str .= $key.'='.$value.'&';? ? ? ? }returnsubstr($str,0, strlen($str) -1);? ? }/**? ? ? * 過(guò)濾待簽名數(shù)據(jù)? ? ? * signature域不參加簽名? ? ? *? ? ? *@returnarray? ? ? */privatefunctionfilterBeforSign(){? ? ? ? $tmp =$this->params;unset($tmp['signature']);return$tmp;? ? }/**? ? ? * RSA簽名數(shù)據(jù)饱狂,并base64編碼? ? ? *@paramstring $data 待簽名數(shù)據(jù)? ? ? *@returnmixed? ? ? */privatefunctionrsaSign($data){? ? ? ? $privatekey =$this->getSignPrivateKey();? ? ? ? $result = openssl_sign($data, $signature, $privatekey);if($result) {returnbase64_encode($signature);? ? ? ? }returnfalse;? ? }/**? ? ? * 取.pfx格式證書ID(SN)? ? ? *@returnstring? ? ? */privatefunctiongetCertIdPfx($path){? ? ? ? $pkcs12certdata = file_get_contents($path);? ? ? ? openssl_pkcs12_read($pkcs12certdata, $certs,$this->config['signCertPwd']);? ? ? ? $x509data = $certs['cert'];? ? ? ? openssl_x509_read($x509data);? ? ? ? $certdata = openssl_x509_parse($x509data);return$certdata['serialNumber'];? ? }/**? ? ? * 取.cer格式證書ID(SN)? ? ? *@returnstring? ? ? */privatefunctiongetCertIdCer($path){? ? ? ? $x509data = file_get_contents($path);? ? ? ? openssl_x509_read($x509data);? ? ? ? $certdata = openssl_x509_parse($x509data);return$certdata['serialNumber'];? ? }/**? ? ? * 取簽名證書私鑰? ? ? *@returnresource? ? ? */privatefunctiongetSignPrivateKey(){? ? ? ? $pkcs12 = file_get_contents($this->config['signCertPath']);? ? ? ? openssl_pkcs12_read($pkcs12, $certs,$this->config['signCertPwd']);return$certs['pkey'];? ? }/**? ? ? * 取驗(yàn)證簽名證書? ? ? *@throws\InvalidArgumentException? ? ? *@returnstring? ? ? */privatefunctiongetVerifyPublicKey(){//先判斷配置的驗(yàn)簽證書是否銀聯(lián)返回指定的證書是否一致if($this->getCertIdCer($this->config['verifyCertPath']) !=$this->params['certId']) {thrownew\InvalidArgumentException('Verify sign cert is incorrect');? ? ? ? }returnfile_get_contents($this->config['verifyCertPath']);? ? ? ? ? ? } } [2].[代碼] 配置示例 跳至 [1] [2] [3] [4]配制事例//銀聯(lián)支付設(shè)置'unionpay'=> [//測(cè)試環(huán)境參數(shù)'frontUrl'=>'https://101.231.204.80:5000/gateway/api/frontTransReq.do',//前臺(tái)交易請(qǐng)求地址//'singleQueryUrl' => 'https://101.231.204.80:5000/gateway/api/queryTrans.do', //單筆查詢請(qǐng)求地址'signCertPath'=>__DIR__.'/../keys/unionpay/test/sign/700000000000001_acp.pfx',//簽名證書路徑'signCertPwd'=>'000000',//簽名證書密碼'verifyCertPath'=>__DIR__.'/../keys/unionpay/test/verify/verify_sign_acp.cer',//驗(yàn)簽證書路徑'merId'=>'xxxxxxx',//正式環(huán)境參數(shù)//'frontUrl' => 'https://101.231.204.80:5000/gateway/api/frontTransReq.do', //前臺(tái)交易請(qǐng)求地址//'singleQueryUrl' => 'https://101.231.204.80:5000/gateway/api/queryTrans.do', //單筆查詢請(qǐng)求地址//'signCertPath' => __DIR__.'/../keys/unionpay/test/sign/PM_700000000000001_acp.pfx', //簽名證書路徑//'signCertPwd' => '000000', //簽名證書密碼//'verifyCertPath' => __DIR__.'/../keys/unionpay/test/verify/verify_sign_acp.cer', //驗(yàn)簽證書路徑//'merId' => 'xxxxxxxxx', //商戶代碼],支付事例$unionPay =newUnionPay(); $unionPay->config = Yii::$app->params['unionpay'];//上面的配置$unionPay->params = ['version'=>'5.0.0',//版本號(hào)'encoding'=>'UTF-8',//編碼方式'certId'=> $unionPay->getSignCertId(),//證書ID'signature'=>'',//簽名'signMethod'=>'01',//簽名方式'txnType'=>'01',//交易類型'txnSubType'=>'01',//交易子類'bizType'=>'000201',//產(chǎn)品類型'channelType'=>'08',//渠道類型'frontUrl'=> Url::toRoute(['payment/unionpayreturn'],true),//前臺(tái)通知地址'backUrl'=> Url::toRoute(['payment/unionpaynotify'],true),//后臺(tái)通知地址//'frontFailUrl' => Url::toRoute(['payment/unionpayfail'], true), //失敗交易前臺(tái)跳轉(zhuǎn)地址'accessType'=>'0',//接入類型'merId'=> Yii::$app->params['unionpay']['merId'],//商戶代碼'orderId'=> $orderNo,//商戶訂單號(hào)'txnTime'=> date('YmdHis'),//訂單發(fā)送時(shí)間'txnAmt'=> $sum *100,//交易金額曹步,單位分'currencyCode'=>'156',//交易幣種];? ? ? ? ? $html = $unionPay->createPostForm();異步通知示例$unionPay =newUnionPay(); $unionPay->config = Yii::$app->params['unionpay'];? ? ? ? ? $unionPay->params = Yii::$app->request->post();//銀聯(lián)提交的參數(shù)if(empty($unionPay->params)) {return'fail!'; }if($unionPay->verifySign() && $unionPay->params['respCode'] =='00') {//.......}