微信小程序支付正常。
private Map<String, String> unifiedorder(Order order) {
// 获取用户openId
// 根据订单支付类型来判断获取公众号openId还是小程序openId
UserToken userToken = new UserToken();
userToken.setToken("");
if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_PUBLIC)) {// 公众号
userToken = userTokenService.getTokenByUserId(order.getUid(), UserConstants.USER_TOKEN_TYPE_WECHAT);
}
if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_MINI)
|| order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_MINI_VIDEO)) {// 小程序
userToken = userTokenService.getTokenByUserId(order.getUid(), UserConstants.USER_TOKEN_TYPE_ROUTINE);
}
// 获取appid、mch_id、微信签名key
String appId = "";
String mchId = "";
String signKey = "";
switch (order.getPayChannel()) {
case PayConstants.PAY_CHANNEL_WECHAT_PUBLIC:
case PayConstants.PAY_CHANNEL_H5:// H5使用公众号的信息
case PayConstants.PAY_CHANNEL_WECHAT_NATIVE:// H5使用公众号的信息
appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PUBLIC_APPID);
mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_MCHID);
signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_KEY);
break;
case PayConstants.PAY_CHANNEL_WECHAT_MINI:
case PayConstants.PAY_CHANNEL_WECHAT_MINI_VIDEO:
appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_MINI_APPID);
mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_MCHID);
signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_KEY);
break;
case PayConstants.PAY_CHANNEL_WECHAT_APP_IOS:
case PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID:
appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_APP_APPID);
mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_MCHID);
signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_KEY);
break;
}
// 获取微信预下单对象
CreateOrderRequestVo unifiedorderVo = getUnifiedorderVo(order, userToken.getToken(), appId, mchId, signKey);
// 预下单(统一下单)
CreateOrderResponseVo responseVo = wechatService.payUnifiedorder(unifiedorderVo);
// 组装前端预下单参数
Map<String, String> map = new HashMap<>();
map.put("appId", unifiedorderVo.getAppid());
map.put("nonceStr", unifiedorderVo.getAppid());
map.put("package", "prepay_id=".concat(responseVo.getPrepayId()));
map.put("signType", unifiedorderVo.getSign_type());
Long currentTimestamp = WxPayUtil.getCurrentTimestamp();
map.put("timeStamp", Long.toString(currentTimestamp));
String paySign = WxPayUtil.getSign(map, signKey);
map.put("paySign", paySign);
map.put("prepayId", responseVo.getPrepayId());
map.put("prepayTime", CrmebDateUtil.nowDateTimeStr());
map.put("outTradeNo", unifiedorderVo.getOut_trade_no());
if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_H5)) {
map.put("mweb_url", responseVo.getMWebUrl());
}
if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_APP_IOS) ||
order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID)) {// App
map.put("partnerid", mchId);
map.put("package", responseVo.getPrepayId());
Map<String, Object> appMap = new HashMap<>();
appMap.put("appid", unifiedorderVo.getAppid());
appMap.put("partnerid", mchId);
appMap.put("prepayid", responseVo.getPrepayId());
appMap.put("package", "Sign=WXPay");
appMap.put("noncestr", unifiedorderVo.getAppid());
appMap.put("timestamp", currentTimestamp);
logger.info("================================================app支付签名,map = " + appMap);
String sign = WxPayUtil.getSignObject(appMap, signKey);
logger.info("================================================app支付签名,sign = " + sign);
map.put("paySign", sign);
}
if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_NATIVE)) {
map.put("code_url", responseVo.getCodeUrl());
}
return map;
}