WeChat payment Development (11) Native payment and native payment

Source: Internet
Author: User

Payment Development (11) Native payment and native payment

Keywords: public platform payment Native payment
Author: Fang Times studio
Original article: http://www.cnblogs.com/txw1958/p/wxpay-native.html

 

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

This article consists of the following three parts:


1. Generate a Native payment URL

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

Weixin: // wxpay/bizpayurl? Sign = XXXXX & appid = XXXXXX & productid = XXXXXX & timestamp = XXXXXX & noncestr = XXXXXX

The generated code is as follows:

1 <?php2 include_once("WxPayHelper.php");3 $wxPayHelper = new WxPayHelper();4 echo $wxPayHelper->create_native_url("1234567890");5 ?>

Productid is the unique id of a product. developers need to define and maintain their own product IDs. This id is equivalent to an order. The background obtains the transaction information through the POST merchant background.

The URL generated by the above Code is as follows:

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

 

Ii. Generate a QR code

You can use a third-party interface or your own Code or plug-in to generate a QR Code. Here we will introduce php qr Code.

Php qr Code is a php qr Code generation class library that allows you to easily generate QR codes. The official website provides download and multiple demo demos at: http://phpqrcode.sourceforge.net /.

The syntax for generating a QR code is very simple. You just need to enter the URL as a parameter. Example:

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

In this way, a QR code for payment is generated.

 

3. Generate a Package

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

1 <? Php 2 Export de_once ("WxPayHelper. php "); 3 4 $ commonUtil = new CommonUtil (); 5 $ wxPayHelper = new WxPayHelper (); 6 $ wxPayHelper-> setParameter (" bank_type "," WX "); 7 $ wxPayHelper-> setParameter ("body", "fang Times studio payment development tutorial"); 8 $ wxPayHelper-> setParameter ("partner", "1900000109 "); 9 $ wxPayHelper-> setParameter ("out_trade_no", $ commonUtil-> create_noncestr (); 10 $ wxPayHelper-> setParameter ("total_timeout", "1"); 11 $ wxPa YHelper-> setParameter ("fee_type", "1"); 12 $ wxPayHelper-> setParameter ("policy_url", "htttp: // www.baidu.com "); 13 $ wxPayHelper-> setParameter ("spbill_create_ip", "127.0.0.1"); 14 $ wxPayHelper-> setParameter ("input_charset", "GBK "); 15 echo $ wxPayHelper-> create_native_package (); 16?>

After scanning the QR code, the user will jump directly to the product page, as shown below:

 

Such a Native payment is formed.

 


Must the developer mode or third-party cooperation be required for the opening and payment of public platforms?

This usually requires a third party to write the payment interface, which is difficult for you

Payment interface technical development documentation

Go to the official website. I applied for an open payment yesterday.
 

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.