fix: 商城支付微信返回jsapi

pull/2/head
tangqian 2023-05-26 14:37:52 +08:00
parent 540caf9cc1
commit 76c248f865
1 changed files with 21 additions and 17 deletions

View File

@ -245,25 +245,28 @@ public class OrderPayServiceImpl implements OrderPayService {
// 微信支付,调用微信预下单,返回拉起微信支付需要的信息
if (storeOrder.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) {
// 预下单
Map<String, String> unifiedorder = unifiedorder(storeOrder, ip, orderPayRequest.getOpenid());
WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = unifiedorder(storeOrder, ip, orderPayRequest.getOpenid());
WxPayService wxPayService = wxPayOneAutoConfiguration.wxPayOneService();
WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = wxPayUnifiedOrderV3Result.getPayInfo(TradeTypeEnum.JSAPI, payProperties.getAppId(), payProperties.getMchId(), wxPayService.getConfig().getPrivateKey());
response.setStatus(true);
WxPayJsResultVo vo = new WxPayJsResultVo();
vo.setAppId(unifiedorder.get("appId"));
vo.setNonceStr(unifiedorder.get("nonceStr"));
vo.setPackages(unifiedorder.get("package"));
vo.setSignType(unifiedorder.get("signType"));
vo.setTimeStamp(unifiedorder.get("timeStamp"));
vo.setPaySign(unifiedorder.get("paySign"));
vo.setAppId(/*unifiedorder.get("appId")*/jsapiResult.getAppId());
vo.setNonceStr(/*unifiedorder.get("nonceStr")*/jsapiResult.getNonceStr());
// vo.setPackages(unifiedorder.get("package"));
vo.setSignType(/*unifiedorder.get("signType")*/jsapiResult.getSignType());
vo.setTimeStamp(/*unifiedorder.get("timeStamp")*/jsapiResult.getTimeStamp());
vo.setPaySign(/*unifiedorder.get("paySign")*/jsapiResult.getPaySign());
if (storeOrder.getIsChannel() == 2) {
vo.setMwebUrl(unifiedorder.get("mweb_url"));
vo.setMwebUrl(wxPayUnifiedOrderV3Result.getH5Url());
response.setPayType(PayConstants.PAY_CHANNEL_WE_CHAT_H5);
}
if (storeOrder.getIsChannel() == 4 || storeOrder.getIsChannel() == 5) {
vo.setPartnerid(unifiedorder.get("partnerid"));
}
// if (storeOrder.getIsChannel() == 4 || storeOrder.getIsChannel() == 5) {
// vo.setPartnerid(unifiedorder.get("partnerid"));
// }
// 更新商户订单号
storeOrder.setOutTradeNo(unifiedorder.get("outTradeNo"));
storeOrderService.updateById(storeOrder);
// storeOrder.setOutTradeNo(unifiedorder.get("outTradeNo"));
// storeOrderService.updateById(storeOrder);
response.setJsConfig(vo);
return response;
}
@ -287,7 +290,7 @@ public class OrderPayServiceImpl implements OrderPayService {
* @param ip ip
* @return
*/
private Map<String, String> unifiedorder(StoreOrder storeOrder, String ip,String openid) {
private WxPayUnifiedOrderV3Result unifiedorder(StoreOrder storeOrder, String ip,String openid) {
// 获取用户openId
// 根据订单支付类型来判断获取公众号openId还是小程序openId
@ -316,7 +319,7 @@ public class OrderPayServiceImpl implements OrderPayService {
// 预下单(统一下单)
//CreateOrderResponseVo responseVo = wechatNewService.payUnifiedorder(unifiedorderVo);
// 组装前端预下单参数
Map<String, String> map = new HashMap<>();
// Map<String, String> map = new HashMap<>();
// map.put("appId", unifiedorderVo.getAppid());
// map.put("nonceStr", unifiedorderVo.getAppid());
// map.put("package", "prepay_id=".concat(responseVo.getPrepayId()));
@ -348,11 +351,12 @@ public class OrderPayServiceImpl implements OrderPayService {
wxPayRequest.setTimeExpire(formatLocalDateTime(LocalDateTime.now().plusMinutes(30), "yyyyMMddHHmmss"));
try {
WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = wxPayService.unifiedOrderV3(TradeTypeEnum.JSAPI, wxPayRequest);
map.put("mweb_url",wxPayUnifiedOrderV3Result.getH5Url());
// map.put("mweb_url",wxPayUnifiedOrderV3Result.getH5Url());
return wxPayUnifiedOrderV3Result;
} catch (Exception e) {
e.getMessage();
}
return map;
return null;
}
public static String formatLocalDateTime(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));