国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
微信掃碼支付(模式一)

微信掃碼支付模式

Apr 04, 2017 am 11:30 AM

微信掃碼支付(模式一)


微信掃碼支付遇到的問(wèn)題

  • 原生支付URL參數(shù)錯(cuò)誤

  • 回調(diào)接口URL有回調(diào),但是接收不到參數(shù)

  • 商戶后臺(tái)返回的數(shù)據(jù)字段結(jié)構(gòu)不合法

  • 獲取商戶訂單信息超時(shí)或者商戶返回的httpcode非200

解決問(wèn)題

  • 原生支付URL參數(shù)錯(cuò)誤
    這個(gè)錯(cuò)誤一般會(huì)出現(xiàn)在獲取到二維碼URL之后生成二維碼微信掃碼的時(shí)候。如果你出現(xiàn)此類型的問(wèn)題請(qǐng)檢查

1、生成二維碼所需參數(shù)列表中參數(shù)是否有錯(cuò)誤(區(qū)分大小寫(xiě))
2、參數(shù)中簽名sign時(shí)候正確 簽名算法 ? 簽名校驗(yàn)工具


以下是生成二維碼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 ?en=getParaNames();

    ??while?(en.hasMoreElements())?{
    ??????Object?o=?en.nextElement();
    ??????System.out.println(o.toString()+"="+getPara(o.toString()));
    ??}

以上代碼中輸出的參數(shù)都為NULL

由于官方的文檔描述不是很清楚,大家都以為回調(diào)請(qǐng)求將帶productid和用戶的openid等參數(shù)是以普通的參數(shù)一樣,其實(shí)這個(gè)回調(diào)返回的參數(shù)是一個(gè)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é)果為









<![CDATA[wx201605151311568e801d50fb0555050106]]></prepay_id><br><trade_type><![CDATA[NATIVE]]></trade_type><br><code_url>![CDATA[weixin://wxpay/bizpayurl?pr=Gj3ZF2b]]</code_url><br></xml></p> <p>如果返回的 return_code ?result_code 不為SUCCESS 而回調(diào)的接口沒(méi)有返回任何數(shù)據(jù)或者返回的數(shù)據(jù)不合法就會(huì)出現(xiàn)以下錯(cuò)誤</p> <ul class=" list-paddingleft-2"> <li><p>商戶后臺(tái)返回的數(shù)據(jù)字段結(jié)構(gòu)不合法(返回的數(shù)據(jù)包格式不正確)</p></li> <li><p>獲取商戶訂單信息超時(shí)或者商戶返回的httpcode非200(沒(méi)有返回的數(shù)據(jù)包)</p></li> </ul> <p>如果以上都沒(méi)有問(wèn)題,就剩下最后一個(gè)步驟了 ?商戶后臺(tái)系統(tǒng)將prepay_id返回給微信支付系統(tǒng) ?以下是詳細(xì)的代碼</p> <pre class="brush:php;toolbar:false">/** ?*?@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)容中各個(gè)參數(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",?"測(cè)試掃碼支付");
????????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的時(shí)候有返回
????????????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時(shí),添加該鍵值對(duì),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();
????}

}


以上是微信掃碼支付模式的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)代碼編輯軟件(SublimeText3)

熱門(mén)話題

Laravel 教程
1601
29
PHP教程
1502
276