中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

支付寶即時到賬-PHP接入

發布時間:2020-06-06 21:13:14 來源:網絡 閱讀:984 作者:myxp 欄目:web開發

首先請到支付寶那邊申請一個及時到賬的接口賬戶,需要提交相關材料申請。然后根據即時到賬的API文檔進行接入。API文檔提供了各種語言版本的demo,我這里是下的php版demo,然后再進行相關修改操作。你也可以將demo版本的代碼重新整合,我這里暫時為了走通充值及時到賬流程,就不進行代碼重構了。

API文檔:https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7386797.0.0.eZb8FX&treeId=108&articleId=103950&docType=1


前臺表單提交

   <form action="/pay/alipayapi.php" class="tm-panel-small uk-form uk-form-stacked" method="post" target="_blank">                                                          
   <div class="element" >                                                                                                                           
   </div>                                                                                                                                                                   
   <div class="uk-form-row">                                                                                                                                                
   <div class="uk-form-controls">                                                                                                                                           
           <label for="form-username" class="uk-form-label" >訂單序號:</label>        
           <input  class="uk-form-width-large" type="text" name="WIDout_trade_no" id="out_trade_no" value="<?php echo trim($_GET['orderid']);?>" >                          
           <br>                                                                                                                                                             
   </div>                                                                                                                                                                   
   </div>                                                                                                                                                                   
                                                                                                                                                                            
   <div class="uk-form-row">                                                                                                                                                
   <div class="uk-form-controls">                                                                                                                                           
           <label for="form-username" class="uk-form-label" >商品名稱:</label>        
           <input class="uk-form-width-large"  type="text" name="WIDsubject" value="<?php echo trim($_GET['orderid']);?>" >                                                 
           <br>                                                                                                                                                             
   </div>                                                                                                                                                                   
   </div>                                                                                                                                                                   
                                                                                                                                                                            
   <div class="uk-form-row">                                                                                                                                                
   <div class="uk-form-controls">                                                                                                                                           
           <label for="form-username" class="uk-form-label" >付款金額:</label>        
           <input class="uk-form-width-large" type="text" name="WIDtotal_fee" value="<?php echo trim($_GET['amt']);?>">                                                     
           <br>                                                                                                                                                             
   </div>                                                                                                                                                                   
   </div>                                                                                                                                                                   
                                                                                                                                                                            
   <div class="uk-form-row">                                                                                                                                                
   <div class="uk-form-controls">                                                                                                                                           
           <label for="form-username" class="uk-form-label" >商品描述:</label>        
           <input  class="uk-form-width-large" type="text" name="WIDbody" value="訂單測試支付">                                                                             
           <br>                                                                                                                                                             
   </div>                                                                                                                                                                   
   </div>                                                                                                                                                                   
                                                                                                                                                                            
                                                                                                                                                                            
  <input type="hidden" name="uid" value="<?php echo $_GET['uid'];?>">                                                                                                       
  <input type="hidden" name="codes" value="<?php echo $_GET['code'];?>">                                                                                                    
  <input type="hidden" name="tags" value="<?php echo $_GET['tag'] ?>">                                                                                                      
   <div class="uk-form-row">                                                                                                                                                
     <input class="uk-button uk-button-primary uk-button-large uk-width-1-1" type="submit" class="alisubmit" value ="確認支付">                                       
   </div>                                                                                                                                                                   
  </div>                                                                                                                                                                    
  </form>

設置alipay.config.php配置文件,主要配置一下幾個參數

$alipay_config['partner'] 設置簽約賬號ID

$alipay_config['key'] 設置MD5校驗key

$alipay_config['notify_url'] 設置異步回調地址

$alipay_config['return_url'] 設置回調返回地址

$alipay_config['transport'] 設置協議類型,默認為http

$alipay_config['partner']               = 'xxxxxxxxxxxx';                                                                   
                                                                                                                            
