java微信支付

weixin_40649938 2018-01-17 04:19:46
统一下单获取完prepay_id怎么把prepay_id在xml里面解析出来 来生成paysign
...全文
611 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
无视悲画扇 2018-01-27
  • 打赏
  • 举报
回复
/** * 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; }
无视悲画扇 2018-01-27
  • 打赏
  • 举报
回复
/** * 获取支付信息 * @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; }
qq_40881558 2018-01-26
  • 打赏
  • 举报
回复
https://edu.csdn.net/course/detail/4604/82573?auto_start=2 教程
无瑕之心 2018-01-17
  • 打赏
  • 举报
回复
官方的文档有说明

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