


Share an example tutorial on developing WeChat public account for credit card payment
Welcome to leave a message and forward
This article will specifically talk about WeChat card payment
Scene introduction
- ##Step 1: The user chooses to pay by swiping a card and opens WeChat, and enters "Me"->"Wallet"->"Swipe Card" barcode interface
- Step 2: The cashier operates the merchant system to generate a payment order, and the user confirms the payment amount
- Step 3: The merchant’s cashier scans the user’s barcode/QR code with a scanning device, and the merchant collects cash The system submits the payment
- Step 4: The WeChat payment backend system receives the payment request and determines whether to verify the user's payment password based on the password verification rules. For transactions that do not require password verification, deductions are initiated directly. For transactions that require password verification, a password input box will pop up. After the payment is successful, a success page will pop up on WeChat. If the payment fails, an error message will pop up
For detailed document introduction, you only need to briefly understand the process. Click here
Card payment access modes can be divided into: merchant backend access (provided to others for use by similar third parties) and store access (for own use);
The difference is that the payment results are distributed once more .
- Transactions with payment amount >500 yuan require verification of user payment password
- User account every day A maximum of 5 transactions can be password-free, after which the password needs to be verified
- WeChat payment background determines that the user's payment behavior is abnormal, and transactions that comply with the password-free rules will also require password verification
The difference between password-free mode and password verification mode will be discussed laterLet’s talk about the specific implementation The payment interface used in credit card payment is: Submitting credit card payment
API uses the https request; a WeChat payment certificate is not required.
micropay()<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>public void micropay(){
String url="https://api.mch.weixin.qq.com/pay/micropay";
String total_fee="1";
//授权码
String auth_code = getPara("auth_code");
Map<String, String> params = new HashMap<String, String>();
params.put("appid", appid);
params.put("mch_id", partner);
params.put("device_info", "javen205");//终端设备号
params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
params.put("body", "刷卡支付测试");
// params.put("detail", "json字符串");//非必须
params.put("attach", "javen205");//附加参数非必须
String out_trade_no=System.currentTimeMillis()+"";
params.put("out_trade_no", out_trade_no);
params.put("total_fee", total_fee);
String ip = IpKit.getRealIp(getRequest());
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
params.put("spbill_create_ip", ip);
params.put("auth_code", auth_code);
String sign = PaymentKit.createSign(params, paternerKey);
params.put("sign", sign);
String xmlResult = HttpUtils.post(url, PaymentKit.toXml(params));
//同步返回结果
System.out.println("xmlResult:"+xmlResult);
Map<String, String> result = PaymentKit.xmlToMap(xmlResult);
String return_code = result.get("return_code");
if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
//通讯失败
String err_code = result.get("err_code");
//用户支付中,需要输入密码
if (err_code.equals("USERPAYING")) {
//等待5秒后调用【查询订单API】https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_2
}
renderText("通讯失败>>"+xmlResult);
return;
}
String result_code = result.get("result_code");
if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
//支付失败
renderText("支付失败>>"+xmlResult);
return;
}
//支付成功
renderText(xmlResult);
}</pre><div class="contentsignin">Copy after login</div></div>
in com.javen.weixin.controller.WeixinPayController
http://domain name[/project name]/pay/micropay?auth_code=xxxxx,
authorization code auth_code is the barcode of the WeChat client card swiping interface the numbers shown on.
(Note: User card swiping barcode rules: 18 pure digits, starting with 10, 11, 12, 13, 14, 15)Test
You can test without using a code scanner, but it is a little troublesome to enter the authorization code manually (it refreshes once every 1 minute), and you need to enter the authorization code quickly. The code scanner only reads the authorization code and does nothing else.The address for my local port mapping test is as follows:
auth_code The value is written by whoever
http://domain name /pay/micropay?auth_code=111 Access
1 2 3 4 5 6 7 8 9 10 11 |
|
err_code is
USERPAYING
This is with password and without password The difference is that if you have a password, you must useEnter the correctquery order
to obtain the payment result. If the result is still
USERPAYING, the
query will be called every 5 seconds loop The order APIdetermines the actual payment result. If the user cancels the payment or the user fails to pay for 30 seconds, the merchant's cashier
exits the query process and continues to call the cancel order APIto cancel the payment transaction. .
auth_code The returned result is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
IfAccess mode Access the merchant backend If the payment is successful, the WeChat payment system will return the above xml
Ifdata to the merchant, and the merchant will call back the payment result to the store cashier, and the cashier will continue to process the business logic
access mode-store access the payment is successful, the WeChat payment system will return the above xml
data to the cashier, and the cashier will continue to process the business logic
WeChat public account platform source code download
2.小 Pigcms (PigCms) micro-e-commerce System operation version (independent WeChat store + three-level distribution system)
3.The above is the detailed content of Share an example tutorial on developing WeChat public account for credit card payment. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP is an open source scripting language that is widely used in web development and server-side programming, especially in WeChat development. Today, more and more companies and developers are starting to use PHP for WeChat development because it has become a truly easy-to-learn and easy-to-use development language. In WeChat development, message encryption and decryption are a very important issue because they involve data security. For messages without encryption and decryption methods, hackers can easily obtain the data, posing a threat to users.

