Home WeChat Applet WeChat Development Share an example tutorial on developing WeChat public account for credit card payment

Share an example tutorial on developing WeChat public account for credit card payment

May 19, 2017 pm 04:02 PM

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

Merchant side process


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 .

According to whether the user needs to enter the payment password, it can be divided into: password-free mode and password verification mode.

Payment verification password rules

  • 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 later

Let’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.

The following is the specific implementation code:

micropay()
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>public void micropay(){ String url=&quot;https://api.mch.weixin.qq.com/pay/micropay&quot;; String total_fee=&quot;1&quot;; //授权码 String auth_code = getPara(&quot;auth_code&quot;); Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;(); params.put(&quot;appid&quot;, appid); params.put(&quot;mch_id&quot;, partner); params.put(&quot;device_info&quot;, &quot;javen205&quot;);//终端设备号 params.put(&quot;nonce_str&quot;, System.currentTimeMillis() / 1000 + &quot;&quot;); params.put(&quot;body&quot;, &quot;刷卡支付测试&quot;); // params.put(&quot;detail&quot;, &quot;json字符串&quot;);//非必须 params.put(&quot;attach&quot;, &quot;javen205&quot;);//附加参数非必须 String out_trade_no=System.currentTimeMillis()+&quot;&quot;; params.put(&quot;out_trade_no&quot;, out_trade_no); params.put(&quot;total_fee&quot;, total_fee); String ip = IpKit.getRealIp(getRequest()); if (StrKit.isBlank(ip)) { ip = &quot;127.0.0.1&quot;; } params.put(&quot;spbill_create_ip&quot;, ip); params.put(&quot;auth_code&quot;, auth_code); String sign = PaymentKit.createSign(params, paternerKey); params.put(&quot;sign&quot;, sign); String xmlResult = HttpUtils.post(url, PaymentKit.toXml(params)); //同步返回结果 System.out.println(&quot;xmlResult:&quot;+xmlResult); Map&lt;String, String&gt; result = PaymentKit.xmlToMap(xmlResult); String return_code = result.get(&quot;return_code&quot;); if (StrKit.isBlank(return_code) || !&quot;SUCCESS&quot;.equals(return_code)) { //通讯失败 String err_code = result.get(&quot;err_code&quot;); //用户支付中,需要输入密码 if (err_code.equals(&quot;USERPAYING&quot;)) { //等待5秒后调用【查询订单API】https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_2 } renderText(&quot;通讯失败&gt;&gt;&quot;+xmlResult); return; } String result_code = result.get(&quot;result_code&quot;); if (StrKit.isBlank(result_code) || !&quot;SUCCESS&quot;.equals(result_code)) { //支付失败 renderText(&quot;支付失败&gt;&gt;&quot;+xmlResult); return; } //支付成功 renderText(xmlResult); }</pre><div class="contentsignin">Copy after login</div></div> in com.javen.weixin.controller.WeixinPayController

is in open source The test access address in the project weixin-guide is

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

in the browser and the return result is as follows:

1

2

3

4

5

6

7

8

9

10

11

<xml><return_code><![CDATA[SUCCESS]]></return_code>

<return_msg><![CDATA[OK]]></return_msg>

<appid><![CDATA[您公众号的appid]]></appid>

<mch_id><![CDATA[您微信商户号]]></mch_id>

<device_info><![CDATA[javen205]]></device_info>

<nonce_str><![CDATA[eXgczazQq54pqcyH]]></nonce_str>

<sign><![CDATA[FF03DA0E58845CCE1FCC2166EC03FBE5]]></sign>

<result_code><![CDATA[FAIL]]></result_code>

<err_code><![CDATA[AUTH_CODE_INVALID]]></err_code>

<err_code_des><![CDATA[请扫描微信支付被扫条码/二维码]]></err_code_des>

</xml>

Copy after login

If you pay by card more than 5 times, you will be prompted to enter the password

Return The

err_code is USERPAYING

At this time, the payment result needs to be obtained through the query order interface

This is with password and without password The difference is that if you have a password, you must use

query order to obtain the payment result. If the result is still USERPAYING, the query will be called every 5 seconds loop The order API determines 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 API to cancel the payment transaction. .

Enter the correct

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

<xml><return_code><![CDATA[SUCCESS]]></return_code>

<return_msg><![CDATA[OK]]></return_msg>

<appid><![CDATA[您公众号的appid]]></appid>

<mch_id><![CDATA[您微信商户号]]></mch_id>

<device_info><![CDATA[javen205]]></device_info>

<nonce_str><![CDATA[Z9p14VPJ822ZTPXP]]></nonce_str>

<sign><![CDATA[03BD421A33A5079A1BE6030E2EBA8291]]></sign>

<result_code><![CDATA[SUCCESS]]></result_code>

<openid><![CDATA[o_pncsidC-pRRfCP4zj98h6slREw]]></openid>

<is_subscribe><![CDATA[Y]]></is_subscribe>

<trade_type><![CDATA[MICROPAY]]></trade_type>

<bank_type><![CDATA[CFT]]></bank_type>

<total_fee>1</total_fee>

<fee_type><![CDATA[CNY]]></fee_type>

<transaction_id><![CDATA[4009682001201610156761057959]]></transaction_id>

<out_trade_no><![CDATA[1476523316727]]></out_trade_no>

<attach><![CDATA[javen205]]></attach>

<time_end><![CDATA[20161015172058]]></time_end>

<cash_fee>1</cash_fee>

</xml>

Copy after login

Usage scenario description

If

Access mode Access the merchant backend If the payment is successful, the WeChat payment system will return the above xml data 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

If

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

Share an example tutorial on developing WeChat public account for credit card payment

Card payment.png

The coding is completed. The above is a detailed introduction to WeChat card payment.

【Related recommendations】

1.

WeChat public account platform source code download

2.

小 Pigcms (PigCms) micro-e-commerce System operation version (independent WeChat store + three-level distribution system)

3.

WeChat voting source code

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!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP WeChat development: How to implement message encryption and decryption PHP WeChat development: How to implement message encryption and decryption May 13, 2023 am 11:40 AM

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.

Using PHP to develop WeChat mass messaging tools Using PHP to develop WeChat mass messaging tools May 13, 2023 pm 05:00 PM

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

PHP WeChat development: How to implement user tag management PHP WeChat development: How to implement user tag management May 13, 2023 pm 04:31 PM

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

PHP WeChat development: How to implement group message sending records PHP WeChat development: How to implement group message sending records May 13, 2023 pm 04:31 PM

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

PHP WeChat development: How to implement customer service chat window management PHP WeChat development: How to implement customer service chat window management May 13, 2023 pm 05:51 PM

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

PHP WeChat development: How to implement voting function PHP WeChat development: How to implement voting function May 14, 2023 am 11:21 AM

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

How to use PHP for WeChat development? How to use PHP for WeChat development? May 21, 2023 am 08:37 AM

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

PHP WeChat development: How to implement speech recognition PHP WeChat development: How to implement speech recognition May 13, 2023 pm 09:31 PM

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

See all articles