运营端充值
This commit is contained in:
parent
423b6f303f
commit
7bb6198798
|
|
@ -47,6 +47,19 @@ public class DistributionPayController {
|
||||||
payParam.setShopId(shopId);
|
payParam.setShopId(shopId);
|
||||||
return payService.ltPayOrder(ServletUtil.getClientIP(request), payParam);
|
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));
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
// * 正扫
|
// * 正扫
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.czg.controller;
|
package com.czg.controller;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
|
@ -9,12 +10,17 @@ import com.czg.entity.CzgBaseRespParams;
|
||||||
import com.czg.mq.PrintMqListener;
|
import com.czg.mq.PrintMqListener;
|
||||||
import com.czg.order.service.OrderInfoService;
|
import com.czg.order.service.OrderInfoService;
|
||||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
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.task.StatisticTask;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
|
import com.ijpay.core.kit.AesUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -38,15 +44,17 @@ public class NotifyController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ShopTableOrderStatisticService shopTableOrderStatisticService;
|
private ShopTableOrderStatisticService shopTableOrderStatisticService;
|
||||||
|
@Resource
|
||||||
|
private WxService wxService;
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("testOpen")
|
@GetMapping("testOpen")
|
||||||
public Map<String, String> test1(String code) throws Exception {
|
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 wxService.v3Pay("oeQYq5LzW-kSxJL9TR4s_UmOmNLE", new BigDecimal("0.01"), "测试", "testZs" + RandomUtil.randomNumbers(20), "test");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/payCallBack")
|
@RequestMapping("/payCallBack")
|
||||||
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams) {
|
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams) {
|
||||||
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
||||||
|
|
@ -56,6 +64,35 @@ public class NotifyController {
|
||||||
return SUCCESS;
|
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")
|
@RequestMapping("/refundCallBack")
|
||||||
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
|
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
|
||||||
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
JSONObject czg = CzgPayUtils.getCzg(respParams);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,17 @@ public class ShopInfo implements Serializable {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信openId
|
||||||
|
*/
|
||||||
|
private String wechatOpenId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝 openid
|
||||||
|
*/
|
||||||
|
private String alipayOpenId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用系统用户 sys_user id
|
* 使用系统用户 sys_user id
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,13 @@ import java.util.Map;
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
public interface WxService {
|
public interface WxService {
|
||||||
|
|
||||||
String getPhone(String code);
|
String getPhone(String code);
|
||||||
|
|
||||||
String getOpenId(String code);
|
String getOpenId(String code);
|
||||||
|
|
||||||
Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type);
|
Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type);
|
||||||
|
|
||||||
|
String decryptToString(String associatedData, String nonceStr, String ciphertext);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ public interface TableValueConstant {
|
||||||
interface DistributionConfig {
|
interface DistributionConfig {
|
||||||
@Getter
|
@Getter
|
||||||
enum OpenType {
|
enum OpenType {
|
||||||
PAY("PAY", "支付购买"),
|
PAY("pay", "支付购买"),
|
||||||
COST("COST", "消费增积分");
|
COST("COST", "消费增积分");
|
||||||
private final String code;
|
private final String code;
|
||||||
private final String msg;
|
private final String msg;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ public class Main {
|
||||||
// String packageName = "product";
|
// String packageName = "product";
|
||||||
String packageName = "market";
|
String packageName = "market";
|
||||||
// tableName 指定需要生成的表
|
// tableName 指定需要生成的表
|
||||||
String tableName = "mk_product_smart_suggest";
|
String tableName = "mk_distribution_amount_flow";
|
||||||
String author = "ww";
|
String author = "ww";
|
||||||
//是否生成DTO实体 默认生成
|
//是否生成DTO实体 默认生成
|
||||||
boolean isGenerateDto = true;
|
boolean isGenerateDto = true;
|
||||||
|
|
|
||||||
|
|
@ -34,5 +34,6 @@ public interface DistributionPayService {
|
||||||
CzgResult<Map<String, Object>> microPayOrder(MkDistributionPayDTO payParam);
|
CzgResult<Map<String, Object>> microPayOrder(MkDistributionPayDTO payParam);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, String> mchRecharge(String clientIP, MkDistributionPayDTO payParam);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.czg.service.order.service.impl;
|
package com.czg.service.order.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.czg.account.entity.ShopInfo;
|
||||||
import com.czg.account.entity.ShopUser;
|
import com.czg.account.entity.ShopUser;
|
||||||
import com.czg.account.entity.UserInfo;
|
import com.czg.account.entity.UserInfo;
|
||||||
import com.czg.account.service.ShopInfoService;
|
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.service.MkDistributionConfigService;
|
||||||
import com.czg.market.vo.MkDistributionConfigVO;
|
import com.czg.market.vo.MkDistributionConfigVO;
|
||||||
import com.czg.order.dto.MkDistributionPayDTO;
|
import com.czg.order.dto.MkDistributionPayDTO;
|
||||||
import com.czg.order.entity.OrderInfo;
|
|
||||||
import com.czg.order.entity.OrderPayment;
|
import com.czg.order.entity.OrderPayment;
|
||||||
import com.czg.order.enums.PayEnums;
|
|
||||||
import com.czg.order.service.OrderPaymentService;
|
import com.czg.order.service.OrderPaymentService;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.service.order.service.DistributionPayService;
|
import com.czg.service.order.service.DistributionPayService;
|
||||||
import com.czg.service.order.service.PayService;
|
|
||||||
import com.czg.system.service.WxService;
|
import com.czg.system.service.WxService;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
@ -63,22 +61,29 @@ public class DistributionPayServiceImpl implements DistributionPayService {
|
||||||
private String openId;
|
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());
|
MkDistributionConfigVO detail = configService.detail(payParam.getShopId());
|
||||||
AssertUtil.isTrue(detail.getIsEnable() != 1, "分销未开启");
|
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("当前未开启购买分销配置");
|
throw new CzgException("当前未开启购买分销配置");
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderPayment orderPayment = new OrderPayment().setShopId(payParam.getShopId()).setSourceId(userId)
|
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);
|
orderPaymentService.save(orderPayment);
|
||||||
|
|
||||||
|
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);
|
ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId);
|
||||||
UserInfo userInfo = userInfoService.getById(userId);
|
UserInfo userInfo = userInfoService.getById(userId);
|
||||||
return new InitInfo().setConfig(detail).setPayment(orderPayment).setShopUser(shopUserInfo)
|
initInfo.setPayment(orderPayment).setShopUser(shopUserInfo)
|
||||||
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
|
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
|
||||||
}
|
}
|
||||||
|
return initInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CzgResult<Object> cashPayOrder(MkDistributionPayDTO payParam) {
|
public CzgResult<Object> cashPayOrder(MkDistributionPayDTO payParam) {
|
||||||
|
|
@ -87,11 +92,17 @@ public class DistributionPayServiceImpl implements DistributionPayService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CzgResult<Map<String, Object>> ltPayOrder(String clintIp, MkDistributionPayDTO payParam) {
|
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(),
|
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(), ""));
|
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
|
@Override
|
||||||
public CzgResult<Map<String, Object>> scanPayOrder(String clintIp, MkDistributionPayDTO payParam) {
|
public CzgResult<Map<String, Object>> scanPayOrder(String clintIp, MkDistributionPayDTO payParam) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
@ -101,7 +102,7 @@ public class WxServiceImpl implements WxService {
|
||||||
private static String platformCertPath;
|
private static String platformCertPath;
|
||||||
private static String platformCertNo;
|
private static String platformCertNo;
|
||||||
private static String mchId;
|
private static String mchId;
|
||||||
private static String apiV3Key;
|
public static String apiV3Key;
|
||||||
private static String apiV2Key;
|
private static String apiV2Key;
|
||||||
private static String notifyUrl;
|
private static String notifyUrl;
|
||||||
private static String refundNotifyUrl;
|
private static String refundNotifyUrl;
|
||||||
|
|
@ -322,6 +323,20 @@ public class WxServiceImpl implements WxService {
|
||||||
log.info(publicKey);
|
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
|
@Override
|
||||||
public Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type) {
|
public Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type) {
|
||||||
if (desc == null) desc = "订单支付";
|
if (desc == null) desc = "订单支付";
|
||||||
|
|
@ -338,7 +353,7 @@ public class WxServiceImpl implements WxService {
|
||||||
String payInfo = JSONObject.toJSONString(model);
|
String payInfo = JSONObject.toJSONString(model);
|
||||||
log.info("统一下单参数: {}", payInfo);
|
log.info("统一下单参数: {}", payInfo);
|
||||||
|
|
||||||
IJPayHttpResponse resp = null;
|
IJPayHttpResponse resp;
|
||||||
try {
|
try {
|
||||||
resp = WxPayApi.v3(
|
resp = WxPayApi.v3(
|
||||||
RequestMethodEnum.POST,
|
RequestMethodEnum.POST,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue