PHP access Alipay instant to account function _php instance

Source: Internet
Author: User
Tags documentation md5

First, please go to the Alipay side to apply for a timely account of the interface accounts, need to submit relevant materials application. And then access to the real-time Billing API document. API documentation provides a variety of language versions of the demo, I here is the PHP version of the demo, and then make related modifications. You can also be the demo version of the code to be integrated, I am here temporarily in order to pass the recharge timely to the account process, no code refactoring.

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

Front Desk Form Submission

<form action= "/pay/alipayapi.php" class= "Tm-panel-small uk-form uk-form-stacked" method= "post" target= "_blank" > <div class= "element" style= "margin-top:60px;"                                                                                  
  > </div>                                                                        
  <div class= "Uk-form-row" >                                                                      
      <div class= "Uk-form-controls" > <label for= "Form-username" class= "Uk-form-label" style= "display:inline-block;padding:0 10px;vertica" l-align:middle;margin-left:-20px; " > Order serial number:</label> <input class= "Uk-form-width-large" type= "text" name= "Widout_trade_no" id= "Out_trade_n" O "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" style= "dis play:inline-block;padding:0 10px;vertical-align:middle;margin-left:-20px; "  > Product name:</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" style= "display:inline-block;padding:0 10px;vertical-ali" gn:middle;margin-left:-20px; " > Payment amount:</label> <input class= "Uk-form-width-large" type= "text" name= "Widtotal_fee" value= "<?php EC Ho Trim ($_get[' amt ']);?                                                                               
  > "> <br>                                                                                   
  </div> </div>                                                                        
  <div class= "Uk-form-row" > <div class= "Uk-form-cOntrols "> <label for=" form-username "CLA ss= "Uk-form-label" style= "display:inline-block;padding:0 10px;vertical-align:middle;margin-left:-20px;"                                       
      > Product Description:</label> <input class= "Uk-form-width-large" type= "text" name= "Widbody" value= "Order Test Payment" >                                                                               
  <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 =" Confirm Payment "> </div>                                                                                  
 </div>
 </form>

Set alipay.config.php configuration file, mainly configure a few parameters

$alipay _config[' partner '] set up the signing account ID
$alipay _config[' key '] set MD5 checksum key
$alipay _config[' Notify_url '] set an asynchronous callback address
$alipay _config[' Return_url '] set callback return address
$alipay _config[' Transport '] sets the protocol type, which defaults to HTTP

$alipay _config[' partner '] = ' xxxxxxxxxxxx '; Collection Alipay account number, with 2088 beginning by 16-digit pure numbers of strings, in general, the billing account is the signing account $alipay _config[' seller_id '] = $alipay _config[' Partner                                
']; MD5 key, security check code, 32-bit string consisting of numbers and letters, view address: https://b.alipay.com/order/pidAndKey.htm $alipay _config[' key '] = ' x                        
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx '; The Server Asynchronous notification page path needs to http://the full path of the format, can not add? id=123 Such custom parameters, must be outside the network can normally access $alipay _config[' notify_url '] = "http://xx.xx.xx.xx                           
/pay/notify_url.php "; Page Jump sync notification page path needs to http://the full path of the format, can not add? id=123 this kind of custom parameter, must extranet can normal access $alipay _config[' return_url '] = "http://xx.xx.xx.xx                           
/pay/return_url.php ";                                     
Signature method $alipay _config[' sign_type '] = strtoupper (' MD5 '); The character encoding format currently supports GBK or Utf-8 $alipay _config[' Input_charset ']= strtolower (' utf-8 ');                                          
CA certificate path address, for SSL checksums in curl//Make sure CACERT.PEM files are in the current folder directory $alipay _config[' cacert '] = GETCWD (). '                                   
\\cacert.pem ';                                          
Access mode, depending on whether your server supports SSL access, if support, please select HTTPS; if not supported please select HTTP $alipay _config[' transport '] = ' http '; Payment type, without modification $alipay _config[' payment_ty                                            
PE '] = "1"; Product type, no need to modify $alipay _config[' service '] = "create_direct_pay_by_user";

When the transaction is completed, the order information and the transaction status are sent to your designated return return_url.php, you can judge the success of the transaction by passing it back to your order status, and the success goes to the next logical (your own order processing logic), otherwise it fails.

<?php * * * Features: Alipay page Jump Sync notification page * Version: 3.3 * Date: 2012-07-23 * Description: * The following code is only for the convenience of merchant test sample code, the merchant can according to their own website needs, according to the technical documentation, not
 Be sure to use this code.
 * This code is only for learning and research Alipay interface use, just provide a reference. Page Function Description ************************* * This page can be tested on the local computer * can be placed in HTML and other landscaping page code, merchant business Logic program code * This page can be debugged using the PHP development tool, or you can use the Write text function Logresult, which has been closed by default, see Functions in alipay_notify_class.php verifyreturn require_once ("
 Alipay.config.php ");
 Require_once ("lib/alipay_notify.class.php"); ?> <! DOCTYPE html>  

The above is a small set to introduce you to the PHP access payment treasure Instant to the account function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.