ThinkPHP integration of WeChat payment-Native scan payment mode 1

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn. This article is the second tutorial in the payment series after the jsapi payment: payment by QR code
The following describes two modes of QR code payment: Mode 1 and Mode 2 are slightly more complex. The content, process, and development documents of Mode 1 and Mode 2 are described in detail, I will not talk nonsense here. Next, let's take a quick tutorial!
First, we will import the payment class library as follows:


Next is the file under Public:


The configuration here is the same as JSAPI payment and does not need to be changed
For more information about the file, please refer to JSAPI payment, here is no longer the link address: http://www.thinkphp1.cn/code/1321.html

Next, let's look at the Controller code:
Step 1: Initialize and introduce the WxPayPubHelper class library. /**
* Initialization
*/
Public function _ initialize ()
{
// Introduce WxPayPubHelper
Vendor ('wxpaypubhelper. WxPayPubHelper ');
}
Step 2: display the QR code scan page. You need to save the QR code link. Public function native_pay ()
{
// Set static links
$ NativeLink = new \ NativeLink_pub ();

// Set static link Parameters
// Set required parameters
// Appid is entered, and merchants do not need to fill it again
// Mch_id is entered, and the Merchant does not need to fill it again
// Noncestr is entered, and merchants do not need to enter it again
// Time_stamp has been filled, and merchants do not need to fill it out again
// The sign has been filled in, and the Merchant does not need to fill in it again
$ Product_id = C ('wxpayconf _ pub. APPID '). "static"; // custom product id
$ NativeLink-> setParameter ("product_id", $ product_id); // product id
// Obtain the link
$ Product_url = $ nativeLink-> getUrl ();
// Use the short link conversion interface
$ Response url = new \ ShortUrl_pub ();
// Set required parameters
// Appid is entered, and merchants do not need to fill it again
// Mch_id is entered, and the Merchant does not need to fill it again
// Noncestr is entered, and merchants do not need to enter it again
// The sign has been filled in, and the Merchant does not need to fill in it again
$ Parameter URL-> setParameter ("long_url", $ product_url); // URL link
// Obtain the short link
$ CodeUrl = $ response URL-> getresponse URL ();
$ This-> assign ('product _ url', $ product_url );
$ This-> assign ('codeurl', $ codeUrl );
$ This-> display ();

}
Match the native_pay.html page with the above Code



Secure Payment



Scan me, scan me




Back to homepage



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.