android 微信支付,body為中文字元,簽名錯誤
阿新 • • 發佈:2018-11-09
微信支付訂單生產方法:
/** * 根據您的訂單資訊 生成 微信產品支付訂單資訊 */ private String createWeChatOrder() { StringBuffer xml = new StringBuffer(); try { String nonceStr = genNonceStr(); xml.append("</xml>"); List<KeyValue> packageParams = new LinkedList<KeyValue>(); packageParams.add(new KeyValue("appid", APP_ID)); packageParams.add(new KeyValue("attach", orderType)); packageParams.add(new KeyValue("body", "天鑫計費-網咖充值")); packageParams.add(new KeyValue("mch_id", MCH_ID)); packageParams.add(new KeyValue("nonce_str", nonceStr)); packageParams.add(new KeyValue("notify_url", callBackUrl)); packageParams.add(new KeyValue("out_trade_no", orderOn)); packageParams.add(new KeyValue("spbill_create_ip", "127.0.0.1")); packageParams.add(new KeyValue("total_fee", getTotalFee(price))); // packageParams.add(new KeyValue("total_fee", price)); packageParams.add(new KeyValue("trade_type", "APP")); String sign = genPackageSign(packageParams); packageParams.add(new KeyValue("sign", sign)); String xmlstring = toXml(packageParams); return xmlstring; // return new String(xmlstring.toString().getBytes(), "ISO8859-1"); // return xmlstring; } catch (Exception e) { return null; } }
使用中文body報錯:簽名錯誤解決方法:
直接返回xmlstring即可。不需要新增字元格式“ISO8859-1”