配置alipay.config.php,
只配置$alipay_config['partner'](16位) / $alipay_config['key'](32位).
//合作身份者id,以2088开头的16位纯数字 $alipay_config['partner'] = '2088************'; //安全检验码,以数字和字母组成的32位字符 $alipay_config['key'] = 'vw******************************';
2.配置alipayapi.php
require_once("alipay.config.php"); require_once("lib/alipay_submit.class.php");
保证参数数组信息完整!$parameter
//构造要请求的参数数组,无需改动 $parameter = array( "service" => "trade_create_by_buyer", "partner" => trim($alipay_config['partner']), "payment_type" => $payment_type, "notify_url" => $notify_url, "return_url" => $return_url, "seller_email" => $seller_email, "out_trade_no" => $out_trade_no, "subject" => $subject, "price" => $price, "quantity" => $quantity, "logistics_fee" => $logistics_fee, "logistics_type" => $logistics_type, "logistics_payment" => $logistics_payment, "body" => $body, "show_url" => $show_url, "receive_name" => $receive_name, "receive_address" => $receive_address, "receive_zip" => $receive_zip, "receive_phone" => $receive_phone, "receive_mobile" => $receive_mobile, "_input_charset" => trim(strtolower($alipay_config['input_charset'])) ); //建立请求 $alipaySubmit = new AlipaySubmit($alipay_config); $html_text = $alipaySubmit->buildRequestForm($parameter,"get", "确认"); echo $html_text;
3.配置alipay_submit.class.php修改订单确认界面修改 function buildRequestForm.
function buildRequestForm($para_temp, $method, $button_name) { //待请求参数数组 $para = $this->buildRequestPara($para_temp); $sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$this->alipay_gateway_new."_input_charset=".trim(strtolower($this->alipay_config['input_charset']))."' method='".$method."'>"; while (list ($key, $val) = each ($para)) { $sHtml.= $key.":<input type='text' name='".$key."' value='".$val."'/><br/>"; } //submit按钮控件请不要含有name属性 $sHtml = $sHtml."<input type='submit' value='".$button_name."'></form>"; $sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>"; return $sHtml; }
4.修改return_url.php,支付返回信息处理
require_once("alipay.config.php"); require_once("lib/alipay_notify.class.php");
//商户订单号$out_trade_no = $_GET['out_trade_no'];
//支付宝交易号$trade_no = $_GET['trade_no'];
//交易状态$trade_status = $_GET['trade_status'];
if($_GET['trade_status'] == 'WAIT_SELLER_SEND_GOODS') { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 } else if($_GET['trade_status'] == 'TRADE_FINISHED') { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 } else { echo "trade_status=".$_GET['trade_status']; }