


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()<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>
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
<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>If you pay by card more than 5 times, you will be prompted to enter the password Return The
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:
<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>Usage scenario description
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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft