In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the problems encountered in Wechat code scanning payment. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Problems encountered in the payment of scanning code on Wechat
Error in native payment URL parameter
Callback API URL has a callback, but cannot receive parameters
The data field structure returned by the merchant backend is invalid.
The order information of the merchant timed out or the httpcode returned by the merchant is not 200.
Solve the problem
Error in native payment URL parameter
This error usually occurs when the QR code Wechat scan code is generated after obtaining the QR code URL. If you have this type of problem, please check
1. Whether there are any errors in the parameter list required to generate the QR code (case-sensitive)
2. Correct signature algorithm when signing sign in parameters signature verification tool
Here is the code to generate the QR code URL
/ * @ author Javen * May 14, 2016 * scan payment to get the QR code URL (mode 1) * / public String getCodeUrl () {String url= "weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXX&time_stamp=XXXXX&nonce_str=XXXXX"; String product_id= "001"; String timeStamp=Long.toString (System.currentTimeMillis () / 1000); String nonceStr=Long.toString (System.currentTimeMillis ()); Map packageParams = new HashMap () PackageParams.put ("appid", appid); packageParams.put ("mch_id", partner); packageParams.put ("product_id", product_id); packageParams.put ("time_stamp", timeStamp); packageParams.put ("nonce_str", nonceStr); String packageSign = PaymentKit.createSign (packageParams, paternerKey); return StringUtils.replace (url, "XXXXX", packageSign,appid,partner,product_id,timeStamp,nonceStr);}
Callback API URL has a callback, but cannot receive parameters
Enumeration en=getParaNames ()
While (en.hasMoreElements ()) {Object o = en.nextElement (); System.out.println (o.toString () + "=" + getPara (o.toString ());}
The output parameters in the above code are all NULL
As the official document description is not very clear, everyone thinks that the callback request will take parameters such as productid and user's openid as normal parameters, but in fact, the parameter returned by this callback is an XML input stream.
HttpServletRequest request = getRequest (); / * get the information returned by Wechat after scanning the QR code * / InputStream inStream = request.getInputStream (); ByteArrayOutputStream outSteam = new ByteArrayOutputStream (); byte [] buffer = new byte [1024]; int len = 0 While ((len = inStream.read (buffer))! =-1) {outSteam.write (buffer, 0, len);} outSteam.close (); inStream.close (); String result = new String (outSteam.toByteArray (), "utf-8")
The result of result is
! [CDATA[weixin: / / wxpay/bizpayurl?pr=Gj3ZF2b]]
If the returned return_code result_code is not callback for SUCCESS, the API that does not return any data or the returned data is illegal, the following error occurs
The data field structure returned by the merchant backend is invalid (the format of the returned data packet is incorrect)
Get the merchant order information timed out or the httpcode returned by the merchant is not 200 (no returned packet)
If there is no problem with all of the above, there is only one last step left. The merchant background system returns the prepay_id to WeChat Pay system. The following is the detailed code.
/ * * @ author Javen * May 14, 2016 * Code scan payment callback (mode 1) * /
Public void wxpay () {
Try {
HttpServletRequest request = getRequest ()
/ * *
* get the information returned by Wechat after scanning the QR code * / InputStream inStream = request.getInputStream (); ByteArrayOutputStream outSteam = new ByteArrayOutputStream (); byte [] buffer = new byte [1024]; int len = 0; while ((len = inStream.read (buffer))! =-1) {outSteam.write (buffer, 0, len);} outSteam.close () InStream.close (); String result = new String (outSteam.toByteArray (), "utf-8"); System.out.println ("callback >" + result); / * get the value of each parameter in the returned information content * / Map map = PaymentKit.xmlToMap (result) For (String key: map.keySet ()) {System.out.println ("key=" + key + "and value=" + map.get (key));} String appid=map.get ("appid"); String openid = map.get ("openid"); String mch_id = map.get ("mch_id"); String is_subscribe = map.get ("is_subscribe") String nonce_str = map.get ("nonce_str"); String product_id = map.get ("product_id"); String sign = map.get ("sign"); Map packageParams = new HashMap (); packageParams.put ("appid", appid); packageParams.put ("openid", openid); packageParams.put ("mch_id", mch_id) PackageParams.put ("is_subscribe", is_subscribe); packageParams.put ("nonce_str", nonce_str); packageParams.put ("product_id", product_id); String packageSign = PaymentKit.createSign (packageParams, paternerKey); / / Unified order document address: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1 Map params = new HashMap () Params.put ("appid", appid); params.put ("mch_id", mch_id); params.put ("body", "Test scan payment"); String out_trade_no=Long.toString (System.currentTimeMillis ()); params.put ("out_trade_no", out_trade_no); int price= ((int) (Float.valueOf (10) * 100)) Params.put ("total_fee", price+ "); params.put (" attach ", out_trade_no); String ip = IpKit.getRealIp (getRequest ()); if (StrKit.isBlank (ip)) {ip =" 127.0.0.1 ";} params.put (" spbill_create_ip ", ip) Params.put ("trade_type", TradeType.NATIVE.name ()); params.put ("nonce_str", System.currentTimeMillis () / 1000 + "); params.put (" notify_url ", notify_url); params.put (" openid ", openid); String paysign = PaymentKit.createSign (params, paternerKey); params.put (" sign ", paysign); String xmlResult = PaymentApi.pushOrder (params) System.out.println ("prepay_xml > >" + xmlResult); / * send messages to Wechat server * / Map payResult = PaymentKit.xmlToMap (xmlResult); String return_code = payResult.get ("return_code"); String result_code = payResult.get ("result_code") If (StrKit.notBlank (return_code) & & StrKit.notBlank (result_code) & & return_code.equalsIgnoreCase ("SUCCESS") & & result_code.equalsIgnoreCase ("SUCCESS")) {/ / the following fields return String prepay_id = payResult.get ("prepay_id") when both return_code and result_code are SUCCESS; Map prepayParams = new HashMap () PrepayParams.put ("return_code", "SUCCESS"); prepayParams.put ("appId", appid); prepayParams.put ("mch_id", mch_id); prepayParams.put ("nonceStr", System.currentTimeMillis () + "); prepayParams.put (" prepay_id ", prepay_id); String prepaySign = null If (sign.equals (packageSign)) {prepayParams.put ("result_code", "SUCCESS");} else {prepayParams.put ("result_code", "FAIL"); prepayParams.put ("err_code_des", "order invalidation") Add this key-value pair when result_code is FAIL. The value value is the information Wechat tells the customer} prepaySign = PaymentKit.createSign (prepayParams, paternerKey); prepayParams.put ("sign", prepaySign); String xml = PaymentKit.toXml (prepayParams); log.error (xml); renderText (xml) }} catch (UnsupportedEncodingException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} catch (IOException e) {/ / TODO Auto-generated catch block e.printStackTrace () }} this is the end of the article on "what are the problems encountered in Wechat code scanning payment". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.