//收款支付寶賬號,以2088開頭由16位純數字組成的字符串,一般情況下收款賬號就是簽約賬號                                        
$alipay_config['seller_id']     = $alipay_config['partner'];                                                                
                                                                                                                            
// MD5密鑰,安全檢驗碼,由數字和字母組成的32位字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm                    
$alipay_config['key']                   = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';                                               
                                                                                                                            
// 服務器異步通知頁面路徑  需http://格式的完整路徑,不能加?id=123這類自定義參數,必須外網可以正常訪問                       
$alipay_config['notify_url'] = "http://xx.xx.xx.xx/pay/notify_url.php";                                                     
                                                                                                                            
// 頁面跳轉同步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義參數,必須外網可以正常訪問                      
$alipay_config['return_url'] = "http://xx.xx.xx.xx/pay/return_url.php";                                                     
                                                                                                                            
//簽名方式                                                                                                                  
$alipay_config['sign_type']    = strtoupper('MD5');                                                                         
                                                                                                                            
//字符編碼格式 目前支持 gbk 或 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'] = "create_direct_pay_by_user";



交易處理完成后會發送訂單信息及交易狀態到你指定好的回傳return_url.php中,你可以通過回傳給你的訂單狀態判斷交易是否成功,成功則進入下一步邏輯(你自己的訂單處理邏輯),否則返回失敗。

<?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) {//驗證成功
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          //請在這里加上商戶的業務邏輯程序代碼
  
          //——請根據您的業務邏輯來編寫程序(以下代碼僅作參考)——
      //獲取支付寶的通知返回參數,可參考技術文檔中頁面跳轉同步通知參數列表
  
          //商戶訂單號^M
          $out_trade_no = $_GET['out_trade_no'];
  
          //支付寶交易號^M
          $trade_no = $_GET['trade_no'];
  
          //交易狀態
          $trade_status = $_GET['trade_status'];
  
          $total_fee = $_GET['total_fee'];
  
          //獲取用戶返回數據
          $user_info = $_GET['extra_common_param'];
          $user_arr = explode('.',$user_info);
          $uid = $user_arr[0];
          $code = $user_arr[1];
          $tags = $user_arr[2];
  
  
      if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
                  $types = "alipay";
                  $user_url = "/user_obj/do_orderinfo.php";
                  die("<script>;window.location='{$user_url}?uid={$uid}&code={$code}&tags={$tags}&payAmount={$total_fee}&order={$out_trade_no}&types={$types}';</script>");
  
                  //判斷該筆訂單是否在商戶網站中已經做過處理
                  //如果沒有做過處理,根據訂單號(out_trade_no)在商戶網站的訂單系統中查到該筆訂單的詳細,并執行商戶的業務程序
                  //如果有做過處理,不執行商戶的業務程序
  
  
      }
      else {
        echo "trade_status=".$_GET['trade_status'];
      }
  
  var_dump($verify_result);
          echo "驗證成功<br />";
  
          //——請根據您的業務邏輯來編寫程序(以上代碼僅作參考)——
  
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  }
  else {
      //驗證失敗
      //如要調試,請看alipay_notify.php頁面的verifyReturn函數
      echo "驗證失敗";
  }
  ?>
          <title>支付寶即時到賬交易接口</title>
          </head>
      <body>
      </body>
  </html>


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

安宁市| 毕节市| 文昌市| 汽车| 大安市| 台南县| 常山县| 博爱县| 宁远县| 泸定县| 宁阳县| 泰安市| 民和| 抚松县| 鹰潭市| 太仆寺旗| 寿光市| 枣阳市| 大田县| 临泽县| 罗山县| 五峰| 光泽县| 芒康县| 嵊泗县| 恩施市| 那曲县| 曲沃县| 河南省| 阜康市| 高雄县| 娄烦县| 台中市| 靖州| 涪陵区| 景宁| 富宁县| 台北县| 远安县| 青冈县| 华宁县|