PHP支付寶介面實例精講

小云云
發布: 2023-03-17 09:06:01
原創
3478 人瀏覽過

隨著科技的逐漸發達,現在手機支付已經成為了一種流行。那關於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:  ver 2.0.0 beta1 
 contact_me: wangwang:dboyzhang 
 *********************************************************************/
登入後複製
//alipay.php代码 
require_once("alipay_config.php"); 
class alipay 
{ 
 function geturl($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( 
    &#39;cmd&#39;   => $s1, 
    &#39;subject&#39;  => $s2, 
    &#39;body&#39;   => $s3, 
    &#39;order_no&#39;  => $s4, 
    &#39;price&#39;   => $s5, 
    &#39;url&#39;   => $s6, 
    &#39;type&#39;   => $s7, 
    &#39;number&#39;  => $s8, 
    &#39;transport&#39;  => $s9, 
    &#39;ordinary_fee&#39;  => $s10, 
    &#39;express_fee&#39;  => $s11, 
    &#39;readonly&#39;  => $s12, 
    &#39;buyer_msg&#39;  => $s13, 
    &#39;seller&#39;  => $s14, 
    &#39;buyer&#39;   => $s15, 
    &#39;buyer_name&#39;  => $s16, 
    &#39;buyer_address&#39;  => $s17, 
    &#39;buyer_zipcode&#39;  => $s18, 
    &#39;buyer_tel&#39;  => $s19, 
    &#39;buyer_mobile&#39;  => $s20, 
    &#39;partner&#39;  => $s21, 
  ); 
 
  $url = $s22.$s14."?"; 
  foreach($parameter as $key => $value){ 
    if($value){ 
      $url  .= $key."=".urlencode($value)."&"; 
      $acsouce .=$key.$value; 
    } 
  } 
  $url  .= &#39;ac=&#39;.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   = &#39;0001&#39;; $subject  = "订单号:".$aliorder; $body   = &#39;商品介绍&#39;; $order_no  = $aliorder; $price   = $alimoney; $url   = &#39;www.jb51.net&#39;;//你的网址 $type   = &#39;1&#39;; $number   =  &#39;1&#39;; $transport  = $alimailtype; $ordinary_fee  = &#39;0.00&#39;; $express_fee  = &#39;0.00&#39;; $readonly  = &#39;true&#39;; $buyer_msg  = $alibody; $seller   = $selleremail; $buyer   = &#39;&#39;; $buyer_name  = $aliname; $buyer_address  = $aliaddress; $buyer_zipcode  = $alizipcode; $buyer_tel  = $aliphone; $buyer_mobile  = $alimob; $partner  = &#39;2088002008096997&#39;;  $geturl = new alipay; $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> 
<link href="admin_style.css教程" rel=stylesheet> 
<meta http-equiv=content-type content="text/html; charset=gb2312"> 
</head> 
 
<body> 
<table class=border id=table1 style="font-size: 9pt" height=185 cellspacing=0  
cellpadding=0 width=492 align=center border=0> 
  <tbody> 
  <tr> 
    <td class=topbg height=30> 
      <div align=center><strong>简易支付宝付款php版</strong></div></td></tr> 
  <tr> 
    <td style="border-left: #e4e4e4 1px solid; border-bottom: #e4e4e4 1px solid" colspan=3 height=150> 
      <table style="font-size: 9pt" height=137 width="100%" align=center bgcolor=#ffffff> 
        <tbody> 
        <tr class=tdbg> 
          <td width="14%">订单号码:</td> 
          <td width="86%"><? echo $aliorder; ?></td></tr> 
        <tr class=tdbg> 
          <td width="14%">收 货 人:</td> 
          <td width="86%"><? echo $aliname; ?></td></tr> 
        <tr class=tdbg> 
          <td width="14%">付款金额:</td> 
          <td width="86%"><b><? echo $alimoney; ?></b></td></tr> 
        <tr class=tdbg> 
          <td width="14%">收货地址:</td> 
          <td width="86%"><? echo $aliaddress; ?></td></tr> 
        <tr class=tdbg> 
          <td>物流方式:</td> 
          <td><? echo $alimailtype; ?> (1.平邮 2.快递 3.虚拟物品)</td></tr> 
        <tr class=tdbg> 
          <td>联系电话:</td> 
          <td><? echo $aliphone; ?></td></tr> 
        <tr class=tdbg> 
          <td>邮政编码:</td> 
          <td><? echo $alizipcode; ?></td></tr> 
        <tr class=tdbg> 
          <td>手机号码:</td> 
          <td><? echo $alimob; ?></td></tr> 
        <tr class=tdbg> 
          <td>客户留言:</td> 
          <td><? echo $alibody; ?></td></tr> 
        <tr class=tdbg> 
          <td></td> 
          <td><input type="button" name="submit21" onclick="网页特效:history.go(-1)" value="返回修改订单">       <a href="<?php echo $link?>" target="_blank">
          <img src="<?php echo $imgurl?>" alt="<?php echo $imgtitle?>" border="0" align=&#39;absmiddle&#39; border=&#39;0&#39;/></a> </td></tr></tbody></table></td></tr></tbody></table> 
</body></html
登入後複製

以上就是關於php如何寫支付寶介面的實例,希望能幫助大家。

以上是PHP支付寶介面實例精講的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板