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