Home  >  Article  >  WeChat Applet  >  WeChat payment development Native payment

WeChat payment development Native payment

高洛峰
高洛峰Original
2017-02-28 10:00:313161browse

In this WeChat public platform development tutorial, we will introduce how to develop the Native function of WeChat payment.

This article is divided into the following three parts:

Generate Native payment URL

Generate QR code

Generate Package


1. Generate Native payment URL

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

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

The generated code is as follows

<?php
include_once("WxPayHelper.php");
$wxPayHelper = new WxPayHelper();
echo $wxPayHelper->create_native_url("1234567890");
?>

The productid is the unique ID of the product. Developers need to define and maintain their own product ID. This ID is equivalent to an order. The WeChat backend uses this ID to obtain transaction information through the POST merchant backend.

The URL generated by the above code is as follows:

weixin://wxpay/bizpayurl?appid=wxb489e8caeabcdefg&noncestr=BBvdr5atZ9D7s08X&productid=1234567890&sign=e15d2466a85cd62b530e2f690604e7502f67ccb5&timestamp=1408025996

2. Generate QR code

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

PHP QR Code is a PHP QR code generation library that can be used to easily generate QR codes. The official website provides downloads and multiple demonstration demos. View address: http://phpqrcode.sourceforge.net /.

The syntax for generating QR codes is very simple, just fill in the URL as a parameter. The example is as follows

include &#39;phpqrcode.php&#39;; 
QRcode::png(&#39;http://www.cnblogs.com/txw1958/&#39;);

This generates a payment QR code.

3. Generate Package

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

<?php
include_once("WxPayHelper.php");

$commonUtil = new CommonUtil();
$wxPayHelper = new WxPayHelper();
$wxPayHelper->setParameter("bank_type", "WX");
$wxPayHelper->setParameter("body", "方倍工作室微信支付开发教程");
$wxPayHelper->setParameter("partner", "1900000109");
$wxPayHelper->setParameter("out_trade_no", $commonUtil->create_noncestr());
$wxPayHelper->setParameter("total_fee", "1");
$wxPayHelper->setParameter("fee_type", "1");
$wxPayHelper->setParameter("notify_url", "htttp://www.baidu.com");
$wxPayHelper->setParameter("spbill_create_ip", "127.0.0.1");
$wxPayHelper->setParameter("input_charset", "GBK");
echo $wxPayHelper->create_native_package();
?>

When the user scans the QR code, he will jump directly to the product page, as shown below

微信支付开发 Native支付

Such a Native payment is formed.

For more articles related to WeChat payment development and Native payment, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn