移动支付php,银联手机支付服务端PHP端代码
1 開發前準備 先和銀聯手機支付簽約,他們會給你測試的證書已經手機客戶端的控件
2? 將包里的文件(TESTMERCHANT.p12)經過openssl生成的密鑰文件TESTMERCHANT.pm 默認密碼是 1
3 PHP端程序
下訂單程序
/*
* 銀聯支付
* */
//wap下訂單接口(需要驗證簽名)
public function wapsendAction() {
header("Content-Type:text/html; charset=utf-8");
$request = $this->getRequest();
if(isset($_SESSION['uid'])){
if($request->isPost()){
$uid=intval($_SESSION['uid']);
$money = intval($request->getPost(money));//金額以元為單位
$beans = $money;
$arraymoney=array("1","10","30","100");
if(!in_array($money,$arraymoney)){
echo '1';//金額不對
exit();
}
}else{
echo '2';//不是POST請求
exit();
}
$payaction = new PayAction();
$rid = $payaction->insertRecharge($uid, 36, $money, $beans);
if($rid) {
$orderTime=date('YmdHis');?//交易開始日期時間
//$rid='00000123';//訂單
$rid=str_pad($rid,'8','0',STR_PAD_LEFT);
//$money='000000000030';//金額str_pad(string,length,pad_string,pad_type)
$money= str_pad($money*100,'12','0',STR_PAD_LEFT);
//$bz='156';//幣種
$terminal='00000001';//pos機
$shanghu='100011000110195';//商戶代碼
$shanghumc='我在找你';//商戶名稱
$string=$orderTime.$rid.$money.$terminal.$shanghu.$shanghumc;
$fp = fopen(ROOT_ACTION.'quickpay/TESTMERCHANT.pem', "r");
$priv_key = fread($fp, 8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key);
openssl_sign($string, $signature, $pkeyid);
$len = strlen($signature);
$hexArray = "0123456789abcdef";
$str = $signature;
$result = "";
for($i=0;$i
if(ord($str[$i]) >= 128){
$byte = ord($str[$i]) - 256;
}else{
$byte =? ord($str[$i]);
}
$bytes[] = $byte ;
$byte = $byte & 0xff;
$result .= $hexArray[$byte >> 4];
$result .= $hexArray[$byte & 0xf];
}
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$orderTime.''.$beans.'塊錢訂單'.$money.''.$result.'';
}else{
$payaction = new PayAction();
$str = '銀聯wap支付下訂單失敗uid='.$uid.'money='.$money.'rid='.$rid;
$payaction->Insert_errorpay($str,1,0);//1為銀聯1 為下訂單失敗
echo '3';//訂單驗證簽名失敗
exit;
}
}else{
echo '4';//登錄后再下訂單
exit();
}
}
現在再提供一個回調的函數就可以了。
public function wapback_notifyAction() {
$request = $this->getRequest();
if($request->isPost()){
$arr_ret = file_get_contents("php://input");
$payaction = new PayAction();
$xml = new SimpleXMLElement($arr_ret);
$orderid=$this->getAttr($arr_ret,'order') ;//獲取訂單id
$submitTime=$this->getDataForXML($arr_ret,'/cupMobile/transaction/submitTime');//獲取交易時間
$moeney=$this->getDataForXML($arr_ret,'/cupMobile/transaction/billAmount');//獲取金額
$accountNumber1=$this->getDataForXML($arr_ret,'/cupMobile/transaction/accountNumber1');//獲取支付卡
$settleDate=date('Ymd');?//交易開始日期時間
$payaction->insertPayQQ(1,1,$arr_ret.'orderid'.$orderid['id']);
if($orderid['id']>0){
$orderNumbe=substr($orderid['id'],'2');
$payaction->updateRechargeStatus($orderNumbe);
echo '<?xml version="1.0" encoding="UTF-8"?>'.$submitTime.''.$submitTime.''.$moeney.''.$accountNumber1.'000000001'.$moeney.''.$settleDate.'';
}
}
}
這樣就好了 另外附帶2個xml操作函數
//xml獲取屬性值
function getAttr($str , $tag) {
preg_match_all("/(?:]*)>/im" , $str , $ary);
if(is_array($ary[1])) {
preg_match_all('/([a-zA_Z0-9]+?)\s*?(?:=)\s*?(?:[\'"]?)([a-zA_Z0-9_\-\.]*?)(?:[\'"])/im' , $ary[1][0] , $a);
for($i = 0 , $j = count($a[1]) ; $i < $j ; ++$i) {
$v[$a[1][$i]] = $a[2][$i];
}
return $v;
}
}
//xml獲取指定節點的元素值
function getDataForXML($res_data,$node)
{
$xml = simplexml_load_string($res_data);
$result = $xml->xpath($node);
while(list( , $node) = each($result))
{
return $node;
}
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的移动支付php,银联手机支付服务端PHP端代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 天猫精灵app如何联网(汉典天字的基本解
- 下一篇: 58同城app如何发布拼车信息(全国58