PHP 接入支付寶即時到賬功能
首先請到支付寶那邊申請一個及時到賬的接口賬戶,需要提交相關(guān)材料申請。然后根據(jù)即時到賬的API文檔進(jìn)行接入。API文檔提供了各種語言版本的demo,我這里是下的php版demo,然后再進(jìn)行相關(guān)修改操作。你也可以將demo版本的代碼重新整合,我這里暫時為了走通充值及時到賬流程,就不進(jìn)行代碼重構(gòu)了。
前臺表單提交
<form action="/pay/alipayapi.php" class="tm-panel-small uk-form uk-form-stacked" method="post" target="_blank"> <div class="element" style="margin-top:60px;"> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">訂單序號:</label> <input class="uk-form-width-large" type="text" name="WIDout_trade_no" id="out_trade_no" value="<?php echo trim($_GET['orderid']);?>" > <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">商品名稱:</label> <input class="uk-form-width-large" type="text" name="WIDsubject" value="<?php echo trim($_GET['orderid']);?>" > <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">付款金額:</label> <input class="uk-form-width-large" type="text" name="WIDtotal_fee" value="<?php echo trim($_GET['amt']);?>"> <br> </div> </div> <div class="uk-form-row"> <div class="uk-form-controls"> <label for="form-username" class="uk-form-label" style="display:inline-block;padding: 0 10px;vertical-align: middle;margin-left:-20px;">商品描述:</label> <input class="uk-form-width-large" type="text" name="WIDbody" value="訂單測試支付"> <br> </div> </div> <input type="hidden" name="uid" value="<?php echo $_GET['uid'];?>"> <input type="hidden" name="codes" value="<?php echo $_GET['code'];?>"> <input type="hidden" name="tags" value="<?php echo $_GET['tag'] ?>"> <div class="uk-form-row"> <input class="uk-button uk-button-primary uk-button-large uk-width-1-1" type="submit" class="alisubmit" value ="確認(rèn)支付"> </div> </div> </form>
設(shè)置alipay.config.php配置文件,主要配置一下幾個參數(shù)
$alipay_config['partner'] 設(shè)置簽約賬號ID
$alipay_config['key'] 設(shè)置MD5校驗(yàn)key
$alipay_config['notify_url'] 設(shè)置異步回調(diào)地址
$alipay_config['return_url'] 設(shè)置回調(diào)返回地址
$alipay_config['transport'] 設(shè)置協(xié)議類型,默認(rèn)為http
$alipay_config['partner'] = 'xxxxxxxxxxxx'; //收款支付寶賬號,以2088開頭由16位純數(shù)字組成的字符串,一般情況下收款賬號就是簽約賬號 $alipay_config['seller_id'] = $alipay_config['partner']; // MD5密鑰,安全檢驗(yàn)碼,由數(shù)字和字母組成的32位字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm $alipay_config['key'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // 服務(wù)器異步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義參數(shù),必須外網(wǎng)可以正常訪問 $alipay_config['notify_url'] = "http://xx.xx.xx.xx/pay/notify_url.php"; // 頁面跳轉(zhuǎn)同步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義參數(shù),必須外網(wǎng)可以正常訪問 $alipay_config['return_url'] = "http://xx.xx.xx.xx/pay/return_url.php"; //簽名方式 $alipay_config['sign_type'] = strtoupper('MD5'); //字符編碼格式 目前支持 gbk 或 utf-8 $alipay_config['input_charset']= strtolower('utf-8'); //ca證書路徑地址,用于curl中ssl校驗(yàn) //請保證cacert.pem文件在當(dāng)前文件夾目錄中 $alipay_config['cacert'] = getcwd().'\\cacert.pem'; //訪問模式,根據(jù)自己的服務(wù)器是否支持ssl訪問,若支持請選擇https;若不支持請選擇http $alipay_config['transport'] = 'http'; // 支付類型 ,無需修改 $alipay_config['payment_type'] = "1"; // 產(chǎn)品類型,無需修改 $alipay_config['service'] = "create_direct_pay_by_user";
交易處理完成后會發(fā)送訂單信息及交易狀態(tài)到你指定好的回傳return_url.php中,你可以通過回傳給你的訂單狀態(tài)判斷交易是否成功,成功則進(jìn)入下一步邏輯(你自己的訂單處理邏輯),否則返回失敗。
<?php /* * * 功能:支付寶頁面跳轉(zhuǎn)同步通知頁面 * 版本:3.3 * 日期:2012-07-23 * 說明: * 以下代碼只是為了方便商戶測試而提供的樣例代碼,商戶可以根據(jù)自己網(wǎng)站的需要,按照技術(shù)文檔編寫,并非一定要使用該代碼。 * 該代碼僅供學(xué)習(xí)和研究支付寶接口使用,只是提供一個參考。 *************************頁面功能說明************************* * 該頁面可在本機(jī)電腦測試 * 可放入HTML等美化頁面的代碼、商戶業(yè)務(wù)邏輯程序代碼 * 該頁面可以使用PHP開發(fā)工具調(diào)試,也可以使用寫文本函數(shù)logResult,該函數(shù)已被默認(rèn)關(guān)閉,見alipay_notify_class.php中的函數(shù)verifyReturn require_once("alipay.config.php"); require_once("lib/alipay_notify.class.php"); ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php //計(jì)算得出通知驗(yàn)證結(jié)果 $alipayNotify = new AlipayNotify($alipay_config); $verify_result = $alipayNotify->verifyReturn(); if($verify_result) {//驗(yàn)證成功 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //請?jiān)谶@里加上商戶的業(yè)務(wù)邏輯程序代碼 //——請根據(jù)您的業(yè)務(wù)邏輯來編寫程序(以下代碼僅作參考)—— //獲取支付寶的通知返回參數(shù),可參考技術(shù)文檔中頁面跳轉(zhuǎn)同步通知參數(shù)列表 //商戶訂單號^M $out_trade_no = $_GET['out_trade_no']; //支付寶交易號^M $trade_no = $_GET['trade_no']; //交易狀態(tài) $trade_status = $_GET['trade_status']; $total_fee = $_GET['total_fee']; //獲取用戶返回?cái)?shù)據(jù) $user_info = $_GET['extra_common_param']; $user_arr = explode('.',$user_info); $uid = $user_arr[0]; $code = $user_arr[1]; $tags = $user_arr[2]; if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') { $types = "alipay"; $user_url = "/user_obj/do_orderinfo.php"; die("<script>;window.location='{$user_url}?uid={$uid}&code={$code}&tags={$tags}&payAmount={$total_fee}&order={$out_trade_no}&types={$types}';</script>"); //判斷該筆訂單是否在商戶網(wǎng)站中已經(jīng)做過處理 //如果沒有做過處理,根據(jù)訂單號(out_trade_no)在商戶網(wǎng)站的訂單系統(tǒng)中查到該筆訂單的詳細(xì),并執(zhí)行商戶的業(yè)務(wù)程序 //如果有做過處理,不執(zhí)行商戶的業(yè)務(wù)程序 } else { echo "trade_status=".$_GET['trade_status']; } var_dump($verify_result); echo "驗(yàn)證成功<br />"; //——請根據(jù)您的業(yè)務(wù)邏輯來編寫程序(以上代碼僅作參考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else { //驗(yàn)證失敗 //如要調(diào)試,請看alipay_notify.php頁面的verifyReturn函數(shù) echo "驗(yàn)證失敗"; } ?> <title>支付寶即時到賬交易接口</title> </head> <body> </body> </html>
以上所述是小編給大家介紹的PHP 接入支付寶即時到賬功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- php支付寶在線支付接口開發(fā)教程
- php支付寶接口用法分析
- 支付寶 接口開發(fā)幫助(asp,php,asp.net,jsp)
- ThinkPHP實(shí)現(xiàn)支付寶接口功能實(shí)例
- php支付寶手機(jī)網(wǎng)頁支付類實(shí)例
- PHP實(shí)現(xiàn)QQ、微信和支付寶三合一收款碼實(shí)例代碼
- php app支付寶回調(diào)(異步通知)詳解
- PHP后臺微信支付和支付寶支付開發(fā)
- 純PHP代碼實(shí)現(xiàn)支付寶批量付款
- PHP實(shí)現(xiàn)支付寶即時到賬功能
- PHP實(shí)現(xiàn)RSA簽名生成訂單功能【支付寶示例】
- PHP實(shí)現(xiàn)的支付寶支付功能示例
相關(guān)文章
VSCode+PHPstudy配置PHP開發(fā)環(huán)境的步驟詳解
這篇文章主要介紹了VSCode+PHPstudy配置PHP開發(fā)環(huán)境,本文分步驟給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08thinkPHP3.2.3實(shí)現(xiàn)阿里大于短信驗(yàn)證的方法
這篇文章主要介紹了thinkPHP3.2.3實(shí)現(xiàn)阿里大于短信驗(yàn)證的方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-06-06PHP在彈框中獲取foreach中遍歷的id值并傳遞給地址欄
這篇文章主要介紹了PHP在彈框中獲取foreach中遍歷的id值并傳遞給地址欄的相關(guān)資料,需要的朋友可以參考下2017-06-06yii2整合百度編輯器umeditor及umeditor圖片上傳問題的解決辦法
這篇文章主要介紹了yii2整合百度編輯器umeditor及umeditor圖片上傳問題的解決辦法的相關(guān)資料,需要的朋友可以參考下2016-04-04利用php的ob緩存機(jī)制實(shí)現(xiàn)頁面靜態(tài)化方法
下面小編就為大家?guī)硪黄胮hp的ob緩存機(jī)制實(shí)現(xiàn)頁面靜態(tài)化方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07