运营端充值

This commit is contained in:
张松 2025-10-27 13:43:26 +08:00
parent 423b6f303f
commit 7bb6198798
9 changed files with 109 additions and 17 deletions

View File

@ -47,6 +47,19 @@ public class DistributionPayController {
payParam.setShopId(shopId);
return payService.ltPayOrder(ServletUtil.getClientIP(request), payParam);
}
/**
* 运营端小程序支付
* payType 必填 支付方式aliPay 支付宝wechatPay 微信
* openId 必填
*/
@PostMapping("/mchRecharge")
@Debounce(value = "#payParam.userId")
public CzgResult<Map<String, String>> mchRecharge(@RequestHeader Long shopId, HttpServletRequest request, @Validated @RequestBody MkDistributionPayDTO payParam) {
payParam.setShopId(shopId);
return CzgResult.success(payService.mchRecharge(ServletUtil.getClientIP(request), payParam));
}
//
// /**
// * 正扫

View File

@ -1,6 +1,7 @@
package com.czg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson2.JSONObject;
@ -9,12 +10,17 @@ import com.czg.entity.CzgBaseRespParams;
import com.czg.mq.PrintMqListener;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.ShopTableOrderStatisticService;
import com.czg.service.Impl.WxServiceImpl;
import com.czg.system.service.WxService;
import com.czg.task.StatisticTask;
import com.czg.utils.AssertUtil;
import com.ijpay.core.kit.AesUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
@ -38,15 +44,17 @@ public class NotifyController {
@Resource
private ShopTableOrderStatisticService shopTableOrderStatisticService;
@Resource
private WxService wxService;
@GetMapping("testOpen")
public Map<String, String> test1(String code) throws Exception {
// return WxService.v3Pay("oeQYq5LzW-kSxJL9TR4s_UmOmNLE", new BigDecimal("0.01"), "测试", "testZs" + RandomUtil.randomNumbers(20), "test");
return null;
return wxService.v3Pay("oeQYq5LzW-kSxJL9TR4s_UmOmNLE", new BigDecimal("0.01"), "测试", "testZs" + RandomUtil.randomNumbers(20), "test");
}
@RequestMapping("/payCallBack")
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams) {
JSONObject czg = CzgPayUtils.getCzg(respParams);
@ -56,6 +64,35 @@ public class NotifyController {
return SUCCESS;
}
@RequestMapping("/wx/pay/distributionRecharge")
public String nativeNotify(HttpServletRequest request) throws IOException {
String timestamp = request.getHeader("Wechatpay-Timestamp");
String nonce = request.getHeader("Wechatpay-Nonce");
String serialNo = request.getHeader("Wechatpay-Serial");
String signature = request.getHeader("Wechatpay-Signature");
String result = IoUtil.readUtf8(request.getInputStream());
JSONObject jsonObject = JSONObject.parseObject(result);
JSONObject resource = jsonObject.getJSONObject("resource");
String associatedData = resource.getString("associated_data");
String ciphertext = resource.getString("ciphertext");
String nonceStr = resource.getString("nonce");
String plainText = wxService.decryptToString(associatedData, nonceStr, ciphertext);
log.info("支付通知明文 {}", plainText);
JSONObject plainTextJson = JSONObject.parseObject(plainText);
String outTradeNo = plainTextJson.getString("out_trade_no");
String tradeState = plainTextJson.getString("trade_state");
String transactionId = plainTextJson.getString("transaction_id");
if ("SUCCESS" == tradeState) {
}
return "SUCCESS";
}
@RequestMapping("/refundCallBack")
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
JSONObject czg = CzgPayUtils.getCzg(respParams);

View File

@ -31,6 +31,17 @@ public class ShopInfo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 微信openId
*/
private String wechatOpenId;
/**
* 支付宝 openid
*/
private String alipayOpenId;
/**
* 使用系统用户 sys_user id
*/

View File

@ -8,9 +8,13 @@ import java.util.Map;
* @author Administrator
*/
public interface WxService {
String getPhone(String code);
String getOpenId(String code);
Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type);
String decryptToString(String associatedData, String nonceStr, String ciphertext);
}

View File

