
初始页,提交基本信息到api页面,
<?php
?>
<!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
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,
);
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "确认");
echo $html_text;
?>
</body>
</html>
获取表单数据和配置数据,发起移动支付请求。
<?php
$alipay_config['partner'] = '2088221883850827';
$alipay_config['seller_id'] = $alipay_config['partner'];
$alipay_config['key'] = '4t3m3qnwiq4lzqvv66sfu2vy9r3skkcn';
$alipay_config['notify_url'] = "http://localhost/alipaywapdirect/notify_url.php";
$alipay_config['return_url'] = "http://localhost/alipaywapdirect/return_url.php";
$alipay_config['sign_type'] = strtoupper('MD5');
$alipay_config['input_charset']= strtolower('utf-8');
$alipay_config['cacert'] = getcwd().'\\cacert.pem';
$alipay_config['transport'] = 'http';
$alipay_config['payment_type'] = "1";
$alipay_config['service'] = "alipay.wap.create.direct.pay.by.user";
?>
上面是配置内容,
支付后,调整到处理页面,
<?php
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') {
}
else {
echo "trade_status=".$_GET['trade_status'];
}
echo "验证成功<br />";
}
else {
echo "验证失败";
}
?>
<title>支付宝手机网站支付接口</title>
</head>
<body>
</body>
</html>

对接到ecshop中一样的道理,

1.传入订单号,订单金额等信息。
2.配置好支付宝账号信息。
3.支付后,对支付结果进行处理,提示支付成功,或者支付失败。
修复支付后,状态不变问题。
<?php
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'];
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 {
?>
<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
操作数据库,
'IN_ECS'truerequire_once'../includes/init.php''db'"UPDATE "'ecs''order_info'" SET pay_status = 2 , confirm_time = "" , pay_time = "" where order_sn = '""'"