java微信支付 统一下单获取完prepay_id怎么把prepay_id在xml里面解析出来 来生成paysign 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 https://edu.csdn.net/course/detail/4604/82573?auto_start=2 教程 /** * 获取支付信息 * @param orderBody * @param money * @param out_trade_no * @param ip * @return */ private WxSubmitOrderExtended getPrePayOrder(String orderBody, BigDecimal money, String out_trade_no, String ip) { money = new BigDecimal(Math.round(Double.valueOf(df.format(money.multiply(ONE_HUNDRED))))); String nonceStr = UUID.randomUUID().toString().replace("-", ""); SortedMap<Object, Object> map = new TreeMap<Object, Object>(); map.put("appid", appid); map.put("body", orderBody); map.put("mch_id", mchid); map.put("nonce_str", nonceStr); map.put("notify_url", notifyUrl); map.put("out_trade_no", out_trade_no); map.put("spbill_create_ip", ip); map.put("total_fee", money + ""); map.put("trade_type", "APP"); String sign = WeiXinUtil.createSign("UTF-8", map, apikey); map.put("sign", sign); String xmlStr = WeiXinUtil.getRequestXml(map); log.info(xmlStr); String response = HttpClientUtil.httpsRequest(unifiedorderUrl, RequestMethod.POST, new String(xmlStr)); log.info(response); if (StringUtils.isBlank(response)) throw new RuntimeException(ResponseCode.SERVER_ERROR.getMessage()); Map result = XmlUtil.xml2mapResult(response); if (FAIL_CODE.equals(result.get(RETURN_CODE_KEY))) { log.error("请求微信失败:" + result.get(RETURN_MSG_KEY)); throw new OrderException(SERVER_ERROR_20060); } return getOrder(result.get("prepay_id"), result.get("nonce_str")); } /** * 执行第二次签名,才能返回给客户端使用 * @param prepayid * @param noncestr * @return */ public WxSubmitOrderExtended getOrder(Object prepayid, Object noncestr) { SortedMap<Object, Object> map = new TreeMap<Object, Object>(); String time = Long.toString(System.currentTimeMillis() / 1000); map.put("appid", appid); map.put("noncestr", noncestr); map.put("package", "Sign=WXPay"); map.put("partnerid", mchid); map.put("prepayid", prepayid); map.put("timestamp", time); String sign = WeiXinUtil.createSign("utf-8", map, apikey); WxSubmitOrderExtended wx = new WxSubmitOrderExtended() {{ setAppid(appid); setNonceStr((String) noncestr); setPackageStr("Sign=WXPay"); setPartnerid(mchid); setPrepayid(prepayid); setTimestamp(time); setSign(sign); }}; log.info(JacksonUtil.toJSon(wx)); return wx; } /** * xml转map 不带属性 * * @param xmlStr * @param needRootKey 是否需要在返回的map里加根节点键 * @return * * @throws DocumentException */ public static Map xml2map(String xmlStr, boolean needRootKey) throws DocumentException { Document doc = DocumentHelper.parseText(xmlStr); Element root = doc.getRootElement(); Map<String, Object> map = (Map<String, Object>) xml2map(root); if (root.elements().size() == 0 && root.attributes().size() == 0) { return map; } if (needRootKey) { //在返回的map里加根节点键(如果需要) Map<String, Object> rootMap = new HashMap<String, Object>(); rootMap.put(root.getName(), map); return rootMap; } return map; } 获取weblogic中配置的jndi数据源,调用时出错 求助呀!关于Hibernate 一个读取xml问题!! oracle sql查询时间 一个Java简单题目 eclipse中cvs项目更新问题 高手帮帮我啊,eclipse下的问题!群9336474专门讨论java方面的知识!欢迎加入!! hibernate映射问题 在struts1.1中,<html:radio 的属性 idName怎么用啊. 〔初学讨论〕关于J2EE的入门 redis + spring sesson 共享 二级域名实现单点登录问题 事务提交的时候出现的大问题
* 获取支付信息
* @param orderBody
* @param money
* @param out_trade_no
* @param ip
* @return
*/
private WxSubmitOrderExtended getPrePayOrder(String orderBody, BigDecimal money, String out_trade_no, String ip) {
money = new BigDecimal(Math.round(Double.valueOf(df.format(money.multiply(ONE_HUNDRED)))));
String nonceStr = UUID.randomUUID().toString().replace("-", "");
SortedMap<Object, Object> map = new TreeMap<Object, Object>();
map.put("appid", appid);
map.put("body", orderBody);
map.put("mch_id", mchid);
map.put("nonce_str", nonceStr);
map.put("notify_url", notifyUrl);
map.put("out_trade_no", out_trade_no);
map.put("spbill_create_ip", ip);
map.put("total_fee", money + "");
map.put("trade_type", "APP");
String sign = WeiXinUtil.createSign("UTF-8", map, apikey);
map.put("sign", sign);
String xmlStr = WeiXinUtil.getRequestXml(map);
log.info(xmlStr);
String response = HttpClientUtil.httpsRequest(unifiedorderUrl, RequestMethod.POST, new String(xmlStr));
log.info(response);
if (StringUtils.isBlank(response))
throw new RuntimeException(ResponseCode.SERVER_ERROR.getMessage());
Map result = XmlUtil.xml2mapResult(response);
if (FAIL_CODE.equals(result.get(RETURN_CODE_KEY))) {
log.error("请求微信失败:" + result.get(RETURN_MSG_KEY));
throw new OrderException(SERVER_ERROR_20060);
}
return getOrder(result.get("prepay_id"), result.get("nonce_str")); } /**
* 执行第二次签名,才能返回给客户端使用
* @param prepayid
* @param noncestr
* @return
*/
public WxSubmitOrderExtended getOrder(Object prepayid, Object noncestr) {
SortedMap<Object, Object> map = new TreeMap<Object, Object>();
String time = Long.toString(System.currentTimeMillis() / 1000);
map.put("appid", appid);
map.put("noncestr", noncestr);
map.put("package", "Sign=WXPay");
map.put("partnerid", mchid);
map.put("prepayid", prepayid);
map.put("timestamp", time);
String sign = WeiXinUtil.createSign("utf-8", map, apikey);
WxSubmitOrderExtended wx = new WxSubmitOrderExtended() {{
setAppid(appid);
setNonceStr((String) noncestr);
setPackageStr("Sign=WXPay");
setPartnerid(mchid);
setPrepayid(prepayid);
setTimestamp(time);
setSign(sign);
}};
log.info(JacksonUtil.toJSon(wx));
return wx;
}
* xml转map 不带属性
*
* @param xmlStr
* @param needRootKey 是否需要在返回的map里加根节点键
* @return
*
* @throws DocumentException
*/
public static Map xml2map(String xmlStr, boolean needRootKey) throws DocumentException {
Document doc = DocumentHelper.parseText(xmlStr);
Element root = doc.getRootElement();
Map<String, Object> map = (Map<String, Object>) xml2map(root);
if (root.elements().size() == 0 && root.attributes().size() == 0) {
return map;
}
if (needRootKey) {
//在返回的map里加根节点键(如果需要)
Map<String, Object> rootMap = new HashMap<String, Object>();
rootMap.put(root.getName(), map);
return rootMap;
}
return map;
}