With the popularity of WeChat, more and more companies are beginning to use it as a marketing tool. The WeChat group messaging function is one of the important means for enterprises to conduct WeChat marketing. However, if you only rely on manual sending, it is an extremely time-consuming and laborious task for marketers. Therefore, it is particularly important to develop a WeChat mass messaging tool. This article will introduce how to use PHP to develop WeChat mass messaging tools. 1. Preparation work To develop WeChat mass messaging tools, we need to master the following technical points: Basic knowledge of PHP WeChat public platform development Development tools: Sub

In the development of WeChat public accounts, user tag management is a very important function, which allows developers to better understand and manage their users. This article will introduce how to use PHP to implement the WeChat user tag management function. 1. Obtain the openid of the WeChat user. Before using the WeChat user tag management function, we first need to obtain the user's openid. In the development of WeChat public accounts, it is a common practice to obtain openid through user authorization. After the user authorization is completed, we can obtain the user through the following code

As WeChat becomes an increasingly important communication tool in people's lives, its agile messaging function is quickly favored by a large number of enterprises and individuals. For enterprises, developing WeChat into a marketing platform has become a trend, and the importance of WeChat development has gradually become more prominent. Among them, the group sending function is even more widely used. So, as a PHP programmer, how to implement group message sending records? The following will give you a brief introduction. 1. Understand the development knowledge related to WeChat public accounts. Before understanding how to implement group message sending records, I

WeChat is currently one of the social platforms with the largest user base in the world. With the popularity of mobile Internet, more and more companies are beginning to realize the importance of WeChat marketing. When conducting WeChat marketing, customer service is a crucial part. In order to better manage the customer service chat window, we can use PHP language for WeChat development. 1. Introduction to PHP WeChat development PHP is an open source server-side scripting language that is widely used in the field of Web development. Combined with the development interface provided by WeChat public platform, we can use PHP language to conduct WeChat

In the development of WeChat public accounts, the voting function is often used. The voting function is a great way for users to quickly participate in interactions, and it is also an important tool for holding events and surveying opinions. This article will introduce you how to use PHP to implement WeChat voting function. Obtain the authorization of the WeChat official account. First, you need to obtain the authorization of the WeChat official account. On the WeChat public platform, you need to configure the API address of the WeChat public account, the official account, and the token corresponding to the public account. In the process of our development using PHP language, we need to use the PH officially provided by WeChat

With the development of the Internet and mobile smart devices, WeChat has become an indispensable part of the social and marketing fields. In this increasingly digital era, how to use PHP for WeChat development has become the focus of many developers. This article mainly introduces the relevant knowledge points on how to use PHP for WeChat development, as well as some of the tips and precautions. 1. Development environment preparation Before developing WeChat, you first need to prepare the corresponding development environment. Specifically, you need to install the PHP operating environment and the WeChat public platform

With the popularity of mobile Internet, more and more people are using WeChat as a social software, and the WeChat open platform has also brought many opportunities to developers. In recent years, with the development of artificial intelligence technology, speech recognition technology has gradually become one of the popular technologies in mobile terminal development. In WeChat development, how to implement speech recognition has become a concern for many developers. This article will introduce how to use PHP to develop WeChat applications to implement speech recognition functions. 1. Principles of Speech Recognition Before introducing how to implement speech recognition, let us first understand the language
