release- 微信支付修改金额

release-2024-04-25
huangyw 2 months ago
parent a92790886a
commit 7ee8db5b07

@ -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<Object> 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<String, Object>() {{
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<String, String> map = WxPayKit.jsApiCreateSign(wxPayConfig.getAppId(), prepayId, wxPayConfig.getPrivateKeyPath());
Map<String, String> 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 {
}
}

Loading…
Cancel
Save