Introduction to the process of using PHP to develop WeChat Payment, and introduction to php payment process _ PHP Tutorial

Source: Internet
Author: User
Let's talk about the PHP payment process. Let's talk about the PHP payment development process. let's talk about the php payment process. next we will take the PHP language as an example to explain the payment development process. 1. obtain order information 2. discuss the process of using PHP to develop payment based on the order letter, and discuss the php payment process

The following uses the PHP language as an example to describe the payment development process.

1. obtain order information

2. generate a sign based on the order information and payment-related accounts, and generate payment parameters

3. POST the payment parameter information to the server to obtain the returned information.

4. Generate the corresponding payment code (internal) or payment QR code (non-internal) based on the returned information to complete the payment.

The steps below are as follows:

1. there are three required order parameters in the payment process: body (commodity name or order description), out_trade_no (generally order number), and total_amount (order amount, unit "minute ", pay attention to unit issues). in different applications, the first thing to do is to obtain the relevant information in the order and prepare for the payment parameter generation.

2. other required payment parameters include appid and mch_id (notified after successful application). device_info (the parameters are unified on the web end and end, and the parameters are capitalized "WEB"). trade_type (this value varies depending on the scenario. the external value is "NATIVE", the internal value is "JSAPI"), nonce_str (32-bit random string ), spbill_create_ip (the terminal IP address that initiates the payment, that is, the server IP address), yy_url (the payment callback address, the server notifies the website whether the payment is completed or not, and changes the order status), sign (signature ), in addition, if trade_type is JSAPI, openid is a required parameter.

The signature algorithm is prone to errors because the signing steps are cumbersome. In fact, it is very important that sign is not involved in the signature.

Assign A: put the parameter value except sign mentioned in 1, 2 into an array, sort by dictionary order, in fact, the key value is sorted by A-Z order.

B: convert the array to a string in the format of k1 = v1 & k2 = v2 &... kN = vN.

C: add the KEY value after the string (set by the user at the payment merchant's background). now string = k1 = v1 & k2 = v2 &... kN = vN & key = KEY.

D: string = md5 (string)

E: sign = strtoupper (string)

So far, sign generation is complete.

Add the sign to the array to generate a new array. Convert the array to XML. Now, the parameter preparation for the payment is complete.

3. send the XML generated in 2 to ( using POST, get the returned XML Information, convert the information into an array format for easy operation. The returned XML information is as follows:


If it is trade_type = native, there will be another parameter code_url, which is the address for the QR code payment.

4. The following is the payment process.

If trade_type = native, you can use some methods to convert code_url to a QR code and scan the code. if you click pay internally, you need to call related items in the js-sdk, in this step, the key is to generate a json string.

First, array_jsapi must be generated to convert the json string.

A: The parameters of this array include appId, timeStamp, nonceStr, package, and signType ("MD5" by default). Note that the case sensitivity is different from that in the preceding array.

B: Use this array to generate the paySign parameter. the signature method is the same as above.

C: append the paySign parameter to the array_jsapi array.

D: format the array using json_encode as the string js_string.

After completing the above work, you can make an internal payment.

The following is an example of the relevant payment code:

Related Article

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