19 changed files with 636 additions and 0 deletions
Unified View
Diff Options
-
38dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/paymentchannelorder/constant/PaymentChannelOrderStatusEnum.java
-
44dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/paymentchannelorder/entity/PaymentChannelOrder.java
-
6dating-agency-mall-server/pom.xml
-
33dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/paymentchannelorder/user/PaymentChannelOrderUserCommandController.java
-
33dating-agency-mall-server/src/main/java/com/qniao/dam/api/command/paymentchannelorder/user/request/PrePayThirdPartyDto.java
-
22dating-agency-mall-server/src/main/java/com/qniao/dam/api/validator/MustBeExisted.java
-
34dating-agency-mall-server/src/main/java/com/qniao/dam/api/validator/impl/MustBeExistedValidator.java
-
39dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/paymentchannelorder/PaymentChannelOrderApplicationService.java
-
25dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/paymentchannelorder/processor/IChannelPayService.java
-
163dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/paymentchannelorder/processor/wechat/WeChatPayProcessor.java
-
45dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/paymentchannelorder/processor/wechat/vobj/ChannelPaymentField.java
-
51dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/paymentchannelorder/processor/wechat/vobj/WeChatPaymentBasic.java
-
20dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/paymentchannelorder/PaymentChannelOrderAggregate.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/paymentchannelorder/repository/PaymentChannelOrderRepository.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/PaymentChannelOrderDao.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/UserOpenIdDao.java
-
31dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/PaymentChannelOrderRepositoryImpl.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/query/useropenid/UserOpenIdQueryService.java
-
24dating-agency-mall-server/src/main/java/com/qniao/dam/query/useropenid/impl/UserOpenIdQueryServiceImpl.java
@ -0,0 +1,38 @@ |
|||||
|
package com.qniao.dam.domian.aggregate.paymentchannelorder.constant; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
|
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
@Getter |
||||
|
@JsonFormat(shape = JsonFormat.Shape.OBJECT) |
||||
|
public enum PaymentChannelOrderStatusEnum { |
||||
|
|
||||
|
UNPAID(1, "未付款"), |
||||
|
|
||||
|
PAID(2, "已付款"), |
||||
|
|
||||
|
CANCELED(3, "已取消"); |
||||
|
|
||||
|
@EnumValue |
||||
|
@JsonValue |
||||
|
private final Integer value; |
||||
|
private final String desc; |
||||
|
|
||||
|
PaymentChannelOrderStatusEnum(Integer value, String desc) { |
||||
|
this.value = value; |
||||
|
this.desc = desc; |
||||
|
} |
||||
|
|
||||
|
@JsonCreator |
||||
|
public static PaymentChannelOrderStatusEnum get(Object code) { |
||||
|
for (PaymentChannelOrderStatusEnum e : PaymentChannelOrderStatusEnum.values()) { |
||||
|
if (e.getValue().equals(code)) { |
||||
|
return e; |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
package com.qniao.dam.domain.aggregate.paymentchannelorder.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.qniao.dam.domian.aggregate.paymentchannelorder.constant.PaymentChannelOrderStatusEnum; |
||||
|
import com.qniao.dam.domian.aggregate.paymentorder.constant.PaymentMethodEnum; |
||||
|
import com.qniao.domain.Entity; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@TableName("da_payment_channel_order") |
||||
|
public class PaymentChannelOrder extends Entity<PaymentChannelOrder> { |
||||
|
|
||||
|
@ApiModelProperty("订单") |
||||
|
private Long txnOrderId; |
||||
|
|
||||
|
@ApiModelProperty("付款方式") |
||||
|
private PaymentMethodEnum paymentMethod; |
||||
|
|
||||
|
@ApiModelProperty("应用ID") |
||||
|
private Long appId; |
||||
|
|
||||
|
@ApiModelProperty("外部单号") |
||||
|
private String extOrderNo; |
||||
|
|
||||
|
@ApiModelProperty("金额") |
||||
|
private BigDecimal amount; |
||||
|
|
||||
|
@ApiModelProperty("交易描述信息") |
||||
|
private String comment; |
||||
|
|
||||
|
@ApiModelProperty("支付时间") |
||||
|
private LocalDateTime paidTime; |
||||
|
|
||||
|
@ApiModelProperty("状态") |
||||
|
private PaymentChannelOrderStatusEnum status; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
package com.qniao.dam.api.command.paymentchannelorder.user; |
||||
|
|
||||
|
import com.qniao.dam.api.command.paymentchannelorder.user.request.PrePayThirdPartyDto; |
||||
|
import com.qniao.dam.application.service.paymentchannelorder.PaymentChannelOrderApplicationService; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.framework.utils.ServletUtils; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("user") |
||||
|
@Api(tags = "支付渠道订单") |
||||
|
public class PaymentChannelOrderUserCommandController { |
||||
|
|
||||
|
@Resource |
||||
|
private PaymentChannelOrderApplicationService paymentChannelOrderApplicationService; |
||||
|
|
||||
|
@ApiOperation("用户发起第三方预支付") |
||||
|
@PostMapping("/pre-pay/third-party") |
||||
|
public Map<String, String> prePayThirdParty(@RequestBody @Validated PrePayThirdPartyDto dto, |
||||
|
@RequestParam Long userId) { |
||||
|
PaymentChannelOrder paymentChannelOrder = dto.trans2Domain(); |
||||
|
paymentChannelOrder.setAppId(Long.valueOf(ServletUtils.getAppId())); |
||||
|
//todo 付款单状态判断 订单支付方式是否满足 |
||||
|
return paymentChannelOrderApplicationService.prePay(dto.trans2Domain(), userId); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
package com.qniao.dam.api.command.paymentchannelorder.user.request; |
||||
|
|
||||
|
import com.qniao.dam.api.validator.MustBeExisted; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.dam.domian.aggregate.paymentorder.constant.PaymentMethodEnum; |
||||
|
import com.qniao.dam.infrastructure.persistent.dao.domain.PaymentOrderDao; |
||||
|
import com.qniao.domain.Trans2DomainAssembler; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
|
||||
|
@Data |
||||
|
public class PrePayThirdPartyDto implements Trans2DomainAssembler<PaymentChannelOrder> { |
||||
|
|
||||
|
|
||||
|
@ApiModelProperty("交易单标识") |
||||
|
@NotNull(message = "交易单标识不能为空") |
||||
|
@MustBeExisted(checker = PaymentOrderDao.class, message = "支付单不存在") |
||||
|
private Long paymentOrderId; |
||||
|
|
||||
|
@ApiModelProperty("付款方式") |
||||
|
@NotNull(message = "付款方式不能为空") |
||||
|
private PaymentMethodEnum paymentMethod; |
||||
|
|
||||
|
@Override |
||||
|
public PaymentChannelOrder trans2Domain() { |
||||
|
PaymentChannelOrder paymentChannelOrder = new PaymentChannelOrder(); |
||||
|
paymentChannelOrder.setTxnOrderId(paymentOrderId); |
||||
|
paymentChannelOrder.setPaymentMethod(paymentMethod); |
||||
|
return paymentChannelOrder; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
package com.qniao.dam.api.validator; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qniao.dam.api.validator.impl.MustBeExistedValidator; |
||||
|
|
||||
|
import javax.validation.Constraint; |
||||
|
import javax.validation.Payload; |
||||
|
import java.lang.annotation.*; |
||||
|
|
||||
|
@Documented |
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
@Target({ElementType.FIELD, ElementType.PARAMETER}) |
||||
|
@Constraint(validatedBy = {MustBeExistedValidator.class}) |
||||
|
public @interface MustBeExisted { |
||||
|
String message() default ""; |
||||
|
|
||||
|
Class<? extends BaseMapper<?>> checker(); |
||||
|
|
||||
|
Class<?>[] groups() default {}; |
||||
|
|
||||
|
Class<? extends Payload>[] payload() default {}; |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package com.qniao.dam.api.validator.impl; |
||||
|
|
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qniao.dam.api.validator.MustBeExisted; |
||||
|
import org.apache.ibatis.session.SqlSession; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import javax.validation.ConstraintValidator; |
||||
|
import javax.validation.ConstraintValidatorContext; |
||||
|
|
||||
|
public class MustBeExistedValidator implements ConstraintValidator<MustBeExisted, Long> { |
||||
|
@Resource |
||||
|
private SqlSession sqlSession; |
||||
|
|
||||
|
private Class<? extends BaseMapper<?>> daoClazz; |
||||
|
|
||||
|
@Override |
||||
|
public void initialize(MustBeExisted constraintAnnotation) { |
||||
|
ConstraintValidator.super.initialize(constraintAnnotation); |
||||
|
|
||||
|
this.daoClazz = constraintAnnotation.checker(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isValid(Long id, ConstraintValidatorContext context) { |
||||
|
if (ObjectUtil.isNull(id)) { |
||||
|
return true; |
||||
|
} else { |
||||
|
BaseMapper<?> dao = sqlSession.getMapper(daoClazz); |
||||
|
return ObjectUtil.isNotNull(dao.selectById(id)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.qniao.dam.application.service.paymentchannelorder; |
||||
|
|
||||
|
import com.qniao.dam.application.service.paymentchannelorder.processor.IChannelPayService; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.PaymentChannelOrderAggregate; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.dam.domain.aggregate.paymentorder.entity.PaymentOrder; |
||||
|
import com.qniao.dam.domain.aggregate.paymentorder.repository.PaymentOrderRepository; |
||||
|
import com.qniao.dam.query.useropenid.UserOpenIdQueryService; |
||||
|
import com.qniao.dau.domain.aggregate.useropenid.entity.UserOpenId; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.util.Assert; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Service |
||||
|
public class PaymentChannelOrderApplicationService { |
||||
|
|
||||
|
@Resource |
||||
|
private UserOpenIdQueryService userOpenIdQueryService; |
||||
|
@Resource |
||||
|
private PaymentOrderRepository paymentOrderRepository; |
||||
|
@Resource |
||||
|
private PaymentChannelOrderAggregate paymentChannelOrderAggregate; |
||||
|
|
||||
|
/** |
||||
|
* todo 旧的付款单失效处理? |
||||
|
*/ |
||||
|
public Map<String, String> prePay(PaymentChannelOrder paymentChannelOrder, Long userId) { |
||||
|
UserOpenId userOpenId = userOpenIdQueryService.getByUserId(userId, paymentChannelOrder.getAppId()); |
||||
|
Assert.notNull(userOpenId, "发起支付失败"); |
||||
|
PaymentOrder paymentOrder = paymentOrderRepository.load(paymentChannelOrder.getTxnOrderId()); |
||||
|
paymentChannelOrder.setAmount(paymentOrder.getUnpaidAmount()); |
||||
|
paymentChannelOrder.setComment("订单交易"); |
||||
|
paymentChannelOrderAggregate.create(paymentChannelOrder); |
||||
|
IChannelPayService channelPayService = IChannelPayService.getService(paymentChannelOrder.getPaymentMethod()); |
||||
|
return channelPayService.handle(paymentChannelOrder, userOpenId); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
package com.qniao.dam.application.service.paymentchannelorder.processor; |
||||
|
|
||||
|
import com.qniao.dam.application.service.paymentchannelorder.processor.wechat.WeChatPayProcessor; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.dam.domian.aggregate.paymentorder.constant.PaymentMethodEnum; |
||||
|
import com.qniao.dau.domain.aggregate.useropenid.entity.UserOpenId; |
||||
|
import com.qniao.framework.exception.BizException; |
||||
|
import com.qniao.framework.utils.SpringContextUtil; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
|
||||
|
public abstract class IChannelPayService { |
||||
|
|
||||
|
|
||||
|
public static IChannelPayService getService(PaymentMethodEnum paymentMethod) { |
||||
|
switch (paymentMethod) { |
||||
|
case WECHAT_PAY: |
||||
|
return SpringContextUtil.getBean(WeChatPayProcessor.class); |
||||
|
default: |
||||
|
throw new BizException("invalid auth method"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public abstract Map<String, String> handle(PaymentChannelOrder paymentChannelOrder, UserOpenId userOpenId); |
||||
|
} |
||||
@ -0,0 +1,163 @@ |
|||||
|
package com.qniao.dam.application.service.paymentchannelorder.processor.wechat; |
||||
|
|
||||
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; |
||||
|
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult; |
||||
|
import com.github.binarywang.wxpay.config.WxPayConfig; |
||||
|
import com.github.binarywang.wxpay.constant.WxPayConstants; |
||||
|
import com.github.binarywang.wxpay.exception.WxPayException; |
||||
|
import com.github.binarywang.wxpay.service.WxPayService; |
||||
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; |
||||
|
import com.github.binarywang.wxpay.util.SignUtils; |
||||
|
import com.qniao.dam.application.service.paymentchannelorder.processor.IChannelPayService; |
||||
|
import com.qniao.dam.application.service.paymentchannelorder.processor.wechat.vobj.ChannelPaymentField; |
||||
|
import com.qniao.dam.application.service.paymentchannelorder.processor.wechat.vobj.WeChatPaymentBasic; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.dau.domain.aggregate.useropenid.entity.UserOpenId; |
||||
|
import com.qniao.framework.exception.BizException; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.math.RoundingMode; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class WeChatPayProcessor extends IChannelPayService { |
||||
|
|
||||
|
@Value("${weixin.mchid}") |
||||
|
private String mchId; |
||||
|
@Value("${weixin.mchkey}") |
||||
|
private String mchKey; |
||||
|
@Value("${weixin.appid}") |
||||
|
private String appid; |
||||
|
@Value("${weixin.notifyurl}") |
||||
|
private String notifyUrl; |
||||
|
|
||||
|
@Override |
||||
|
public Map<String, String> handle(PaymentChannelOrder paymentChannelOrder, UserOpenId userOpenId) { |
||||
|
WxPayConfig wxPayConfig = getWxPayConfig(); |
||||
|
WxPayUnifiedOrderRequest request = buildUnifiedOrderRequest(paymentChannelOrder, wxPayConfig, userOpenId.getOpenId()); |
||||
|
WeChatPaymentBasic weChatPaymentBasic = getWeChatPaymentBasic(request, wxPayConfig); |
||||
|
return transformToMap(weChatPaymentBasic); |
||||
|
} |
||||
|
|
||||
|
public WxPayConfig getWxPayConfig() { |
||||
|
WxPayConfig wxPayConfig = new WxPayConfig(); |
||||
|
wxPayConfig.setMchId(mchId); |
||||
|
wxPayConfig.setMchKey(mchKey); |
||||
|
wxPayConfig.setAppId(appid); |
||||
|
wxPayConfig.setTradeType("JSAPI"); |
||||
|
wxPayConfig.setNotifyUrl(notifyUrl); |
||||
|
return wxPayConfig; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 构建微信统一下单请求数据 |
||||
|
* |
||||
|
* @param paymentChannelOrder |
||||
|
* @param wxPayConfig |
||||
|
* @return |
||||
|
*/ |
||||
|
public WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PaymentChannelOrder paymentChannelOrder, WxPayConfig wxPayConfig, String openId) { |
||||
|
// 微信统一下单请求对象 |
||||
|
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); |
||||
|
request.setBody(paymentChannelOrder.getComment()); |
||||
|
request.setOutTradeNo(paymentChannelOrder.getId().toString()); |
||||
|
request.setTotalFee(paymentChannelOrder.getAmount().multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_UP).intValue()); |
||||
|
request.setSpbillCreateIp("127.0.0.1"); |
||||
|
//todo 是否需要记在渠道支付单中 |
||||
|
request.setTimeExpire(LocalDateTime.now().plusMinutes(30L).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); |
||||
|
request.setNotifyUrl(wxPayConfig.getNotifyUrl()); |
||||
|
request.setTradeType(wxPayConfig.getTradeType()); |
||||
|
if (request.getTradeType().equals("JSAPI")) { |
||||
|
request.setOpenid(openId); |
||||
|
} |
||||
|
return request; |
||||
|
} |
||||
|
|
||||
|
private WeChatPaymentBasic getWeChatPaymentBasic(WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest, WxPayConfig wxPayConfig) { |
||||
|
WxPayService wxPayService = new WxPayServiceImpl(); |
||||
|
wxPayService.setConfig(wxPayConfig); |
||||
|
WxPayUnifiedOrderResult wxPayUnifiedOrderResult = null; |
||||
|
try { |
||||
|
String timestamp = String.valueOf(System.currentTimeMillis() / 1000); |
||||
|
String nonceStr = String.valueOf(System.currentTimeMillis()); |
||||
|
log.info("发起微信支付参数 配置:{},参数: {}", wxPayUnifiedOrderRequest, wxPayConfig); |
||||
|
wxPayUnifiedOrderResult = wxPayService.unifiedOrder(wxPayUnifiedOrderRequest); |
||||
|
WeChatPaymentBasic weChatPaymentBasic = new WeChatPaymentBasic(); |
||||
|
if (wxPayConfig.getTradeType().equals("JSAPI")) { |
||||
|
log.info("微信预支付返回结果:{}", wxPayUnifiedOrderResult); |
||||
|
weChatPaymentBasic.setAppId(wxPayUnifiedOrderResult.getAppid()); |
||||
|
weChatPaymentBasic.setNonceStr(nonceStr); |
||||
|
weChatPaymentBasic.setTimeStamp(timestamp); |
||||
|
weChatPaymentBasic.setPackages("prepay_id=" + wxPayUnifiedOrderResult.getPrepayId()); |
||||
|
weChatPaymentBasic.setSignType(WxPayConstants.SignType.MD5); |
||||
|
weChatPaymentBasic.setPaySign(sign(weChatPaymentBasic, wxPayConfig)); |
||||
|
log.info("微信预支付调起参数:{}", weChatPaymentBasic); |
||||
|
} else if (wxPayConfig.getTradeType().equals("APP")) { |
||||
|
log.info("微信预支付返回结果:{}", wxPayUnifiedOrderResult); |
||||
|
String packageValue = "Sign=WXPay"; |
||||
|
weChatPaymentBasic.setSign(appSign(wxPayUnifiedOrderResult.getPrepayId(), |
||||
|
wxPayConfig.getMchId(), |
||||
|
timestamp, |
||||
|
nonceStr, |
||||
|
wxPayConfig.getAppId(), |
||||
|
packageValue, |
||||
|
wxPayConfig)); |
||||
|
weChatPaymentBasic.setPrepayid(wxPayUnifiedOrderResult.getPrepayId()); |
||||
|
weChatPaymentBasic.setPartnerid(wxPayConfig.getMchId()); |
||||
|
weChatPaymentBasic.setAppId(wxPayUnifiedOrderResult.getAppid()); |
||||
|
weChatPaymentBasic.setPackages(packageValue); |
||||
|
weChatPaymentBasic.setTimeStamp(timestamp); |
||||
|
weChatPaymentBasic.setNonceStr(nonceStr); |
||||
|
log.info("微信预支付调起参数:{}", weChatPaymentBasic); |
||||
|
} |
||||
|
return weChatPaymentBasic; |
||||
|
} catch (WxPayException e) { |
||||
|
log.info(e.getMessage()); |
||||
|
throw new BizException("发起微信预支付异常"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private String sign(WeChatPaymentBasic weChatPaymentBasicVo, WxPayConfig wxPayConfig) { |
||||
|
Map<String, String> payInfo = new HashMap<>(); |
||||
|
payInfo.put("appId", weChatPaymentBasicVo.getAppId()); |
||||
|
payInfo.put("timeStamp", weChatPaymentBasicVo.getTimeStamp()); |
||||
|
payInfo.put("nonceStr", weChatPaymentBasicVo.getNonceStr()); |
||||
|
payInfo.put("package", weChatPaymentBasicVo.getPackages()); |
||||
|
payInfo.put("signType", WxPayConstants.SignType.MD5); |
||||
|
return SignUtils.createSign(payInfo, wxPayConfig.getSignType(), wxPayConfig.getMchKey(), null); |
||||
|
} |
||||
|
|
||||
|
private String appSign(String prepayid, String partnerid, String timestamp, String noncestr, String appid, String packageValue, WxPayConfig wxPayConfig) { |
||||
|
Map<String, String> configMap = new HashMap<>(); |
||||
|
configMap.put("prepayid", prepayid); |
||||
|
configMap.put("partnerid", partnerid); |
||||
|
configMap.put("package", packageValue); |
||||
|
configMap.put("timestamp", timestamp); |
||||
|
configMap.put("noncestr", noncestr); |
||||
|
configMap.put("appid", appid); |
||||
|
return SignUtils.createSign(configMap, wxPayConfig.getSignType(), wxPayConfig.getMchKey(), null); |
||||
|
} |
||||
|
|
||||
|
private Map<String, String> transformToMap(WeChatPaymentBasic weChatPaymentBasic) { |
||||
|
Map<String, String> map = new HashMap<>(); |
||||
|
map.put(ChannelPaymentField.APPID, weChatPaymentBasic.getAppId()); |
||||
|
map.put(ChannelPaymentField.TIMESTAMP, weChatPaymentBasic.getTimeStamp()); |
||||
|
map.put(ChannelPaymentField.NONCE_STR, weChatPaymentBasic.getNonceStr()); |
||||
|
map.put(ChannelPaymentField.PACKAGES, weChatPaymentBasic.getPackages()); |
||||
|
map.put(ChannelPaymentField.SIGN_TYPE, weChatPaymentBasic.getSignType()); |
||||
|
map.put(ChannelPaymentField.PAY_SIGN, weChatPaymentBasic.getPaySign()); |
||||
|
map.put(ChannelPaymentField.PRE_PAY_ID, weChatPaymentBasic.getPrepayid()); |
||||
|
map.put(ChannelPaymentField.PARTNER_ID, weChatPaymentBasic.getPartnerid()); |
||||
|
map.put(ChannelPaymentField.SIGN, weChatPaymentBasic.getSign()); |
||||
|
return map; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
package com.qniao.dam.application.service.paymentchannelorder.processor.wechat.vobj; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author Derran |
||||
|
* @date 2023/8/17 17:25 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class ChannelPaymentField { |
||||
|
|
||||
|
/** |
||||
|
* 应用ID |
||||
|
*/ |
||||
|
public static final String APPID = "appId"; |
||||
|
/** |
||||
|
* 时间戳 |
||||
|
*/ |
||||
|
public static final String TIMESTAMP = "timeStamp"; |
||||
|
/** |
||||
|
* 随机字符串 |
||||
|
*/ |
||||
|
public static final String NONCE_STR = "nonceStr"; |
||||
|
/** |
||||
|
* 订单详情扩展字符串 |
||||
|
*/ |
||||
|
public static final String PACKAGES = "packages"; |
||||
|
/** |
||||
|
* 签名方式 |
||||
|
*/ |
||||
|
public static final String SIGN_TYPE = "signType"; |
||||
|
/** |
||||
|
* JSAPI签名 |
||||
|
*/ |
||||
|
public static final String PAY_SIGN = "paySign"; |
||||
|
|
||||
|
public static final String PRE_PAY_ID = "prepayid"; |
||||
|
|
||||
|
public static final String PARTNER_ID = "partnerid"; |
||||
|
/** |
||||
|
* APP sign |
||||
|
*/ |
||||
|
public static final String SIGN = "sign"; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
package com.qniao.dam.application.service.paymentchannelorder.processor.wechat.vobj; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author Derran |
||||
|
* @date 2023/8/17 17:05 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class WeChatPaymentBasic { |
||||
|
|
||||
|
/** |
||||
|
* 应用ID |
||||
|
*/ |
||||
|
private String appId; |
||||
|
|
||||
|
/** |
||||
|
* 时间戳 |
||||
|
*/ |
||||
|
private String timeStamp; |
||||
|
|
||||
|
/** |
||||
|
* 随机字符串 |
||||
|
*/ |
||||
|
private String nonceStr; |
||||
|
|
||||
|
/** |
||||
|
* 订单详情扩展字符串 |
||||
|
*/ |
||||
|
private String packages; |
||||
|
|
||||
|
/** |
||||
|
* 签名方式 |
||||
|
*/ |
||||
|
private String signType; |
||||
|
|
||||
|
/** |
||||
|
* JSAPI签名 |
||||
|
*/ |
||||
|
private String paySign; |
||||
|
|
||||
|
|
||||
|
private String prepayid; |
||||
|
|
||||
|
private String partnerid; |
||||
|
|
||||
|
/** |
||||
|
* APP sign |
||||
|
*/ |
||||
|
private String sign; |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package com.qniao.dam.domain.aggregate.paymentchannelorder; |
||||
|
|
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.repository.PaymentChannelOrderRepository; |
||||
|
import com.qniao.dam.domian.aggregate.paymentchannelorder.constant.PaymentChannelOrderStatusEnum; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
@Service |
||||
|
public class PaymentChannelOrderAggregate { |
||||
|
|
||||
|
@Resource |
||||
|
private PaymentChannelOrderRepository paymentChannelOrderRepository; |
||||
|
|
||||
|
public void create(PaymentChannelOrder paymentChannelOrder) { |
||||
|
paymentChannelOrder.setStatus(PaymentChannelOrderStatusEnum.UNPAID); |
||||
|
paymentChannelOrderRepository.save(paymentChannelOrder); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
package com.qniao.dam.domain.aggregate.paymentchannelorder.repository; |
||||
|
|
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.domain.Repository; |
||||
|
|
||||
|
public interface PaymentChannelOrderRepository extends Repository<PaymentChannelOrder, Long> { |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
package com.qniao.dam.infrastructure.persistent.dao.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
|
||||
|
public interface PaymentChannelOrderDao extends BaseMapper<PaymentChannelOrder> { |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
package com.qniao.dam.infrastructure.persistent.dao.domain; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qniao.dau.domain.aggregate.useropenid.entity.UserOpenId; |
||||
|
|
||||
|
public interface UserOpenIdDao extends BaseMapper<UserOpenId> { |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
package com.qniao.dam.infrastructure.persistent.repository.impl; |
||||
|
|
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
||||
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.repository.PaymentChannelOrderRepository; |
||||
|
import com.qniao.dam.infrastructure.persistent.dao.domain.PaymentChannelOrderDao; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.Objects; |
||||
|
|
||||
|
@Service |
||||
|
public class PaymentChannelOrderRepositoryImpl implements PaymentChannelOrderRepository { |
||||
|
|
||||
|
@Resource |
||||
|
private PaymentChannelOrderDao paymentChannelOrderDao; |
||||
|
|
||||
|
@Override |
||||
|
public PaymentChannelOrder load(Long id) { |
||||
|
return paymentChannelOrderDao.selectById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Long save(PaymentChannelOrder entity) { |
||||
|
if (Objects.isNull(entity.getId()) || Objects.isNull(paymentChannelOrderDao.selectById(entity.getId()))) { |
||||
|
paymentChannelOrderDao.insert(entity); |
||||
|
} else { |
||||
|
paymentChannelOrderDao.updateById(entity); |
||||
|
} |
||||
|
return entity.getId(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
package com.qniao.dam.query.useropenid; |
||||
|
|
||||
|
import com.qniao.dau.domain.aggregate.useropenid.entity.UserOpenId; |
||||
|
|
||||
|
public interface UserOpenIdQueryService { |
||||
|
UserOpenId getByUserId(Long userId, Long appFrom); |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.qniao.dam.query.useropenid.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.qniao.dam.infrastructure.persistent.dao.domain.UserOpenIdDao; |
||||
|
import com.qniao.dam.query.useropenid.UserOpenIdQueryService; |
||||
|
import com.qniao.dau.domain.aggregate.useropenid.entity.UserOpenId; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
@Service |
||||
|
public class UserOpenIdQueryServiceImpl implements UserOpenIdQueryService { |
||||
|
|
||||
|
@Resource |
||||
|
private UserOpenIdDao userOpenIdDao; |
||||
|
|
||||
|
@Override |
||||
|
public UserOpenId getByUserId(Long userId, Long appFrom) { |
||||
|
return userOpenIdDao.selectOne(new LambdaQueryWrapper<UserOpenId>() |
||||
|
.eq(UserOpenId::getUserId, userId) |
||||
|
.eq(UserOpenId::getAppId, appFrom) |
||||
|
.last("limit 1")); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save