@ -28,7 +28,7 @@ public interface TableValueConstant {
interface DistributionConfig {
@Getter
enum OpenType {
PAY("PAY", "支付购买"),
PAY("pay", "支付购买"),
COST("COST", "消费增积分");
private final String code;
private final String msg;

View File

@ -34,7 +34,7 @@ public class Main {
// String packageName = "product";
String packageName = "market";
// tableName 指定需要生成的表
String tableName = "mk_product_smart_suggest";
String tableName = "mk_distribution_amount_flow";
String author = "ww";
//是否生成DTO实体 默认生成
boolean isGenerateDto = true;

View File

@ -34,5 +34,6 @@ public interface DistributionPayService {
CzgResult<Map<String, Object>> microPayOrder(MkDistributionPayDTO payParam);
Map<String, String> mchRecharge(String clientIP, MkDistributionPayDTO payParam);
}

View File

@ -1,6 +1,7 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.util.IdUtil;
import com.czg.account.entity.ShopInfo;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.UserInfo;
import com.czg.account.service.ShopInfoService;
@ -12,13 +13,10 @@ import com.czg.exception.CzgException;
import com.czg.market.service.MkDistributionConfigService;
import com.czg.market.vo.MkDistributionConfigVO;
import com.czg.order.dto.MkDistributionPayDTO;
import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PayEnums;
import com.czg.order.service.OrderPaymentService;
import com.czg.resp.CzgResult;
import com.czg.service.order.service.DistributionPayService;
import com.czg.service.order.service.PayService;
import com.czg.system.service.WxService;
import com.czg.utils.AssertUtil;
import jakarta.annotation.Resource;
@ -63,21 +61,28 @@ public class DistributionPayServiceImpl implements DistributionPayService {
private String openId;
}
private InitInfo initPayment(Long userId, MkDistributionPayDTO payParam) {
private InitInfo initPayment(Long userId, MkDistributionPayDTO payParam, boolean isRecharge) {
MkDistributionConfigVO detail = configService.detail(payParam.getShopId());
AssertUtil.isTrue(detail.getIsEnable() != 1, "分销未开启");
if (!TableValueConstant.DistributionConfig.OpenType.PAY.getCode().equals(detail.getOpenType())) {
if (!isRecharge && !TableValueConstant.DistributionConfig.OpenType.PAY.getCode().equals(detail.getOpenType())) {
throw new CzgException("当前未开启购买分销配置");
}
OrderPayment orderPayment = new OrderPayment().setShopId(payParam.getShopId()).setSourceId(userId)
.setPayType("distribution").setOrderNo(payParam.getPlatformType() + IdUtil.getSnowflakeNextId()).setAmount(detail.getPayAmount());
.setPayType(isRecharge ? "distributionRecharge" : "distribution").setOrderNo(payParam.getPlatformType() + IdUtil.getSnowflakeNextId()).setAmount(detail.getPayAmount());
orderPaymentService.save(orderPayment);
ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId);
UserInfo userInfo = userInfoService.getById(userId);
return new InitInfo().setConfig(detail).setPayment(orderPayment).setShopUser(shopUserInfo)
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
InitInfo initInfo = new InitInfo().setConfig(detail);
if (isRecharge) {
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
initInfo.setOpenId(shopInfo.getWechatOpenId());
} else {
ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId);
UserInfo userInfo = userInfoService.getById(userId);
initInfo.setPayment(orderPayment).setShopUser(shopUserInfo)
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
}
return initInfo;
}
@Override
@ -87,11 +92,17 @@ public class DistributionPayServiceImpl implements DistributionPayService {
@Override
public CzgResult<Map<String, Object>> ltPayOrder(String clintIp, MkDistributionPayDTO payParam) {
InitInfo initInfo = initPayment(payParam.getUserId(), payParam);
InitInfo initInfo = initPayment(payParam.getUserId(), payParam, false);
return payService.ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(initInfo.payment.getOrderNo(), initInfo.payment.getAmount().multiply(MONEY_RATE).longValue(),
payParam.getPayType(), "分销员开通", initInfo.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
}
@Override
public Map<String, String> mchRecharge(String clientIP, MkDistributionPayDTO payParam) {
InitInfo initInfo = initPayment(payParam.getUserId(), payParam, true);
return wxService.v3Pay(initInfo.openId, payParam.getAmount(), "商户运营余额充值", initInfo.payment.getOrderNo(), initInfo.payment.getPayType());
}
@Override
public CzgResult<Map<String, Object>> scanPayOrder(String clintIp, MkDistributionPayDTO payParam) {
return null;

View File

@ -34,6 +34,7 @@ import java.io.ByteArrayInputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Base64;
@ -101,7 +102,7 @@ public class WxServiceImpl implements WxService {
private static String platformCertPath;
private static String platformCertNo;
private static String mchId;
private static String apiV3Key;
public static String apiV3Key;
private static String apiV2Key;
private static String notifyUrl;
private static String refundNotifyUrl;
@ -322,6 +323,20 @@ public class WxServiceImpl implements WxService {
log.info(publicKey);
}
@Override
public String decryptToString(String associatedData, String nonceStr, String ciphertext) {
AesUtil aesUtil = new AesUtil(apiV3Key.getBytes(StandardCharsets.UTF_8));
try {
return aesUtil.decryptToString(
associatedData.getBytes(StandardCharsets.UTF_8),
nonceStr.getBytes(StandardCharsets.UTF_8),
ciphertext
);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}
}
@Override
public Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type) {
if (desc == null) desc = "订单支付";
@ -338,7 +353,7 @@ public class WxServiceImpl implements WxService {
String payInfo = JSONObject.toJSONString(model);
log.info("统一下单参数: {}", payInfo);
IJPayHttpResponse resp = null;
IJPayHttpResponse resp;
try {
resp = WxPayApi.v3(
RequestMethodEnum.POST,