
初始頁,提交基本信息到api頁面,
<?php
/* *
* 功能:支付寶手機網站支付接口接口調試入口頁面
* 版本:3.4
* 修改日期:2016-03-08
* 說明:
* 以下代碼只是為了方便商戶測試而提供的樣例代碼,商戶可以根據自己網站的需要,按照技術文檔編寫,並非一定要使用該代碼。
*/
?>
<!DOCTYPE html>
<html>
<head>
<title>支付寶手機網站支付接口接口</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
*{
margin:0;
padding:0;
}
ul,ol{
list-style:none;
}
body{
font-family: "Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;
}
.hidden{
display:none;
}
.new-btn-login-sp{
padding: 1px;
display: inline-block;
width: 75%;
}
.new-btn-login {
background-color: #02aaf1;
color: #FFFFFF;
font-weight: bold;
border: none;
width: 100%;
height: 30px;
border-radius: 5px;
font-size: 16px;
}
#main{
width:100%;
margin:0 auto;
font-size:14px;
}
.red-star{
color:#f00;
width:10px;
display:inline-block;
}
.null-star{
color:#fff;
}
.content{
margin-top:5px;
}
.content dt{
width:100px;
display:inline-block;
float: left;
margin-left: 20px;
color: #666;
font-size: 13px;
margin-top: 8px;
}
.content dd{
margin-left:120px;
margin-bottom:5px;
}
.content dd input {
width: 85%;
height: 28px;
border: 0;
-webkit-border-radius: 0;
-webkit-appearance: none;
}
#foot{
margin-top:10px;
position: absolute;
bottom: 15px;
width: 100%;
}
.foot-ul{
width: 100%;
}
.foot-ul li {
width: 100%;
text-align:center;
color: #666;
}
.note-help {
color: #999999;
font-size: 12px;
line-height: 130%;
margin-top: 5px;
width: 100%;
display: block;
}
#btn-dd{
margin: 20px;
text-align: center;
}
.foot-ul{
width: 100%;
}
.one_line{
display: block;
height: 1px;
border: 0;
border-top: 1px solid #eeeeee;
width: 100%;
margin-left: 20px;
}
.am-header {
display: -webkit-box;
display: -ms-flexbox;
display: box;
width: 100%;
position: relative;
padding: 7px 0;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
background: #1D222D;
height: 50px;
text-align: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
box-pack: center;
-webkit-box-align: center;
-ms-flex-align: center;
box-align: center;
}
.am-header h1 {
-webkit-box-flex: 1;
-ms-flex: 1;
box-flex: 1;
line-height: 18px;
text-align: center;
font-size: 18px;
font-weight: 300;
color: #fff;
}
</style>
</head>
<body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
<header class="am-header">
<h1>支付寶手機網站支付接口快速通道</h1>
</header>
<div id="main">
<form name=alipayment action=alipayapi.php method=post target="_blank">
<div id="body" style="clear:left">
<dl class="content">
<dt>商戶訂單號
:</dt>
<dd>
<input id="WIDout_trade_no" name="WIDout_trade_no" />
</dd>
<hr class="one_line">
<dt>訂單名稱
:</dt>
<dd>
<input id="WIDsubject" name="WIDsubject" />
</dd>
<hr class="one_line">
<dt>付款金額
:</dt>
<dd>
<input id="WIDtotal_fee" name="WIDtotal_fee" />
</dd>
<hr class="one_line">
<dt>商品展示網址
:</dt>
<dd>
<input id="WIDshow_url" name="WIDshow_url" />
</dd>
<hr class="one_line">
<dt>商品描述:</dt>
<dd>
<input id="WIDbody" name="WIDbody" />
</dd>
<hr class="one_line">
<dt></dt>
<dd id="btn-dd">
<span class="new-btn-login-sp">
<button class="new-btn-login" type="submit" style="text-align:center;">確 認</button>
</span>
<span class="note-help">如果您點擊“確認”按鈕,即表示您同意該次的執行操作。</span>
</dd>
</dl>
</div>
</form>
<div id="foot">
<ul class="foot-ul">
<li>
支付寶版權所有 2015-2018 ALIPAY.COM
</li>
</ul>
</div>
</div>
</body>
<script language="javascript">
function GetDateNow() {
var vNow = new Date();
var sNow = "";
sNow += String(vNow.getFullYear());
sNow += String(vNow.getMonth() + 1);
sNow += String(vNow.getDate());
sNow += String(vNow.getHours());
sNow += String(vNow.getMinutes());
sNow += String(vNow.getSeconds());
sNow += String(vNow.getMilliseconds());
document.getElementById("WIDout_trade_no").value = sNow;
document.getElementById("WIDsubject").value = "測試";
document.getElementById("WIDtotal_fee").value = "0.01";
}
GetDateNow();
</script>
</html>
進入API頁,
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>支付寶手機網站支付接口接口</title>
</head>
<?php
/* *
* 功能:手機網站支付接口接入頁
* 版本:3.3
* 修改日期:2012-07-23
* 說明:
* 以下代碼只是為了方便商戶測試而提供的樣例代碼,商戶可以根據自己網站的需要,按照技術文檔編寫,並非一定要使用該代碼。
* 該代碼僅供學習和研究支付寶接口使用,只是提供一個參考。
*************************注意*************************
* 如果您在接口集成過程中遇到問題,可以按照下面的途徑來解決
*1、開發文檔中心(https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.2Z6TSk&treeId=60&articleId=103693&docType=1)
*2、商戶幫助中心(https://cshall.alipay.com/enterprise/help_detail.htm?help_id=473888)
*3、支持中心(https://support.open.alipay.com/alipay/support/index.htm)
* 如果不想使用擴展功能請把擴展功能參數賦空值。
*/
require_once("alipay.config.php");
require_once("lib/alipay_submit.class.php");
/**************************請求參數**************************/
//商戶訂單號,商戶網站訂單系統中唯一訂單號,必填
$out_trade_no = $_POST['WIDout_trade_no'];
//訂單名稱,必填
$subject = $_POST['WIDsubject'];
//付款金額,必填
$total_fee = $_POST['WIDtotal_fee'];
//收銀台頁面上,商品展示的超鏈接,必填
$show_url = $_POST['WIDshow_url'];
//商品描述,可空
$body = $_POST['WIDbody'];
/************************************************************/
//構造要請求的參數數組,無需改動
$parameter = array(
"service" => $alipay_config['service'],
"partner" => $alipay_config['partner'],
"seller_id" => $alipay_config['seller_id'],
"payment_type" => $alipay_config['payment_type'],
"notify_url" => $alipay_config['notify_url'],
"return_url" => $alipay_config['return_url'],
"_input_charset" => trim(strtolower($alipay_config['input_charset'])),
"out_trade_no" => $out_trade_no,
"subject" => $subject,
"total_fee" => $total_fee,
"show_url" => $show_url,
"body" => $body,
//其他業務參數根據在線開發文檔,添加參數.文檔地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.2Z6TSk&treeId=60&articleId=103693&docType=1
//如"參數名" => "參數值" 注:上一個參數末尾需要“,”逗號。
);
//建立請求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "確認");
echo $html_text;
?>
</body>
</html>
獲取表單數據和配置數據,發起移動支付請求。
<?php
/* *
* 配置文件
* 版本:3.4
* 修改日期:2016-03-08
* 說明:
* 以下代碼只是為了方便商戶測試而提供的樣例代碼,商戶可以根據自己網站的需要,按照技術文檔編寫,並非一定要使用該代碼。
* 該代碼僅供學習和研究支付寶接口使用,只是提供一個參考。
* 安全校驗碼查看時,輸入支付密碼后,頁面呈灰色的現象,怎么辦?
* 解決方法:
* 1、檢查瀏覽器配置,不讓瀏覽器做彈框屏蔽設置
* 2、更換瀏覽器或電腦,重新登錄查詢。
*/
//↓↓↓↓↓↓↓↓↓↓請在這里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
//合作身份者ID,簽約賬號,以2088開頭由16位純數字組成的字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm
$alipay_config['partner'] = '2088221883850827';
//收款支付寶賬號,以2088開頭由16位純數字組成的字符串,一般情況下收款賬號就是簽約賬號
$alipay_config['seller_id'] = $alipay_config['partner'];
// MD5密鑰,安全檢驗碼,由數字和字母組成的32位字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm
$alipay_config['key'] = '4t3m3qnwiq4lzqvv66sfu2vy9r3skkcn';
// 服務器異步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義參數,必須外網可以正常訪問
$alipay_config['notify_url'] = "http://localhost/alipaywapdirect/notify_url.php";
// 頁面跳轉同步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義參數,必須外網可以正常訪問
$alipay_config['return_url'] = "http://localhost/alipaywapdirect/return_url.php";
//簽名方式
$alipay_config['sign_type'] = strtoupper('MD5');
//字符編碼格式 目前支持utf-8
$alipay_config['input_charset']= strtolower('utf-8');
//ca證書路徑地址,用於curl中ssl校驗
//請保證cacert.pem文件在當前文件夾目錄中
$alipay_config['cacert'] = getcwd().'\\cacert.pem';
//訪問模式,根據自己的服務器是否支持ssl訪問,若支持請選擇https;若不支持請選擇http
$alipay_config['transport'] = 'http';
// 支付類型 ,無需修改
$alipay_config['payment_type'] = "1";
// 產品類型,無需修改
$alipay_config['service'] = "alipay.wap.create.direct.pay.by.user";
//↑↑↑↑↑↑↑↑↑↑請在這里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
?>
上面是配置內容,
支付后,調整到處理頁面,
<?php
/* *
* 功能:支付寶頁面跳轉同步通知頁面
* 版本:3.3
* 日期:2012-07-23
* 說明:
* 以下代碼只是為了方便商戶測試而提供的樣例代碼,商戶可以根據自己網站的需要,按照技術文檔編寫,並非一定要使用該代碼。
* 該代碼僅供學習和研究支付寶接口使用,只是提供一個參考。
*************************頁面功能說明*************************
* 該頁面可在本機電腦測試
* 可放入HTML等美化頁面的代碼、商戶業務邏輯程序代碼
* 該頁面可以使用PHP開發工具調試,也可以使用寫文本函數logResult,該函數已被默認關閉,見alipay_notify_class.php中的函數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
//計算得出通知驗證結果
$alipayNotify = new AlipayNotify($alipay_config);
$verify_result = $alipayNotify->verifyReturn();
if($verify_result) {//驗證成功
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//請在這里加上商戶的業務邏輯程序代碼
//——請根據您的業務邏輯來編寫程序(以下代碼僅作參考)——
//獲取支付寶的通知返回參數,可參考技術文檔中頁面跳轉同步通知參數列表
//商戶訂單號
$out_trade_no = $_GET['out_trade_no'];
//支付寶交易號
$trade_no = $_GET['trade_no'];
//交易狀態
$trade_status = $_GET['trade_status'];
if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
//判斷該筆訂單是否在商戶網站中已經做過處理
//如果沒有做過處理,根據訂單號(out_trade_no)在商戶網站的訂單系統中查到該筆訂單的詳細,並執行商戶的業務程序
//如果有做過處理,不執行商戶的業務程序
}
else {
echo "trade_status=".$_GET['trade_status'];
}
echo "驗證成功<br />";
//——請根據您的業務邏輯來編寫程序(以上代碼僅作參考)——
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else {
//驗證失敗
//如要調試,請看alipay_notify.php頁面的verifyReturn函數
echo "驗證失敗";
}
?>
<title>支付寶手機網站支付接口</title>
</head>
<body>
</body>
</html>

對接到ecshop中一樣的道理,

1.傳入訂單號,訂單金額等信息。
2.配置好支付寶賬號信息。
3.支付后,對支付結果進行處理,提示支付成功,或者支付失敗。
修復支付后,狀態不變問題。
<?php
/* *
* 功能:支付寶頁面跳轉同步通知頁面
* 版本:3.3
* 日期:2012-07-23
* 說明:
* 以下代碼只是為了方便商戶測試而提供的樣例代碼,商戶可以根據自己網站的需要,按照技術文檔編寫,並非一定要使用該代碼。
* 該代碼僅供學習和研究支付寶接口使用,只是提供一個參考。
*************************頁面功能說明*************************
* 該頁面可在本機電腦測試
* 可放入HTML等美化頁面的代碼、商戶業務邏輯程序代碼
* 該頁面可以使用PHP開發工具調試,也可以使用寫文本函數logResult,該函數已被默認關閉,見alipay_notify_class.php中的函數verifyReturn
*/
require_once("alipay.config.php");
require_once("lib/alipay_notify.class.php");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style type="text/css">
#page{
width: 98%;
height: 10em;
margin:1em auto;
font-size:1em;
line-height:1.5em;
}
#page2{
width: 98%;
height: 10em;
margin:1em auto;
;
font-size:1em;
line-height:1.5em;
}
</style>
<title>支付寶即時到賬交易接口</title>
</head>
<body>
<?php
//計算得出通知驗證結果
$alipayNotify = new AlipayNotify($alipay_config);
$verify_result = $alipayNotify->verifyReturn();
if($verify_result) {//驗證成功
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//請在這里加上商戶的業務邏輯程序代碼
//——請根據您的業務邏輯來編寫程序(以下代碼僅作參考)——
//獲取支付寶的通知返回參數,可參考技術文檔中頁面跳轉同步通知參數列表
//商戶訂單號
$out_trade_no = $_GET['out_trade_no'];
//支付寶交易號
$trade_no = $_GET['trade_no'];
//交易狀態
$trade_status = $_GET['trade_status'];
//判斷該筆訂單是否在商戶網站中已經做過處理
//如果沒有做過處理,根據訂單號(out_trade_no)在商戶網站的訂單系統中查到該筆訂單的詳細,並執行商戶的業務程序
//如果有做過處理,不執行商戶的業務程序
if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS'){
// 更改支付狀態
// 訂單確認時間
// 訂單支付時間
define('IN_ECS', true);
require_once('../includes/init.php'); // 原來是這里出了問題
$r = $GLOBALS['db']->query("UPDATE ".$GLOBALS['ecs']->table('order_info')." SET pay_status = 2 , confirm_time = ".time()." , pay_time = ".time()." where order_sn = '".$out_trade_no."'");
?>
<div id='page'>
<div style="text-align:center;color:red;font-size:2em;font-weight: bold;">
<br />
<br />
<br />
祝賀您!您的訂單支付已經成功!!!3秒后自動跳轉動商城首頁
</div>
</div>
<?php
}else{
//支付失敗
?>
<div id='page2'>
<div style="text-align:center;font-weight: bold; font-size:2em;color:red;">
<br />
<br />
<br />
很抱歉,您的訂單支付失敗!3秒后自動跳轉動商城首頁
</div>
</div>
<?php
}
}
else {
//驗證失敗
//如要調試,請看alipay_notify.php頁面的verifyReturn函數
?>
<div id='page2'>
<div style="text-align:center;font-weight: bold;font-size:2em;"><span style="color:red;">支付失敗</span><br />
支付過程中出現驗證錯誤,如果你的支付寶金額已被扣除,請聯系開發商
</div>
</div>
<?php
}
?>
<script type="text/javascript">
window.setTimeout("window.location='http://local.easymall.com/mobile/'",3000);
</script>
</body>
</html>
ecshop
操作數據庫,
// 更改支付狀態
// 訂單確認時間
// 訂單支付時間
define('IN_ECS', true);
require_once('../includes/init.php'); // 原來是這里出了問題
$r = $GLOBALS['db']->query("UPDATE ".$GLOBALS['ecs']->table('order_info')." SET pay_status = 2 , confirm_time = ".time()." , pay_time = ".time()." where order_sn = '".$out_trade_no."'");
