1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| @Service public class WeiXinServiceImpl implements WeiXinService { @Autowired private PaymentInfoService paymentInfoService; @Autowired private OrderInfoService orderInfoService; @Autowired private WeiXinService weiXinService; @Override public Map createNative(Long orderId) { OrderInfo orderInfo = orderInfoService.getById(orderId); if (orderInfo == null){ throw new OrderException(20001,"订单不存在"); } paymentInfoService.savePaymentInfo(orderInfo,PaymentTypeEnum.WEIXIN.getStatus()); try { Map paramMap = new HashMap(); paramMap.put("appid", ConstantPropertiesUtils.APPID); paramMap.put("mch_id", ConstantPropertiesUtils.PARTNER); paramMap.put("nonce_str", WXPayUtil.generateNonceStr()); Date reserveDate = orderInfo.getReserveDate(); String reserveDateString = new DateTime(reserveDate).toString("yyyy/MM/dd"); String body = reserveDateString + "就诊"+ orderInfo.getDepname(); paramMap.put("body", body); paramMap.put("out_trade_no", orderInfo.getOutTradeNo()); paramMap.put("total_fee", "1"); paramMap.put("spbill_create_ip", "127.0.0.1"); paramMap.put("notify_url", "http://xxxxxxxxx"); paramMap.put("trade_type", "NATIVE"); HttpClient client = new HttpClient("https://api.mch.weixin.qq.com/pay/unifiedorder"); String xml = WXPayUtil.generateSignedXml(paramMap, ConstantPropertiesUtils.PARTNERKEY); client.setXmlParam(xml); client.setHttps(true); client.post(); String resultXml = client.getContent(); System.out.println("微信二维码:"+resultXml); Map<String, String> resultMap = WXPayUtil.xmlToMap(resultXml); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("totalFee", orderInfo.getAmount()); map.put("resultCode", resultMap.get("result_code")); map.put("codeUrl", resultMap.get("code_url")); return map; } catch (Exception e) { e.printStackTrace(); throw new orderException(20001,"生成二维码失败"); } } }
|