微信支付开发遇到常见问题
public Map<String, String> getPrepayOrder(String body, String outTradeNo, String totalFee, String spbillCreateIp) {
Map<String, String> paramMap = new HashMap<>();
paramMap.put("appid", APP_ID);
paramMap.put("mch_id", MCH_ID);
paramMap.put("nonce_str", WXPayUtil.generateNonceStr());
paramMap.put("body", body);
paramMap.put("out_trade_no", outTradeNo);
paramMap.put("total_fee", totalFee);
paramMap.put("spbill_create_ip", spbillCreateIp);
paramMap.put("notify_url", NOTIFY_URL);
paramMap.put("trade_type", "JSAPI");
paramMap.put("openid", openid);
paramMap.put("sign", WXPayUtil.generateSignature(paramMap, API_KEY));
try {
String xmlData = WXPayUtil.mapToXml(paramMap);
String responseData = restTemplate.postForObject(PREPAY_ORDER_URL, xmlData, String.class);
return WXPayUtil.xmlToMap(responseData);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}