Get the App
SLTechnology News&Howtos  ›  Development  › 

How to develop and realize the Native function of WeChat Pay

Shulou Source: shulou.com Published: 2022-06-03 16:21:19 11月14日 Update

This article mainly introduces how to develop and achieve WeChat Pay's Native function, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

First, generate Native payment URL

Native (Native) payment URL is a series of weixin://wxpay/bizpayurl? The prefix URL is followed by a series of key-value pairs that identify the merchant. The rules for Native (native) to pay URL are as follows:

Weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXXX&productid=XXXXXX×tamp=XXXXXX&noncestr=XXXXXX

The generated code is as follows

Productid is the only id for goods. Developers need to define and maintain their own product id, which is equivalent to an order. Wechat backend uses this id to obtain transaction information through POST merchant backend.

The URL generated by the above code is as follows:

Weixin://wxpay/bizpayurl?appid=wxb489e8caeabcdefg&noncestr=BBvdr5atZ9D7s08X&productid=1234567890&sign=e15d2466a85cd62b530e2f690604e7502f67ccb5×tamp=1408025996

Second, generate QR codes

You can use a third-party interface to generate a QR code, or you can use your own code or plug-in. PHP QR Code is introduced here.

PHP QR Code is a PHP QR code generation class library, which can easily generate QR codes. Downloads and multiple demo demo are available on the official website. Check the address: http://phpqrcode.sourceforge.net/.

The syntax for generating the QR code is very simple, just fill in the URL as a parameter. Examples are as follows

Include 'phpqrcode.php'; QRcode::png (' http://www.cnblogs.com/txw1958/');

This generates a QR code for payment.

Third, generate Package

When the user scans the above QR code, the Native payment URL,URL needs to call the order information Package to return to the user, and the Package is implemented by create_native_package () of the WxPayHelper class. The call code is as follows:

When the user scans the QR code, it jumps directly to the product page, as shown below

Such a Native payment is formed.

Thank you for reading this article carefully. I hope the article "how to develop and realize WeChat Pay's Native function" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Payment generation 2D QR code development code article commodity user function information at the same time background merchant order personnel code generation value interest prefix Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei NVidia Microsoft Redmi