接口--php對接農行網上支付平台-b2b


 

對接農行網上支付平台

從銀行那邊獲取到對應的接口包

將文件保存在網站的路徑中

我是destoon網站系統對接,就放在了api/pay/新建一個文件夾abc/下

完成之后填寫接口的配置文件

路徑:ebusclient/TrustMerchant.ini

標出的內容  都是需要填寫的   對應的證書,聯系銀行要

配置完成之后  訪問測試文件確定是否安裝正確

 

 

在接下來就是交易流程

首先仿照對應demo從自己的網站中獲取接口需要的所有信息  例我在desoon中只需要對接支付充值 因為本身dt的第三方支付就是充值,所以我只需要按照農行接口需要的信息提供就可以了  如代碼

<?php
defined('IN_DESTOON') or exit('Access Denied');
require DT_ROOT.'/api/pay/'.$bank.'/ebusclient/PaymentRequest.php';

$tRequest = new PaymentRequest();

$tRequest->order["PayTypeID"] = "ImmediatePay"; //設定交易類型
$tRequest->order["OrderNo"] = "$orderid"; //設定訂單編號
$tRequest->order["ExpiredDate"] = ""; //設定訂單保存時間
$tRequest->order["OrderAmount"] = "$charge"; //設定交易金額
$tRequest->order["Fee"] = "$fee"; //設定手續費金額
$tRequest->order["CurrencyCode"] = "156"; //設定交易幣種
$tRequest->order["ReceiverAddress"] = ""; //收貨地址
$tRequest->order["InstallmentMark"] = "0"; //分期標識
$tRequest->order["CommodityType"] = "0201"; //設置商品種類
$tRequest->order["BuyIP"] = ""; //IP
$tRequest->order["orderTimeoutDate"] = ""; //設定訂單有效期
$tRequest->order["OrderDesc"] = "網站充值"; //設定訂單說明
$tRequest->order["OrderURL"] = ""; //設定訂單地址

$time1 = str_replace('-', '/', timetodate($DT_TIME,3));
$time = explode(' ', timetodate($DT_TIME,6));
$time2 = $time[1];
$tRequest->order["OrderDate"] = $time1; //設定訂單日期 (必要信息 - YYYY/MM/DD)
$tRequest->order["OrderTime"] = $time2 ; //設定訂單時間 (必要信息 - HH:MM:SS)

//2、訂單明細
$orderitem = array ();
$orderitem["ProductName"] = "網站充值"; //商品名稱
$tRequest->orderitems[0] = $orderitem;

//3、生成支付請求對象
$tRequest->request["PaymentType"] = "A"; //設定支付類型
if($DT_PC){
    $tRequest->request["PaymentLinkType"] = "1"; //設定支付接入方式
}else {
    $tRequest->request["PaymentLinkType"] = "2"; //設定支付接入方式
}

/*
if (isset($_POST['PaymentType']) && isset($_POST['PaymentLinkType']) && $_POST['PaymentType'] === "6" && $_POST['PaymentLinkType'] === "2") {
    $tRequest->request["UnionPayLinkType"] = ($_POST['UnionPayLinkType']); //當支付類型為6,支付接入方式為2的條件滿足時,需要設置銀聯跨行移動支付接入方式
}
*/
$tRequest->request["ReceiveAccount"] = ""; //設定收款方賬號
$tRequest->request["ReceiveAccName"] = ""; //設定收款方戶名
$tRequest->request["NotifyType"] = "1"; //設定通知方式
$tRequest->request["ResultNotifyURL"] = 'http://www.ceshi.cn/api/pay/abc/notify.php'; //設定通知URL地址
$tRequest->request["MerchantRemarks"] = ""; //設定附言
$tRequest->request["IsBreakAccount"] = "0"; //設定交易是否分賬
$tRequest->request["SplitAccTemplate"] = ""; //分賬模版編號 


$tResponse = $tRequest->postRequest();
/*print_r($tResponse);
exit('test11');
var_dump($tResponse);exit;*/

if ($tResponse->isSuccess()) {
    // print ("<br>Success!!!" . "</br>");
    // print ("ReturnCode   = [" . $tResponse->getReturnCode() . "]</br>");
    // print ("ReturnMsg   = [" . $tResponse->getErrorMessage() . "]</br>");
    $PaymentURL = $tResponse->GetValue("PaymentURL");
    // var_dump($PaymentURL);exit;
    // print ("<br>PaymentURL=$PaymentURL" . "</br>");
    echo "<script language='javascript'>";
    echo "window.location.href='$PaymentURL'";
    echo "</script>";
} else {
    print ("<br>Failed!!!" . "</br>");
    print ("ReturnCode   = [" . $tResponse->getReturnCode() . "]</br>");
    print ("ReturnMsg   = [" . $tResponse->getErrorMessage() . "]</br>");
}


?>

其中的有些參數直接寫死

上面的代碼就是把信息打包好發給農行  農行會返回一個支付鏈接 瀏覽器會自動跳轉到鏈接

再完了之后就是接受返回的信息 接口文檔中有說明

 

demo中有示例文件

獲取到返回的信息之后  就可以自己處理了   修改本地的支付狀態  等等

例我在destoon中的

 

<?php

require '../../../common.inc.php';

$bank = 'abc';
require DT_ROOT.'/api/pay/'.$bank.'/ebusclient/Result.php';
$PAY = cache_read('pay.php');
//1、取得MSG參數,並利用此參數值生成驗證結果對象

$tResult = new Result();
$tResponse = $tResult->init($_POST['MSG']);

if ($tResponse->isSuccess()) {
    
    $order = $tResponse->getValue("OrderNo");
    $amount = $tResponse->getValue("Amount");
    $r = $db->get_one("SELECT * FROM {$DT_PRE}finance_charge WHERE itemid='$order'");
    if($r){
        if($r['status'] == 0) {
            $charge_orderid = $r['itemid'];
            $charge_money = $r['amount'] + $r['fee'];
            $charge_amount = $r['amount'];
            $editor = 'L'.$bank;
            if($amount == $charge_money){
                require DT_ROOT.'/api/pay/success.inc.php';
                $rtnUrl = $MODULE[2]['linkurl'].'charge.php';
                echo "<script language='javascript'>";
                echo "window.location.replace('$rtnUrl')";
                echo "</script>";
            } else {
                $note = '充值金額不匹配S:'.$charge_money.'R:'.$amount;
                $db->query("UPDATE {$DT_PRE}finance_charge SET status=1,receivetime='$DT_TIME',editor='$editor',note='$note' WHERE itemid=$charge_orderid");//支付失敗
                log_write($note, 'labc');
                exit('error');
            }
        }else if($r['status'] == 1) {
            exit('error');
        } else if($r['status'] == 2) {
            exit('error');
        } else {
            $rtnUrl = $MODULE[2]['linkurl'].'charge.php';
            echo "<script language='javascript'>";
            echo "window.location.replace('$rtnUrl')";
            echo "</script>";
        }    
    }
} else {
    exit('error');
}
?>

以上基本就完工了 

友情提示  瀏覽器一定要用ie

踩過的坑  跳轉到農行支付頁面一直不成功  配置信息填寫有問題

      返回的信息一直抓不到,日志一步一步扒  總會找到錯到哪兒了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM