Welcome to leave a message and forward
This article will specifically talk about WeChat card payment
Scene introduction
The difference is that the payment results are distributed once more .
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:html;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
<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>
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>
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!