php支付宝接口用法分析
本文实例讲述了php支付宝接口用法。分享给大家供大家参考。具体分析如下:
现在流行的网站支持平台,支付宝当仁不让的老大了,现在我们就来告诉你如何使用支付宝api来做第三方支付,把支付宝放到自己网站来,代码如下:
alipay_config.php配置程序如下:
<?php */ //alipay_config.php配置程序 $interfaceurl="https://www.alipay.com/payto:"; $sitename ="网站名称"; $weburl ="http://网站网址"; $o_fee ="0.00"; //平邮费 $e_fee ="0.00"; //快递费 $selleremail ="";//支付宝账号 $payalikey ="";//安全校验码 $imgurl ="pay.gif";//按钮图片源 $imgtitle ="使用支付宝购买"; //按钮图片说明 ?>
alipay.php代码如下:
<?php /********************************************************************* filename:alipay.php author: dboyzhang version: ver2.0.0beta1 contact_me:wangwang:dboyzhang *********************************************************************/ //alipay.php代码 require_once("alipay_config.php"); classalipay { functiongeturl($s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$s11,$s12,$s13,$s14,$s15,$s16,$s17,$s18,$s19,$s20,$s21,$s22,$s23) { $parameter=array( 'cmd' =>$s1, 'subject' =>$s2, 'body' =>$s3, 'order_no' =>$s4, 'price' =>$s5, 'url' =>$s6, 'type' =>$s7, 'number' =>$s8, 'transport' =>$s9, 'ordinary_fee' =>$s10, 'express_fee' =>$s11, 'readonly' =>$s12, 'buyer_msg' =>$s13, 'seller' =>$s14, 'buyer' =>$s15, 'buyer_name' =>$s16, 'buyer_address' =>$s17, 'buyer_zipcode' =>$s18, 'buyer_tel' =>$s19, 'buyer_mobile' =>$s20, 'partner' =>$s21, ); $url=$s22.$s14."?"; foreach($parameteras$key=>$value){ if($value){ $url .=$key."=".urlencode($value)."&"; $acsouce.=$key.$value; } } $url .='ac='.md5($acsouce.$s23); return$url; } } ?>
pay.php页面如下:
<?php error_reporting(0); $aliname=$_POST["aliname"]; $alizipcode=$_POST["alizipcode"]; $aliphone=$_POST["aliphone"]; $aliaddress=$_POST["aliaddress"]; $aliorder=$_POST["aliorder"]; $alimailtype=$_POST["alimailtype"]; $alimoney=$_POST["alimoney"]; $alimob=$_POST["alimob"]; $alibody=$_POST["alibody"];
require_once("alipay_config.php"); require_once("alipay.php"); $cmd ='0001'; $subject ="订单号:".$aliorder; $body ='商品介绍'; $order_no =$aliorder; $price =$alimoney; $url ='www.nhooo.com';//你的网址 $type ='1'; $number = '1'; $transport =$alimailtype; $ordinary_fee ='0.00'; $express_fee ='0.00'; $readonly ='true'; $buyer_msg =$alibody; $seller =$selleremail; $buyer =''; $buyer_name =$aliname; $buyer_address =$aliaddress; $buyer_zipcode =$alizipcode; $buyer_tel =$aliphone; $buyer_mobile =$alimob; $partner ='2088002008096997'; $geturl=newalipay; $link=$geturl->geturl ( $cmd,$subject,$body,$order_no,$price,$url,$type,$number,$transport, $ordinary_fee,$express_fee,$readonly,$buyer_msg,$seller,$buyer, $buyer_name,$buyer_address,$buyer_zipcode,$buyer_tel,$buyer_mobile,$partner, $interfaceurl,$payalikey ); ?> <html> <head> <title>简易支付宝付款php版</title> <linkhref="admin_style.css教程"rel=stylesheet> <metahttp-equiv=content-typecontent="text/html;charset=gb2312"> </head> <body> <tableclass=borderid=table1style="font-size:9pt"height=185cellspacing=0 cellpadding=0width=492align=centerborder=0> <tbody> <tr> <tdclass=topbgheight=30> <divalign=center><strong>简易支付宝付款php版</strong></div></td></tr> <tr> <tdstyle="border-left:#e4e4e41pxsolid;border-bottom:#e4e4e41pxsolid"colspan=3height=150> <tablestyle="font-size:9pt"height=137width="100%"align=centerbgcolor=#ffffff> <tbody> <trclass=tdbg> <tdwidth="14%">订单号码:</td> <tdwidth="86%"><?echo$aliorder;?></td></tr> <trclass=tdbg> <tdwidth="14%">收货人:</td> <tdwidth="86%"><?echo$aliname;?></td></tr> <trclass=tdbg> <tdwidth="14%">付款金额:</td> <tdwidth="86%"><b><?echo$alimoney;?></b></td></tr> <trclass=tdbg> <tdwidth="14%">收货地址:</td> <tdwidth="86%"><?echo$aliaddress;?></td></tr> <trclass=tdbg> <td>物流方式:</td> <td><?echo$alimailtype;?>(1.平邮2.快递3.虚拟物品)</td></tr> <trclass=tdbg> <td>联系电话:</td> <td><?echo$aliphone;?></td></tr> <trclass=tdbg> <td>邮政编码:</td> <td><?echo$alizipcode;?></td></tr> <trclass=tdbg> <td>手机号码:</td> <td><?echo$alimob;?></td></tr> <trclass=tdbg> <td>客户留言:</td> <td><?echo$alibody;?></td></tr> <trclass=tdbg> <td></td> <td><inputtype="button"name="submit21"onclick="网页特效:history.go(-1)"value="返回修改订单"> <ahref="<?phpecho$link?>"target="_blank"><imgsrc="<?phpecho$imgurl?>"alt="<?phpecho$imgtitle?>"border="0"align='absmiddle'border='0'/></a></td></tr></tbody></table></td></tr></tbody></table> </body></html>