這篇文章將為大家詳細(xì)講解有關(guān)微信掃碼支付遇到的問題有哪些,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的修武網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
微信掃碼支付遇到的問題
原生支付URL參數(shù)錯誤
回調(diào)接口URL有回調(diào),但是接收不到參數(shù)
商戶后臺返回的數(shù)據(jù)字段結(jié)構(gòu)不合法
獲取商戶訂單信息超時或者商戶返回的httpcode非200
解決問題
原生支付URL參數(shù)錯誤
這個錯誤一般會出現(xiàn)在獲取到二維碼URL之后生成二維碼微信掃碼的時候。如果你出現(xiàn)此類型的問題請檢查
1、生成二維碼所需參數(shù)列表中參數(shù)是否有錯誤(區(qū)分大小寫)
2、參數(shù)中簽名sign時候正確 簽名算法 簽名校驗工具
以下是生成二維碼URL的代碼
/** * * @author Javen * 2016年5月14日 * 掃碼支付獲取二維碼URL(模式一) */ 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<String, String> packageParams = new HashMap<String, String>(); 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); }
回調(diào)接口URL有回調(diào),但是接收不到參數(shù)
Enumeration<String> en=getParaNames();
while (en.hasMoreElements()) { Object o= en.nextElement(); System.out.println(o.toString()+"="+getPara(o.toString())); }
以上代碼中輸出的參數(shù)都為NULL
由于官方的文檔描述不是很清楚,大家都以為回調(diào)請求將帶productid和用戶的openid等參數(shù)是以普通的參數(shù)一樣,其實這個回調(diào)返回的參數(shù)是一個XML輸入流
HttpServletRequest request = getRequest(); /** * 獲取用戶掃描二維碼后,微信返回的信息 */ 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");
result結(jié)果為
<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
<appid><![CDATA[wx5e9360a3f46f64cd]]></appid>
<mch_id><![CDATA[1322117501]]></mch_id>
<nonce_str><![CDATA[lr3cCuO2KxMEBHIW]]></nonce_str>
<sign><![CDATA[842C1857EDD009D67519527BCF3AFA4C]]></sign>
<result_code><![CDATA[SUCCESS]]></result_code>
<prepay_id><![CDATA[wx201605151311568e801d50fb0555050106]]></prepay_id>
<trade_type><![CDATA[NATIVE]]></trade_type>
<code_url>![CDATA[weixin://wxpay/bizpayurl?pr=Gj3ZF2b]]</code_url>
</xml>
如果返回的 return_code result_code 不為SUCCESS 而回調(diào)的接口沒有返回任何數(shù)據(jù)或者返回的數(shù)據(jù)不合法就會出現(xiàn)以下錯誤
商戶后臺返回的數(shù)據(jù)字段結(jié)構(gòu)不合法(返回的數(shù)據(jù)包格式不正確)
獲取商戶訂單信息超時或者商戶返回的httpcode非200(沒有返回的數(shù)據(jù)包)
如果以上都沒有問題,就剩下最后一個步驟了 商戶后臺系統(tǒng)將prepay_id返回給微信支付系統(tǒng) 以下是詳細(xì)的代碼
/** * @author Javen * 2016年5月14日 * 掃碼支付回調(diào)(模式一) */
public void wxpay(){
try {
HttpServletRequest request = getRequest();
/**
* 獲取用戶掃描二維碼后,微信返回的信息 */ 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); /** * 獲取返回的信息內(nèi)容中各個參數(shù)的值 */ Map<String, String> 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<String, String> packageParams = new HashMap<String, String>(); 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); // 統(tǒng)一下單文檔地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1 Map<String, String> params = new HashMap<String, String>(); params.put("appid", appid); params.put("mch_id", mch_id); params.put("body", "測試掃碼支付"); 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); /** * 發(fā)送信息給微信服務(wù)器 */ Map<String, String> 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")) { // 以下字段在return_code 和result_code都為SUCCESS的時候有返回 String prepay_id = payResult.get("prepay_id"); Map<String, String> prepayParams = new HashMap<String, String>(); 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", "訂單失效"); //result_code為FAIL時,添加該鍵值對,value值是微信告訴客戶的信息 } 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(); } }
關(guān)于“微信掃碼支付遇到的問題有哪些”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
網(wǎng)站標(biāo)題:微信掃碼支付遇到的問題有哪些
網(wǎng)頁鏈接:http://muchs.cn/article2/jpepoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、網(wǎng)站改版、網(wǎng)站收錄、網(wǎng)站排名、網(wǎng)站策劃、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)