Talking about the process of developing micro-credit payment with PHP and the _php tutorial of PHP payment process

Source: Internet
Author: User
Tags cdata website server

Talking about the process of developing payment using PHP, talking about the PHP payment process


The following is an example of the PHP language, the payment of the development process to explain.

1. Get Order Information

2. Generate sign based on order information and payment related accounts, and generate payment parameters

3. Post the payment parameter information to the server for return information

4. Generate the corresponding payment code (internal) or pay the QR code (non-internal) according to the return information to complete the payment.

Here are a few steps to talk about:

1. The necessary order parameters related to the payment are three, namely: Body (product name or order description), Out_trade_no (usually order number) and Total_fee (order amount, unit "cent", pay attention to unit problem), in different applications, The first thing to do is to get the relevant information in the order to prepare for the payment parameter generation.

2. Other required payment parameters are AppID (AppID), mch_id (notify after successful application), Device_info (web side and end of this parameter are unified, uppercase "Web"), Trade_type (depending on the use of the scene, this value is also different, external for "NATIVE", Internal for "JSAPI"), Nonce_str (32-bit random string), SPBILL_CREATE_IP (initiating payment of the terminal IP, i.e. server IP), Notify_url (Payment callback address, server notifies the site that payment is complete or not, Modify order status), sign (signature), there is a need to explain where, if Trade_type is Jsapi, OpenID is required parameters.

Signature algorithm is more prone to error, in the signature step is cumbersome, in fact, it is crucial that sign does not participate in the signature

A: The parameters mentioned in 1, 2, except for the parameter assignment, placed in an array of arrays, sorted by dictionary order, in fact, the key values in a-Z order.

B: Convert the array to a string, formatted as K1=V1&K2=V2&...KN=VN

C: After this string, add the key value (set by the user in the payment merchant backend) Now string = K1=v1&k2=v2&...kn=vn&key=key.

d:string = MD5 (string)

E:sign = Strtoupper (String)

At this point, sign generation is complete.

Add sign to array to create a new array. Converts the array to XML. At this point, the parameter preparation for the payment is completed.

3. Generate the XML in 2, send the request to (Https://api.mch.weixin.qq.com/pay/unifiedorder) using post, get the returned XML information, convert the information into an array format to facilitate operation. The XML information returned is as follows:

 
   
  
   SUCCESS
  
    
  
   OK
  
   wx2421b1c4370ec43b 
  
   10000100
  
    
  
   IITRi8Iabbblz1Jc
  
    
  
   7921E432F65EB8ED0CE9755F0E86D72F
  
    
  
   SUCCESS
  
    
  
   wx201411101639507cbf6ffd8b0779950874
  
    
  
   JSAPI
  
   
 
  


If it is trade_type==native payment, there will be one more parameter code_url, the URL is the address of the sweep code payment.

4. Here is the process of payment.

If trade_type==native, then use some way to convert Code_url to two-dimensional code, using a sweep code, if the internal click to pay, you need to call JS-SDK in the relevant things, this step is the most important to generate a JSON format string.

The first step is to generate an array array_jsapi that transforms the JSON string.

A: The parameters of the array include: Appid,timestamp,noncestr,package,signtype (default = "MD5"), note that the case is not the same as the above array.

B: Use this array to generate the Paysign parameter, the same way as the signature.

C: Append the paysign parameter to the ARRAY_JSAPI array.

D: Format the array with Json_encode as a string js_string.

By completing the work above, you can pay in-house.

The following is an example code for a related payment:

The js_string in the code is the string we generate.

The Callpay () function is called in the HTML code to initiate the payment.

The payment of this payment is completed.

The following is the callback work, which ensures that after the order is paid successfully, the correct status is displayed to the user.

After the payment is completed, the POST request is used to feedback the payment result to the website server, the website server obtains post information and determines whether to modify the order information according to the success of the payment.

A: Remove sign from the post parameter and record the value.

B: Sign the remaining parameters

C: Match the signature result with sign in post, the same description is correct and the order status is modified according to the payment result.

E: Return the XML message to make sure that the site has received the notification and avoid pushing the post again, as shown in the following example:

 
   
  
   SUCCESS
  
    
  
   OK
  
   
 
  

If it fails, it returns

 
   
  
   FAIL
  
    
  
   失败原因
  
   
 
  

At this point, the entire development of the payment is complete.

http://www.bkjia.com/PHPjc/1058152.html www.bkjia.com true http://www.bkjia.com/PHPjc/1058152.html techarticle talking about the process of developing payment using PHP, talking about the PHP payment process the following PHP language as an example, the payment of the development process to explain. 1. Get order Information 2. According to the order letter ...

  • 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.