|
|
@@ -1,6 +1,10 @@
|
|
|
package com.kym.service.wechat.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.kym.common.config.WxPayConfig;
|
|
|
+import com.kym.common.constant.ResponseEnum;
|
|
|
+import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.utils.OrderUtils;
|
|
|
import com.kym.entity.miniapp.PayLog;
|
|
|
import com.kym.service.miniapp.PayLogService;
|
|
|
@@ -26,7 +30,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
|
/**
|
|
|
* @author skyline
|
|
|
@@ -78,13 +81,18 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
* JSAPI支付下单
|
|
|
*/
|
|
|
@Override
|
|
|
- public PrepayResponse prepay(BigDecimal rechargeAmount, String openid) {
|
|
|
+ public PrepayResponse prepay(JSONObject params) {
|
|
|
+ if (!params.containsKey("amount") || params.getInteger("amount") == null || !(params.get("amount") instanceof Integer)) {
|
|
|
+ throw new BusinessException(ResponseEnum.WX_PAY_AMOUNT_ERROR);
|
|
|
+ }
|
|
|
+ var rechargeAmount = params.getInteger("amount");
|
|
|
+ var openid = StpUtil.getSession().getString("openid");
|
|
|
// 生成订单号
|
|
|
String outTradeNo = OrderUtils.getOrderNo();
|
|
|
// request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
PrepayRequest request = new PrepayRequest();
|
|
|
Amount amount = new Amount();
|
|
|
- amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue());
|
|
|
+ amount.setTotal(rechargeAmount * 100);
|
|
|
request.setAmount(amount);
|
|
|
request.setAppid(conf.getAppid());
|
|
|
request.setMchid(conf.getMchid());
|