Personally, I think scanning code payment is much smoother in terms of development and use than Jsapi payment. When you scan the QR code to pay, you don’t have to worry about accessing via PC, mobile browser or WeChat client. Just generate a QR code and scan it to pay.
For some configuration and code SDK and errors in the SDK, please refer to the previous article WeChat Pay Articles
WeChat Payment - Detailed explanation of official account payment code
Friendly reminder that the following content is very simple - -# If you have run through Jsapi payment, then there is nothing special about scanning the QR code to pay.
The file for scanning the QR code to initiate payment is in the native.php file in the example SDK.
There are two payment methods for scan code payment. Before using scan code payment, you must configure the specific configuration of payment callback URL. Reference
WeChat developer documentation http://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_3
Introduction to two payment methods
Mode 1: http://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4
Mode 2: http://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5
In fact, mode 2 does not need to set a callback URL. However, once you modify the payment configuration and use scan code payment, you must check Native payment. At this time, the callback URL is required.
But I only want to use mode 2. There is no callback URL in mode 2, so I have to randomly write a URL that may be used in mode 1 in the future.
Code analysis:
Scan code payment mode 1
$notify = new NativePay(); $url1 = $notify->GetPrePayUrl("123456789");Mainly look at the scan code payment mode 2
$input = new WxPayUnifiedOrder(); $input->SetBody("test"); $input->SetAttach("test"); $input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis")); $input->SetTotal_fee("1"); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("test"); $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id("123456789"); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"];
QR code:
<img alt="模式二扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data=<?php%20echo%20urlencode(%24url2);?>" style="max-width:90%">First instantiate the class WxPayUnifiedOrder, then set some parameters required for payment, and pass the required parameters to the function GetPayUrl()
The function is defined in the example/Wxpay.NativePay.php file
public function GetPayUrl($input) { if($input->GetTrade_type() == "NATIVE") { $result = WxPayApi::unifiedOrder($input); return $result; } }
$result = WxPayApi::unifiedOrder($input);The code here is to call the unified ordering interface. The code is located in the file lib/WxPay.Api.php and part of the code is
if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){ throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!"); } if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){ throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!"); }
Determine the payment method, if it is JsApi method, Openid is required
The Native method must require product_id. By the way, let’s make another complaint to determine whether it is a Native payment method. The lack of product_id prompt turns out to be JSAPI required product_id.
Alas, I really can’t be sloppy anymore. The SDK can be written in such a sloppy way.
After that, the unified ordering interface process is called.
After the function is executed, a link starting with weixin:// will be returned, and then the phpqrcode program can be called to generate the QR code.
The payment result processing page can still use the processing logic in the notify.php file.
Further reading:
WeChat payment scan code payment (java version native payment)
WeChat payment development process
The latest version of WeChat Payment JS-SDK, starting from 0
iOS-About WeChat Pay
The above introduces WeChat payment - scan code payment, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function