/** * @param orderCode 订单号 * @param openId * @param totalFee 需要支付的金额,元为单位 */ private WechatPaymentParam(String memberPin, String orderCode, String openId, String totalFee) { this.appId = WechatPropertiesUtils.getWechatAppid(); this.inquiryNo = orderCode; this.openId = openId; this.bodyDesc = "惠易保"; try { this.notifyUrl = URLEncoder.encode(WechatPropertiesUtils.getWechatServer() + "notify/wechat", "UTF-8"); this.resultUrl = URLEncoder.encode(WechatPropertiesUtils.getWechatServer() + "notify/page", "UTF-8"); String path = WechatPropertiesUtils.getWechatServer() + "notify/fail?memberPin=" + memberPin + "&orderCode=" + orderCode + "&openid=" + openId + "&reason="; this.prePayResultUrl = URLEncoder.encode(path, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); } this.totalFee = totalFee; }
// 区 public RestResultDTO getAreaList(String cityCode) { String callMethod = WechatPropertiesUtils.getRestAreas(); String url = WechatPropertiesUtils.getRestServer() + callMethod; try { Map<String, String> params = SignUtil.buildRestCallParams(callMethod); params.put("cityCode", cityCode); String body = client.post(url, params); return JSON.parseObject(body, RestResultDTO.class); } catch (Exception e) { log.error(e.getMessage(), e); } return new RestResultDTO(StatusCode.INTERNAL_SERVER_ERROR); }
/** * 构建微信支付的请求地址 * * @param memberPin * @param orderCode * @param openId * @param totalFee * @return */ public static String buildWechatPaymentUrl( String memberPin, String orderCode, String openId, String totalFee, WechatRedisService redis) { // todo 设置支付金额为1分,正式发布需要修改 totalFee = "0.01"; WechatPaymentParam param = new WechatPaymentParam(memberPin, orderCode, openId, totalFee); String href = WechatPropertiesUtils.getWechatPay() + "?jsonStr=" + JSON.toJSONString(param); if (redis != null) { log.info("--- put key into redis :" + orderCode); redis.put("PAYMENT_" + orderCode, href, 600); } return href; }