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

零下一度
Release: 2017-05-19 16:02:46
Original
2830 people have browsed it

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:html;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:

<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:

<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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template