diff --git a/luoo_user/src/main/java/com/luoo/user/controller/WxPayController.java b/luoo_user/src/main/java/com/luoo/user/controller/WxPayController.java index b7f628f..e03e678 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/WxPayController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/WxPayController.java @@ -1,5 +1,6 @@ package com.luoo.user.controller; +import api.Result; import cn.hutool.core.util.StrUtil; import cn.hutool.http.ContentType; import cn.hutool.json.JSONObject; @@ -15,6 +16,7 @@ import com.ijpay.wxpay.enums.WxDomainEnum; import com.ijpay.wxpay.enums.v3.BasePayApiEnum; import com.ijpay.wxpay.model.UnifiedOrderModel; import com.luoo.user.config.WxPayConfig; +import com.luoo.user.util.RedisUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; @@ -43,10 +45,13 @@ public class WxPayController { @Resource private WxPayConfig wxPayConfig; + @Resource + private RedisUtils redisUtils; + //支付 @RequestMapping("/app") @ResponseBody - public String jsApiPay() { + public Result jsApiPay() { try { String timeExpire = DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3); UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel() @@ -66,11 +71,12 @@ public class WxPayController { params.put("time_expire", timeExpire); params.put("notify_url", "https://www.baidu.com"); params.put("amount", new HashMap() {{ - put("total", 1); + put("total", 0.01); put("currency", "CNY"); }}); log.info("统一下单参数 {}", JSONUtil.toJsonStr(params)); + redisUtils.set(params.get("out_trade_no").toString(), params); IJPayHttpResponse response = WxPayApi.v3( RequestMethodEnum.POST, WxDomainEnum.CHINA.toString(), @@ -90,14 +96,15 @@ public class WxPayController { String body = response.getBody(); JSONObject jsonObject = JSONUtil.parseObj(body); String prepayId = jsonObject.getStr("prepay_id"); - Map map = WxPayKit.jsApiCreateSign(wxPayConfig.getAppId(), prepayId, wxPayConfig.getPrivateKeyPath()); + + Map map = WxPayKit.appCreateSign(wxPayConfig.getAppId(), wxPayConfig.getMchId(), prepayId, wxPayConfig.getPrivateKeyPath()); log.info("唤起支付参数:{}", map); - return JSONUtil.toJsonStr(map); + return Result.success(map); } - return JSONUtil.toJsonStr(response); + return Result.success(response); } catch (Exception e) { e.printStackTrace(); - return e.getMessage(); + return Result.failed(e.getMessage()); } } @@ -120,6 +127,7 @@ public class WxPayController { wxPayConfig.getApiV3Key(), wxPayConfig.getPlatformCertPath()); log.info("支付通知明文 {}", plainText); + redisUtils.set("payNotify" + DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis()), plainText); if (StrUtil.isNotEmpty(plainText)) { response.setStatus(200); @@ -139,5 +147,4 @@ public class WxPayController { } - }