数据
This commit is contained in:
2
doc/v4.sql
Normal file
2
doc/v4.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `cai_account`
|
||||||
|
ADD COLUMN `total_trd_money` decimal(20, 2) NOT NULL DEFAULT 0 COMMENT '三方充值总额' AFTER `total_buy_coin`;
|
||||||
@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.cai.app;
|
|||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaIgnore;
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.alipay.api.AlipayApiException;
|
import com.alipay.api.AlipayApiException;
|
||||||
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
||||||
import com.alipay.api.internal.util.AlipaySignature;
|
import com.alipay.api.internal.util.AlipaySignature;
|
||||||
@@ -14,10 +15,15 @@ import com.ijpay.core.kit.WxPayKit;
|
|||||||
import com.ijpay.wxpay.WxPayApi;
|
import com.ijpay.wxpay.WxPayApi;
|
||||||
import com.ijpay.wxpay.model.UnifiedOrderModel;
|
import com.ijpay.wxpay.model.UnifiedOrderModel;
|
||||||
import com.ruoyi.cai.domain.PayConfig;
|
import com.ruoyi.cai.domain.PayConfig;
|
||||||
|
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||||
|
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||||
import com.ruoyi.cai.pay.*;
|
import com.ruoyi.cai.pay.*;
|
||||||
|
import com.ruoyi.cai.trdpay.TrdPayManager;
|
||||||
|
import com.ruoyi.cai.trdpay.TrdPayProperties;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -44,10 +50,53 @@ public class PayController {
|
|||||||
private PayConfigManager payConfigManager;
|
private PayConfigManager payConfigManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PayManager payManager;
|
private PayManager payManager;
|
||||||
|
@Autowired
|
||||||
|
private TrdPayProperties trdPayProperties;
|
||||||
|
@Autowired
|
||||||
|
private TrdPayManager trdPayManager;
|
||||||
|
@Autowired
|
||||||
|
private SystemConfigManager systemConfigManager;
|
||||||
|
|
||||||
private static final String NOTIFY_WX_URL = "/api/pay/wx/notify";
|
private static final String NOTIFY_WX_URL = "/api/pay/wx/notify";
|
||||||
private static final String NOTIFY_ALI_URL = "/api/pay/ali/notify";
|
private static final String NOTIFY_ALI_URL = "/api/pay/ali/notify";
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/trdAli")
|
||||||
|
@Operation(summary = "第三方支付宝支付")
|
||||||
|
@Log(title = "第三方支付宝支付", businessType = BusinessType.OTHER, isSaveDb = true)
|
||||||
|
public R<Map<String,Object>> checkPayType(){
|
||||||
|
Integer payInit = systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.COS_DOMAIN);
|
||||||
|
Long userId = LoginHelper.getUserId();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/trdAli")
|
||||||
|
@Operation(summary = "第三方支付宝支付")
|
||||||
|
@Log(title = "第三方支付宝支付", businessType = BusinessType.OTHER, isSaveDb = true)
|
||||||
|
public R<PayReturnResp> trdWxPay(@RequestBody PayControllerDTO dto){
|
||||||
|
PayOrderInfoDTO payOrderInfo = payManager.getOrderInfo(dto.getOrderNo());
|
||||||
|
if(payOrderInfo == null){
|
||||||
|
return R.fail(600,"支付失败,未找到订单");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONObject wx = trdPayManager.createOrderWx(payOrderInfo);
|
||||||
|
String code = wx.getString("retCode");
|
||||||
|
if(!"SUCCESS".equals(code)){
|
||||||
|
return R.fail(600,"支付失败!微信支付通道失败!");
|
||||||
|
}
|
||||||
|
String payUrl = wx.getJSONObject("payParams").getString("payUrl");
|
||||||
|
PayReturnResp payTrdReturnResp = new PayReturnResp();
|
||||||
|
payTrdReturnResp.setData(payUrl);
|
||||||
|
return R.ok(payTrdReturnResp);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("第三方微信支付失败!",e);
|
||||||
|
return R.fail(600,"支付失败!微信支付通道失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping(value = "/wx")
|
@PostMapping(value = "/wx")
|
||||||
@Operation(summary = "微信支付")
|
@Operation(summary = "微信支付")
|
||||||
@Log(title = "微信支付", businessType = BusinessType.OTHER, isSaveDb = true)
|
@Log(title = "微信支付", businessType = BusinessType.OTHER, isSaveDb = true)
|
||||||
@@ -196,4 +245,24 @@ public class PayController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/trd/notify")
|
||||||
|
@Operation(hidden = true)
|
||||||
|
@Log(title = "第三方支付回调", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||||
|
@SaIgnore
|
||||||
|
public String trdNotifyUrl(HttpServletRequest request) {
|
||||||
|
try {
|
||||||
|
Map<String, String> params = AliPayApi.toMap(request);
|
||||||
|
log.info("第三方支付回调:{}",JSON.toJSONString(params));
|
||||||
|
String mchOrderNo = params.get("mchOrderNo");
|
||||||
|
String payOrderId = params.get("payOrderId");
|
||||||
|
String productId = params.get("productId");
|
||||||
|
payManager.callBack(mchOrderNo,payOrderId,params,productId, PayTypeEnum.TRD);
|
||||||
|
return "success";
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("第三方支付回调失败!",e);
|
||||||
|
return "failure";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,3 +109,9 @@ springdoc:
|
|||||||
enabled: false
|
enabled: false
|
||||||
knife4j:
|
knife4j:
|
||||||
enable: false
|
enable: false
|
||||||
|
trd:
|
||||||
|
pay:
|
||||||
|
mch-id: 10418
|
||||||
|
wx-product-id: 8000
|
||||||
|
ali-product-id: 8000
|
||||||
|
notify-url-domain: "http://1.12.220.225:9889"
|
||||||
|
|||||||
@@ -245,6 +245,12 @@ cai:
|
|||||||
websocket: false
|
websocket: false
|
||||||
coin-name: 花钻
|
coin-name: 花钻
|
||||||
home-name: 花语
|
home-name: 花语
|
||||||
|
trd:
|
||||||
|
pay:
|
||||||
|
mch-id: 10418
|
||||||
|
wx-product-id: 8000
|
||||||
|
ali-product-id: 8000
|
||||||
|
notify-url-domain: "http://1.12.220.225:9889"
|
||||||
--- # Actuator 监控端点的配置项
|
--- # Actuator 监控端点的配置项
|
||||||
management:
|
management:
|
||||||
endpoints:
|
endpoints:
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ public class ConsumerManager {
|
|||||||
log.error("RabbitMq 发送失败, 充值分销流程流转失败!",e);
|
log.error("RabbitMq 发送失败, 充值分销流程流转失败!",e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// 记录主播的消费记录
|
// 记录用户的消费统计
|
||||||
accountTotalManager.incsPayIncomeCoin(resp.getUserId(), resp.getRechargeCoin(),resp.getPrice(), resp.getConsumeLogId());
|
accountTotalManager.incsPayIncomeCoin(resp.getUserId(), resp.getRechargeCoin(),resp.getPrice(), resp.getConsumeLogId());
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("主播消费记录失败-充值",e);
|
log.error("主播消费记录失败-充值",e);
|
||||||
|
|||||||
@@ -36,4 +36,6 @@ public interface AccountMapper extends BaseMapper<Account> {
|
|||||||
void incsVideoIncomeIcon(@Param("userId") Long userId, @Param("amount") Long amount);
|
void incsVideoIncomeIcon(@Param("userId") Long userId, @Param("amount") Long amount);
|
||||||
|
|
||||||
void incsPayTotal(@Param("userId") Long userId, @Param("rechargeCoin") Long rechargeCoin, @Param("price") BigDecimal price);
|
void incsPayTotal(@Param("userId") Long userId, @Param("rechargeCoin") Long rechargeCoin, @Param("price") BigDecimal price);
|
||||||
|
|
||||||
|
void incsTrdPayTotal(@Param("userId") Long userId, @Param("rechargeCoin") Long rechargeCoin, @Param("price") BigDecimal price);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.ruoyi.cai.pay;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PayTrdReturnResp {
|
||||||
|
private String payUrl;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.ruoyi.cai.pay;
|
|||||||
public enum PayTypeEnum {
|
public enum PayTypeEnum {
|
||||||
ALI(1),
|
ALI(1),
|
||||||
WX(2),
|
WX(2),
|
||||||
|
TRD(3),
|
||||||
;
|
;
|
||||||
private final Integer code;
|
private final Integer code;
|
||||||
|
|
||||||
|
|||||||
116
ruoyi-cai/src/main/java/com/ruoyi/cai/trdpay/TrdPayManager.java
Normal file
116
ruoyi-cai/src/main/java/com/ruoyi/cai/trdpay/TrdPayManager.java
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
package com.ruoyi.cai.trdpay;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.ruoyi.cai.pay.PayOrderInfoDTO;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.client.BufferingClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class TrdPayManager {
|
||||||
|
|
||||||
|
private final String CREATE_ORDER_URL = "http://pay.jpay.one/api/pay/create_order";
|
||||||
|
|
||||||
|
private static final String NOTIFY_ALI_URL = "/api/pay/trd/notify";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TrdPayProperties trdPayProperties;
|
||||||
|
|
||||||
|
public static RestTemplate restTemplate;
|
||||||
|
|
||||||
|
static {
|
||||||
|
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
||||||
|
requestFactory.setConnectTimeout(3000);
|
||||||
|
requestFactory.setReadTimeout(3000);
|
||||||
|
restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(requestFactory));
|
||||||
|
List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
|
||||||
|
//添加转换器
|
||||||
|
for (HttpMessageConverter<?> messageConverter : messageConverters) {
|
||||||
|
if (messageConverter instanceof StringHttpMessageConverter) {
|
||||||
|
StringHttpMessageConverter converter = (StringHttpMessageConverter) messageConverter;
|
||||||
|
converter.setDefaultCharset(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject createOrderWx(PayOrderInfoDTO payOrderInfoDTO){
|
||||||
|
return createOrder(payOrderInfoDTO,trdPayProperties.getWxProductId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject createOrderAli(PayOrderInfoDTO payOrderInfoDTO){
|
||||||
|
return createOrder(payOrderInfoDTO,trdPayProperties.getAliProductId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public JSONObject createOrder(PayOrderInfoDTO payOrderInfoDTO,String productId){
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("mchId", trdPayProperties.getMchId());
|
||||||
|
params.put("productId", productId);
|
||||||
|
params.put("mchOrderNo", payOrderInfoDTO.getOrderNo());
|
||||||
|
params.put("amount", payOrderInfoDTO.getPriceFenStr());
|
||||||
|
String notifyUrl = trdPayProperties.getNotifyUrlDomain() + NOTIFY_ALI_URL;
|
||||||
|
params.put("notifyUrl", notifyUrl);
|
||||||
|
String para = createParams(params);
|
||||||
|
String url = CREATE_ORDER_URL + "?" + para;
|
||||||
|
String body = restTemplate.getForEntity(url, String.class).getBody();
|
||||||
|
JSONObject jsonObject = JSON.parseObject(body);
|
||||||
|
if(jsonObject == null){
|
||||||
|
log.error("第三方支付失败 返回数据为空");
|
||||||
|
throw new ServiceException("调用支付失败");
|
||||||
|
}
|
||||||
|
if(!"SUCCESS".equals(jsonObject.getString("retCode"))){
|
||||||
|
log.info("第三方支付失败 统一支付失败失败 url={}, body={}",url, body);
|
||||||
|
throw new ServiceException("调用支付失败");
|
||||||
|
}
|
||||||
|
log.info("第三方支付成功 URL={}, body={}",url, body);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createParams(Map<String, String> params){
|
||||||
|
List<String> url = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||||
|
url.add(entry.getKey()+"="+entry.getValue());
|
||||||
|
}
|
||||||
|
url = url.stream().sorted().collect(Collectors.toList());
|
||||||
|
String stringSignTemp = StringUtils.join(url, "&") + "&key=" + trdPayProperties.getSignKey();
|
||||||
|
String sign = DigestUtil.md5Hex(stringSignTemp).toUpperCase();
|
||||||
|
url.add("sign="+sign);
|
||||||
|
return StringUtils.join(url, "&");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
TrdPayProperties payProperties = new TrdPayProperties();
|
||||||
|
payProperties.setMchId("10418");
|
||||||
|
payProperties.setNotifyUrlDomain("https://api.ssss.com");
|
||||||
|
PayOrderInfoDTO payOrderInfo = new PayOrderInfoDTO();
|
||||||
|
payOrderInfo.setPrice(new BigDecimal("10"));
|
||||||
|
payOrderInfo.setOrderNo("DSKsdasklddshjkasdka");
|
||||||
|
TrdPayManager trdPayManager = new TrdPayManager();
|
||||||
|
// trdPayManager.(payProperties);
|
||||||
|
trdPayManager.createOrder(payOrderInfo,"8000");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.cai.trdpay;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "trd.pay")
|
||||||
|
public class TrdPayProperties {
|
||||||
|
private String mchId;
|
||||||
|
private String wxProductId;
|
||||||
|
private String aliProductId;
|
||||||
|
private String notifyUrlDomain;
|
||||||
|
private String signKey = "IQJWYHUKWOWWLJHTY8K9SVGLD8OCRNOT4817D383FIYZI53YPEKTIXOUKDHTY4TEXGKK45YY2YJJDHS5YHMKOWO6HASDQ4KX10R23BOQ8JNQUICSKW2OWQRBDMLRKL2J";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user