64 changed files with 1534 additions and 280 deletions
@ -0,0 +1,23 @@ |
|||||
|
package com.bnyer.img.api.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/03/27 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class QueryVipOrderDto implements Serializable { |
||||
|
|
||||
|
@ApiModelProperty(value="订单id") |
||||
|
private String orderId; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
package com.bnyer.img.api.factory; |
||||
|
|
||||
|
import com.bnyer.common.core.domain.R; |
||||
|
import com.bnyer.img.api.dto.QueryVipOrderDto; |
||||
|
import com.bnyer.img.api.remote.RemoteVipOrderService; |
||||
|
import com.bnyer.img.api.vo.VipOrderVo; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.cloud.openfeign.FallbackFactory; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description :订单服务:vip订单接口熔断降级 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class RemoteVipOrderFallbackFactory implements FallbackFactory<RemoteVipOrderService> |
||||
|
{ |
||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteVipOrderFallbackFactory.class); |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public RemoteVipOrderService create(Throwable throwable) { |
||||
|
log.error("api订单服务调用失败:{}", throwable.getMessage()); |
||||
|
return new RemoteVipOrderService() { |
||||
|
|
||||
|
@Override |
||||
|
public R<List<VipOrderVo>> getVipOrderList(QueryVipOrderDto dto) { |
||||
|
return R.fail("获取会员订单信息失败:+"+throwable.getMessage()); |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
package com.bnyer.img.api.remote; |
||||
|
|
||||
|
import com.bnyer.common.core.constant.ServiceNameConstants; |
||||
|
import com.bnyer.common.core.domain.R; |
||||
|
import com.bnyer.common.core.dto.CreatorLoginDto; |
||||
|
import com.bnyer.common.core.dto.FhLoginDto; |
||||
|
import com.bnyer.common.core.dto.TiktokLoginDto; |
||||
|
import com.bnyer.common.core.dto.WxLoginDto; |
||||
|
import com.bnyer.img.api.dto.QueryVipOrderDto; |
||||
|
import com.bnyer.img.api.dto.TiktokImgMiniDto; |
||||
|
import com.bnyer.img.api.dto.VipOrderDto; |
||||
|
import com.bnyer.img.api.factory.RemoteImgFallbackFactory; |
||||
|
import com.bnyer.img.api.factory.RemoteVipOrderFallbackFactory; |
||||
|
import com.bnyer.img.api.model.LoginCreator; |
||||
|
import com.bnyer.img.api.model.LoginFhUser; |
||||
|
import com.bnyer.img.api.model.LoginTiktokUser; |
||||
|
import com.bnyer.img.api.model.LoginWechatUser; |
||||
|
import com.bnyer.img.api.vo.VipOrderVo; |
||||
|
import io.swagger.annotations.ApiParam; |
||||
|
import org.springframework.cloud.openfeign.FeignClient; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
|
||||
|
import javax.validation.Valid; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description :订单服务:vip订单接口远程调用 |
||||
|
*/ |
||||
|
@FeignClient(contextId = "remoteImgService", value = ServiceNameConstants.OORDER_SERVICE, fallbackFactory = RemoteVipOrderFallbackFactory.class) |
||||
|
public interface RemoteVipOrderService { |
||||
|
|
||||
|
@GetMapping("/getVipOrderList") |
||||
|
R<List<VipOrderVo>> getVipOrderList(@Valid QueryVipOrderDto dto); |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
package com.bnyer.img.api.vo; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/03/27 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class VipOrderVo { |
||||
|
|
||||
|
@ApiModelProperty(value="手机号") |
||||
|
private String phone; |
||||
|
|
||||
|
@ApiModelProperty(value="vip表id") |
||||
|
private Long vipId; |
||||
|
|
||||
|
@ApiModelProperty(value = "vip编码") |
||||
|
private String vipCode; |
||||
|
|
||||
|
@ApiModelProperty(value = "vip名称") |
||||
|
private String vipName; |
||||
|
|
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@ApiModelProperty(value="开始时间") |
||||
|
private Date startTime; |
||||
|
|
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@ApiModelProperty(value="到期时间") |
||||
|
private Date endTime; |
||||
|
|
||||
|
@ApiModelProperty(value = "用户客户端类型:10用户-抖音 20用户-快手 30用户-微信 40艺术家-微信") |
||||
|
private Integer userClientType; |
||||
|
|
||||
|
@ApiModelProperty(value="热门描述") |
||||
|
private String hotSignDesc; |
||||
|
|
||||
|
@ApiModelProperty(value="是否到期自动续费(0>否;1->是)") |
||||
|
private String isDelay; |
||||
|
|
||||
|
@ApiModelProperty(value="时长天数") |
||||
|
private Integer days; |
||||
|
|
||||
|
@ApiModelProperty(value="支付金额") |
||||
|
private BigDecimal payAmount; |
||||
|
|
||||
|
@ApiModelProperty(value = "分类名称") |
||||
|
private String categoryName; |
||||
|
|
||||
|
@ApiModelProperty(value = "vip类型名称") |
||||
|
private String vipTypeName; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
package com.bnyer.common.core.enums; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
import java.util.Objects; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@AllArgsConstructor |
||||
|
public enum EnumPayType { |
||||
|
|
||||
|
WX_PAY("wxpay","微信"), |
||||
|
ALI_PAY("alipay","支付宝"), |
||||
|
; |
||||
|
|
||||
|
private final String type; |
||||
|
|
||||
|
private final String name; |
||||
|
|
||||
|
public static String getName(String type) { |
||||
|
for (EnumPayType s : EnumPayType.values()) { |
||||
|
if (Objects.equals(type, s.getType())) { |
||||
|
return s.getName(); |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
package com.bnyer.common.core.enums; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@AllArgsConstructor |
||||
|
public enum EnumSceneCode { |
||||
|
|
||||
|
VIP_RECHARGE(1,"会员充值"), |
||||
|
UNKNOWN(-1,"未知"), |
||||
|
; |
||||
|
|
||||
|
private final int sceneCode; |
||||
|
|
||||
|
private final String name; |
||||
|
|
||||
|
public static String getSceneCodeName(int sceneCode) { |
||||
|
for (EnumSceneCode s : EnumSceneCode.values()) { |
||||
|
if (sceneCode == s.getSceneCode()) { |
||||
|
return s.getName(); |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
public static EnumSceneCode getSceneCodeByCode(int code) { |
||||
|
return Arrays.stream(values()) |
||||
|
.filter(sceneCode -> sceneCode.getSceneCode() == code) |
||||
|
.findFirst().orElse(EnumSceneCode.UNKNOWN); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
package com.bnyer.common.core.enums; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
import java.util.Objects; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@AllArgsConstructor |
||||
|
public enum EnumVipCategory { |
||||
|
|
||||
|
IMG_VIP("img","下图会员"), |
||||
|
VIDEO_VIP("video","视频会员"), |
||||
|
AI_VIP("ai","ai会员"), |
||||
|
; |
||||
|
|
||||
|
private final String code; |
||||
|
|
||||
|
private final String name; |
||||
|
|
||||
|
public static String getNameByCode(String code) { |
||||
|
for (EnumVipCategory s : EnumVipCategory.values()) { |
||||
|
if (Objects.equals(code, s.code)) { |
||||
|
return s.getName(); |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package com.bnyer.order.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/03/27 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class AddVipOrderDto implements Serializable { |
||||
|
|
||||
|
@NotBlank(message = "手机号不能为空!") |
||||
|
@ApiModelProperty(value="手机号") |
||||
|
private String phone; |
||||
|
|
||||
|
@NotNull(message = "vipId不能为空!") |
||||
|
@ApiModelProperty(value="vip表id") |
||||
|
private Long vipId; |
||||
|
|
||||
|
// @NotBlank(message = "用户客户端类型不能为空!")
|
||||
|
// @Range(min = 10,max = 40,message = "用户客户端类型只能包含:10用户-抖音 20用户-快手 30用户-微信 40艺术家-微信")
|
||||
|
// @ApiModelProperty(value="用户客户端类型:10用户-抖音 20用户-快手 30用户-微信 40艺术家-微信")
|
||||
|
// private Integer userClientType;
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
package com.bnyer.order.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/03/27 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class QueryVipOrderDto implements Serializable { |
||||
|
|
||||
|
@ApiModelProperty(value="订单id") |
||||
|
private String orderId; |
||||
|
|
||||
|
} |
||||
@ -1,30 +0,0 @@ |
|||||
package com.bnyer.order.enums; |
|
||||
|
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.Getter; |
|
||||
|
|
||||
/** |
|
||||
* @author :WXC |
|
||||
* @description : |
|
||||
*/ |
|
||||
@Getter |
|
||||
@AllArgsConstructor |
|
||||
public enum EnumSceneCode { |
|
||||
|
|
||||
VIP_RECHARGE("1","会员充值"), |
|
||||
; |
|
||||
|
|
||||
private String sceneCode; |
|
||||
|
|
||||
private String name; |
|
||||
|
|
||||
public static String getSceneCodeName(String sceneCode) { |
|
||||
for (EnumSceneCode s : EnumSceneCode.values()) { |
|
||||
if (sceneCode.equals(s.getSceneCode())) { |
|
||||
return s.getName(); |
|
||||
} |
|
||||
} |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,19 @@ |
|||||
|
package com.bnyer.pay.constant; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description : |
||||
|
*/ |
||||
|
public class AliPayConstant { |
||||
|
|
||||
|
/** |
||||
|
* 超时时间 |
||||
|
*/ |
||||
|
public static final String timeoutExpress = "30m"; |
||||
|
|
||||
|
/*** |
||||
|
* 接口地址 |
||||
|
*/ |
||||
|
public static final String aliUrl = "https://openapi.alipay.com/gateway.do"; |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.bnyer.pay.controller; |
||||
|
|
||||
|
import com.bnyer.common.core.domain.R; |
||||
|
import com.bnyer.pay.dto.AliPayInOrderDto; |
||||
|
import com.bnyer.pay.vo.PayInOrderVo; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.validation.Valid; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Api(value = "支付宝支付相关接口",tags = "支付宝支付相关接口") |
||||
|
@RestController |
||||
|
@RequestMapping("/pay/ali") |
||||
|
@Slf4j |
||||
|
public class AliPayController { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.bnyer.pay.controller; |
||||
|
|
||||
|
import com.bnyer.common.core.domain.R; |
||||
|
import com.bnyer.pay.dto.AddPayInfoDto; |
||||
|
import com.bnyer.pay.service.PayInfoService; |
||||
|
import com.bnyer.pay.vo.PayInOrderVo; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.validation.Valid; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Api(value = "支付订单相关接口",tags = "支付订单相关接口") |
||||
|
@RestController |
||||
|
@RequestMapping("/pay/order") |
||||
|
@Slf4j |
||||
|
public class PayController { |
||||
|
@Autowired |
||||
|
private PayInfoService payInfoService; |
||||
|
|
||||
|
@PostMapping("/addPayInOrder") |
||||
|
@Operation(summary = "统一下单,并生成支付订单" , description = "生成支付订单,返回前端支付所需参数") |
||||
|
public R<PayInOrderVo> addPayInOrder(@Valid @RequestBody AddPayInfoDto dto, HttpServletRequest request){ |
||||
|
PayInOrderVo payInOrderVo = payInfoService.addPayInOrder(dto,request); |
||||
|
return R.ok(payInOrderVo); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package com.bnyer.pay.controller; |
||||
|
|
||||
|
import io.swagger.annotations.Api; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Api(value = "微信支付相关接口",tags = "微信支付相关接口") |
||||
|
@RestController |
||||
|
@RequestMapping("/pay/wx") |
||||
|
@Slf4j |
||||
|
public class WxPayController { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package com.bnyer.pay.design.factory; |
||||
|
|
||||
|
import com.bnyer.common.core.enums.EnumPayType; |
||||
|
import com.bnyer.pay.design.strategy.AliPayStrategy; |
||||
|
import com.bnyer.pay.design.strategy.PayStrategy; |
||||
|
import com.bnyer.pay.design.strategy.WxPayStrategy; |
||||
|
import com.google.common.collect.ImmutableMap; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description :支付工厂 |
||||
|
*/ |
||||
|
public class PayFactory { |
||||
|
private static final Map<String, PayStrategy> strategyMap = new ImmutableMap.Builder<String, PayStrategy>() |
||||
|
.put(EnumPayType.ALI_PAY.getType(),new AliPayStrategy()) |
||||
|
.put(EnumPayType.WX_PAY.getType(),new WxPayStrategy()) |
||||
|
.build(); |
||||
|
|
||||
|
public static class SingletonHolder{ |
||||
|
public static PayFactory payStrategy = new PayFactory(); |
||||
|
} |
||||
|
|
||||
|
public static PayFactory getInstance(){ |
||||
|
return SingletonHolder.payStrategy; |
||||
|
} |
||||
|
|
||||
|
public PayStrategy getConcreteStrategy(String payType){ |
||||
|
return PayFactory.strategyMap.get(payType); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
package com.bnyer.pay.design.strategy; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import com.alipay.api.AlipayClient; |
||||
|
import com.alipay.api.AlipayConstants; |
||||
|
import com.alipay.api.DefaultAlipayClient; |
||||
|
import com.alipay.api.domain.AlipayTradeAppPayModel; |
||||
|
import com.alipay.api.request.AlipayTradeAppPayRequest; |
||||
|
import com.alipay.api.response.AlipayTradeAppPayResponse; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.bnyer.common.core.domain.AlipayConfig; |
||||
|
import com.bnyer.common.core.enums.ResponseEnum; |
||||
|
import com.bnyer.common.core.exception.ServiceException; |
||||
|
import com.bnyer.common.core.utils.SpringUtils; |
||||
|
import com.bnyer.pay.constant.AliPayConstant; |
||||
|
import com.bnyer.pay.dto.UnifiedOrderDto; |
||||
|
import com.bnyer.pay.enums.EnumPayConfigStatus; |
||||
|
import com.bnyer.pay.mapper.AlipayConfigMapper; |
||||
|
import com.bnyer.pay.vo.PayInOrderVo; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description :支付宝支付策略 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class AliPayStrategy implements PayStrategy{ |
||||
|
|
||||
|
@Override |
||||
|
public PayInOrderVo unifiedOrder(UnifiedOrderDto dto) { |
||||
|
AlipayConfigMapper alipayConfigMapper = SpringUtils.getBean(AlipayConfigMapper.class); |
||||
|
List<AlipayConfig> alipayConfigList = alipayConfigMapper.selectList(new LambdaQueryWrapper<AlipayConfig>().eq(AlipayConfig::getStatus, EnumPayConfigStatus.ENABLE.getCode())); |
||||
|
if (CollUtil.isEmpty(alipayConfigList)){ |
||||
|
throw new ServiceException(ResponseEnum.PAY_CONFIG_ERROR.getCode()); |
||||
|
} |
||||
|
AlipayConfig alipayConfig = alipayConfigList.get(0); |
||||
|
String appid = alipayConfig.getAppid(); |
||||
|
String alipayPublicKey = alipayConfig.getAlipayPublicKey(); |
||||
|
String appPrivateKey = alipayConfig.getAppPrivateKey(); |
||||
|
String keyType = alipayConfig.getKeyType(); |
||||
|
String backurl = alipayConfig.getBackurl(); |
||||
|
//实例化客户端
|
||||
|
AlipayClient alipayClient = new DefaultAlipayClient(AliPayConstant.aliUrl, appid,appPrivateKey, AlipayConstants.FORMAT_JSON, AlipayConstants.CHARSET_UTF8, alipayPublicKey, keyType); |
||||
|
// 实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
|
||||
|
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); |
||||
|
// SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
|
||||
|
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); |
||||
|
model.setSubject(dto.getGoodsSubject()); |
||||
|
model.setBody(dto.getGoodsDesc()); |
||||
|
model.setOutTradeNo(dto.getOrderId()); |
||||
|
model.setTimeoutExpress(AliPayConstant.timeoutExpress); |
||||
|
//元
|
||||
|
model.setTotalAmount(dto.getPayAmount()); |
||||
|
request.setBizModel(model); |
||||
|
request.setNotifyUrl(backurl); |
||||
|
try { |
||||
|
// 这里和普通的接口调用不同,使用的是sdkExecute
|
||||
|
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); |
||||
|
if(response.isSuccess()){ |
||||
|
PayInOrderVo vo = new PayInOrderVo(); |
||||
|
vo.setOutStr(response.getBody()); |
||||
|
vo.setAppid(appid); |
||||
|
return vo; |
||||
|
}else{ |
||||
|
throw new ServiceException(response.getMsg()); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
log.error("支付宝下单接口调用失败,error:{}",e.getMessage()); |
||||
|
throw new ServiceException(ResponseEnum.PAY_FAILS.getCode()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
package com.bnyer.pay.design.strategy; |
||||
|
|
||||
|
import com.bnyer.pay.dto.UnifiedOrderDto; |
||||
|
import com.bnyer.pay.vo.PayInOrderVo; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description :支付策略 |
||||
|
*/ |
||||
|
public interface PayStrategy { |
||||
|
/** |
||||
|
* 统一下单 |
||||
|
* @param dto |
||||
|
* @return |
||||
|
*/ |
||||
|
PayInOrderVo unifiedOrder(UnifiedOrderDto dto); |
||||
|
|
||||
|
|
||||
|
//===========待完成================
|
||||
|
// TODO: 2023/04/03 回调处理
|
||||
|
// void parsePayNotify();
|
||||
|
|
||||
|
// TODO: 2023/04/03 订单查询
|
||||
|
// void orderQuery();
|
||||
|
|
||||
|
// TODO: 2023/04/03 退款
|
||||
|
// void refund();
|
||||
|
|
||||
|
// TODO: 2023/04/03 退款查询
|
||||
|
// void refundQuery();
|
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
package com.bnyer.pay.design.strategy; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.bnyer.common.core.domain.WxpayConfig; |
||||
|
import com.bnyer.common.core.enums.ResponseEnum; |
||||
|
import com.bnyer.common.core.exception.ServiceException; |
||||
|
import com.bnyer.pay.dto.UnifiedOrderDto; |
||||
|
import com.bnyer.pay.enums.EnumTradeType; |
||||
|
import com.bnyer.pay.manager.WxPayManager; |
||||
|
import com.bnyer.pay.vo.PayInOrderVo; |
||||
|
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; |
||||
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; |
||||
|
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult; |
||||
|
import com.github.binarywang.wxpay.exception.WxPayException; |
||||
|
import com.github.binarywang.wxpay.service.WxPayService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description :微信支付策略 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class WxPayStrategy implements PayStrategy { |
||||
|
|
||||
|
@Autowired |
||||
|
private WxPayManager wxPayManager; |
||||
|
|
||||
|
@Override |
||||
|
public PayInOrderVo unifiedOrder(UnifiedOrderDto dto) { |
||||
|
log.info("微信支付:统一下单接口调用开始,WxPayStrategy.unifiedOrder dto:{}",JSON.toJSONString(dto)); |
||||
|
PayInOrderVo payInOrderVo = null; |
||||
|
EnumTradeType payByTradeType = EnumTradeType.getPayByTradeType(dto.getTradeType()); |
||||
|
switch (payByTradeType){ |
||||
|
case JSAPI_MINI: |
||||
|
payInOrderVo = jsApiPay(dto); |
||||
|
break; |
||||
|
case JSAPI_PUBLIC: |
||||
|
break; |
||||
|
default: |
||||
|
throw new ServiceException("TradeType未匹配上对应支付方式"); |
||||
|
} |
||||
|
return payInOrderVo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* JSAPI支付 |
||||
|
* @param dto |
||||
|
* @return |
||||
|
*/ |
||||
|
private PayInOrderVo jsApiPay(UnifiedOrderDto dto) { |
||||
|
WxpayConfig wxPayConfig = wxPayManager.getWxPayConfig(dto.getTradeType()); |
||||
|
WxPayService wxPayService = wxPayManager.getWxPayService(wxPayConfig); |
||||
|
try { |
||||
|
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); |
||||
|
orderRequest.setOpenid(dto.getOpenId()); |
||||
|
orderRequest.setOutTradeNo(dto.getOrderId()); |
||||
|
orderRequest.setBody(dto.getGoodsDesc()); |
||||
|
orderRequest.setSpbillCreateIp(dto.getIp()); |
||||
|
orderRequest.setTotalFee(BaseWxPayRequest.yuanToFen(dto.getPayAmount())); |
||||
|
//调用微信支付接口
|
||||
|
WxPayUnifiedOrderResult wxPayUnifiedOrderResult = wxPayService.unifiedOrder(orderRequest); |
||||
|
String timestamp = String.valueOf(dto.getCurrDate().getTime()); |
||||
|
if (timestamp.length() > 10) { |
||||
|
timestamp = timestamp.substring(0, 10); |
||||
|
} |
||||
|
//返回数据
|
||||
|
PayInOrderVo payInOrderVo = new PayInOrderVo(); |
||||
|
payInOrderVo.setAppid(wxPayConfig.getAppid()); |
||||
|
payInOrderVo.setMchid(wxPayConfig.getMchid()); |
||||
|
payInOrderVo.setPrepayid(wxPayUnifiedOrderResult.getPrepayId()); |
||||
|
payInOrderVo.setNoncestr(wxPayUnifiedOrderResult.getNonceStr()); |
||||
|
payInOrderVo.setTimestamp(timestamp); |
||||
|
payInOrderVo.setSign(wxPayUnifiedOrderResult.getSign()); |
||||
|
payInOrderVo.setTradeType(wxPayUnifiedOrderResult.getTradeType()); |
||||
|
return payInOrderVo; |
||||
|
} catch (WxPayException e) { |
||||
|
log.error("微信支付:统一下单接口调用失败,orderId:{},error{}", dto.getOrderId(), e.getMessage()); |
||||
|
throw new ServiceException(ResponseEnum.PAY_FAILS.getCode()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.bnyer.pay.dto; |
||||
|
|
||||
|
import com.bnyer.common.core.annotation.DiyParamsValidation; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class AddPayInfoDto { |
||||
|
|
||||
|
@NotBlank(message = "业务主订单号不能为空") |
||||
|
@ApiModelProperty(value="业务主订单号:关联内部业务订单表",required = true) |
||||
|
private String orderId; |
||||
|
|
||||
|
@NotBlank(message = "支付场景不能为空") |
||||
|
@ApiModelProperty(value="支付场景:1.会员充值",required = true) |
||||
|
private Integer sceneCode; |
||||
|
|
||||
|
@NotBlank(message = "支付类型不能为空") |
||||
|
@ApiModelProperty(value="支付类型:wxpay/alipay",required = true) |
||||
|
private String payType; |
||||
|
|
||||
|
@ApiModelProperty(value="交易类型 1--JSAPI支付(小程序appId支付)、2--Native支付、3--app支付,4--JSAPI支付(公众号appId支付)5--H5支付,微信支付必填",example = "1") |
||||
|
@DiyParamsValidation(range = "1",message = "交易类型暂时只支持JSAPI") |
||||
|
private String tradeType; |
||||
|
|
||||
|
@ApiModelProperty(value="备注") |
||||
|
private String remark; |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.bnyer.pay.dto; |
||||
|
|
||||
|
import com.bnyer.common.core.annotation.DiyParamsValidation; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class AliPayInOrderDto { |
||||
|
@ApiModelProperty(value="orderId",example = "1") |
||||
|
@NotBlank(message = "orderId 不能为空") |
||||
|
private String orderId; |
||||
|
|
||||
|
@ApiModelProperty(value="费用(单位元)",example = "0.01") |
||||
|
@NotBlank(message = "请输入金额(单位元)") |
||||
|
private String payAmount; |
||||
|
|
||||
|
@ApiModelProperty(value="用户ip",example = "127.0.0.1") |
||||
|
@NotBlank(message = "请输入终端IP") |
||||
|
private String ip; |
||||
|
|
||||
|
@ApiModelProperty(value="商品标题",example = "商品标题") |
||||
|
@NotBlank(message = "请输入支付标题") |
||||
|
private String goodsSubject; |
||||
|
|
||||
|
@ApiModelProperty(value="商品描述",example = "商品描述") |
||||
|
@NotBlank(message = "请输入支付描述") |
||||
|
private String goodsDesc; |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
package com.bnyer.pay.dto; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class UnifiedOrderDto { |
||||
|
|
||||
|
/** |
||||
|
* 业务主订单id:关联内部业务订单表 |
||||
|
*/ |
||||
|
private String orderId; |
||||
|
/** |
||||
|
* trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。 |
||||
|
*/ |
||||
|
private String openId; |
||||
|
/** |
||||
|
* 支付金额:元 |
||||
|
*/ |
||||
|
private String payAmount; |
||||
|
/** |
||||
|
* ip地址 |
||||
|
*/ |
||||
|
private String ip; |
||||
|
/** |
||||
|
* 当前时间 |
||||
|
*/ |
||||
|
private Date currDate; |
||||
|
/** |
||||
|
* 交易类型 1--JSAPI支付(小程序appId支付)、2--Native支付、3--app支付,4--JSAPI支付(公众号appId支付) 6-H5支付 ,必要参数 |
||||
|
*/ |
||||
|
private String tradeType; |
||||
|
/** |
||||
|
* 商品标题:会员充值 |
||||
|
*/ |
||||
|
private String goodsSubject; |
||||
|
/** |
||||
|
* 商品描述: 会员充值 |
||||
|
*/ |
||||
|
private String goodsDesc; |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
package com.bnyer.pay.dto; |
||||
|
|
||||
|
import com.bnyer.common.core.annotation.DiyParamsValidation; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/05 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class WxPayInOrderDto { |
||||
|
|
||||
|
@ApiModelProperty(value="orderId",example = "1") |
||||
|
@NotBlank |
||||
|
private String orderId; |
||||
|
|
||||
|
@ApiModelProperty(value="timestamp",example = "1111111111") |
||||
|
@NotBlank |
||||
|
private String timestamp; |
||||
|
|
||||
|
@ApiModelProperty(value="费用(单位分)",example = "1") |
||||
|
@NotBlank(message = "请输入金额(单位分)") |
||||
|
private String feeFen; |
||||
|
|
||||
|
@ApiModelProperty(value="商品描述",example = "商品描述") |
||||
|
@NotBlank(message = "请输入支付描述") |
||||
|
private String goodsDesc; |
||||
|
|
||||
|
@ApiModelProperty(value="用户ip",example = "127.0.0.1") |
||||
|
@NotBlank(message = "请输入终端IP") |
||||
|
private String ip; |
||||
|
|
||||
|
@ApiModelProperty(value="交易类型[APP不传,JSAPI必传|MINIPROGRAM],APP|JSAPI|MWEB|MINIPROGRAM",example = "JSAPI") |
||||
|
@DiyParamsValidation(range = "APP|JSAPI|MWEB|MINIPROGRAM",message = "请输入正确的交易类型") |
||||
|
private String tradeType; |
||||
|
|
||||
|
@ApiModelProperty(value="openid[APP不传,JSAPI必传]",example = "12345678") |
||||
|
private String openid; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.bnyer.pay.enums; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
import java.util.Objects; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@AllArgsConstructor |
||||
|
public enum EnumPayConfigStatus { |
||||
|
|
||||
|
ENABLE("0","正常"), |
||||
|
DISABLE("1","停用"), |
||||
|
; |
||||
|
|
||||
|
private final String code; |
||||
|
|
||||
|
private final String name; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
package com.bnyer.pay.enums; |
||||
|
|
||||
|
import com.bnyer.common.core.enums.EnumVipCategory; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Getter; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.Objects; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Getter |
||||
|
@AllArgsConstructor |
||||
|
public enum EnumTradeType { |
||||
|
|
||||
|
JSAPI_MINI("1","JSAPI","JSAPI支付(小程序appId支付)"), |
||||
|
NATIVE("2","NATIVE","Native支付"), |
||||
|
APP("3","APP","app支付"), |
||||
|
JSAPI_PUBLIC("4","JSAPI","JSAPI支付(公众号appId支付)"), |
||||
|
H5("5","JSAPI","H5支付"), |
||||
|
|
||||
|
UNKNOWN("-1", null, "未知支付"), |
||||
|
; |
||||
|
|
||||
|
private final String code; |
||||
|
|
||||
|
private final String name; |
||||
|
|
||||
|
private final String desc; |
||||
|
|
||||
|
public static EnumTradeType getPayByTradeType(String code) { |
||||
|
return Arrays.stream(values()) |
||||
|
.filter(tradeType -> tradeType.getCode().equals(code)) |
||||
|
.findFirst().orElse(EnumTradeType.UNKNOWN); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
package com.bnyer.pay.manager; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.bnyer.common.core.domain.WxpayConfig; |
||||
|
import com.bnyer.common.core.enums.ResponseEnum; |
||||
|
import com.bnyer.common.core.exception.ServiceException; |
||||
|
import com.bnyer.common.core.utils.SpringUtils; |
||||
|
import com.bnyer.pay.enums.EnumPayConfigStatus; |
||||
|
import com.bnyer.pay.enums.EnumTradeType; |
||||
|
import com.bnyer.pay.mapper.WxpayConfigMapper; |
||||
|
import com.github.binarywang.wxpay.config.WxPayConfig; |
||||
|
import com.github.binarywang.wxpay.constant.WxPayConstants; |
||||
|
import com.github.binarywang.wxpay.service.WxPayService; |
||||
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.Objects; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/06 |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Component |
||||
|
public class WxPayManager { |
||||
|
|
||||
|
/** |
||||
|
* 获取支付配置 |
||||
|
* @return |
||||
|
*/ |
||||
|
public WxpayConfig getWxPayConfig(String tradeType){ |
||||
|
WxpayConfigMapper wxpayConfigMapper = SpringUtils.getBean(WxpayConfigMapper.class); |
||||
|
//查询数据库配置:appId,mchId,key,backUrl等
|
||||
|
WxpayConfig wxpayConfig = wxpayConfigMapper.selectOne(new LambdaQueryWrapper<WxpayConfig>().eq(WxpayConfig::getTradeType,tradeType).eq(WxpayConfig::getStatus, EnumPayConfigStatus.ENABLE.getCode())); |
||||
|
if (Objects.isNull(wxpayConfig)) { |
||||
|
throw new ServiceException(ResponseEnum.PAY_CONFIG_ERROR.getCode()); |
||||
|
} |
||||
|
return wxpayConfig; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取微信支付服务 |
||||
|
* @return |
||||
|
*/ |
||||
|
public WxPayService getWxPayService(WxpayConfig wxpayConfig){ |
||||
|
String appId = wxpayConfig.getAppid(); |
||||
|
String mchId = wxpayConfig.getMchid(); |
||||
|
String key = wxpayConfig.getKey(); |
||||
|
String backUrl = wxpayConfig.getBackurl(); |
||||
|
WxPayConfig payConfig = new WxPayConfig(); |
||||
|
payConfig.setAppId(appId); |
||||
|
payConfig.setMchId(mchId); |
||||
|
payConfig.setMchKey(key); |
||||
|
payConfig.setSignType(WxPayConstants.SignType.MD5); |
||||
|
payConfig.setNotifyUrl(backUrl); |
||||
|
payConfig.setTradeType(EnumTradeType.getPayByTradeType(wxpayConfig.getTradeType()).getName()); |
||||
|
WxPayService wxPayService = new WxPayServiceImpl(); |
||||
|
wxPayService.setConfig(payConfig); |
||||
|
return wxPayService; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
package com.bnyer.pay.service; |
||||
|
|
||||
|
import com.bnyer.common.core.domain.PayInfo; |
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.bnyer.pay.dto.AddPayInfoDto; |
||||
|
import com.bnyer.pay.vo.PayInOrderVo; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @description : |
||||
|
*/ |
||||
|
public interface PayInfoService extends IService<PayInfo>{ |
||||
|
/** |
||||
|
* 生成支付订单 |
||||
|
* @param dto |
||||
|
* @param request |
||||
|
* @return |
||||
|
*/ |
||||
|
PayInOrderVo addPayInOrder(AddPayInfoDto dto, HttpServletRequest request); |
||||
|
} |
||||
@ -1,12 +0,0 @@ |
|||||
package com.bnyer.pay.service; |
|
||||
|
|
||||
import com.bnyer.common.core.domain.PayInfo; |
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
|
||||
/** |
|
||||
* @author :WXC |
|
||||
* @description : |
|
||||
*/ |
|
||||
public interface PayPayInfoService extends IService<PayInfo>{ |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,94 @@ |
|||||
|
package com.bnyer.pay.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.bnyer.common.core.context.SecurityContextHolder; |
||||
|
import com.bnyer.common.core.domain.PayInfo; |
||||
|
import com.bnyer.common.core.domain.R; |
||||
|
import com.bnyer.common.core.enums.EnumSceneCode; |
||||
|
import com.bnyer.common.core.exception.ServiceException; |
||||
|
import com.bnyer.common.core.utils.bean.EntityConvertUtil; |
||||
|
import com.bnyer.common.core.utils.ip.IpUtils; |
||||
|
import com.bnyer.common.security.utils.SecurityUtils; |
||||
|
import com.bnyer.img.api.dto.QueryVipOrderDto; |
||||
|
import com.bnyer.img.api.remote.RemoteVipOrderService; |
||||
|
import com.bnyer.img.api.vo.VipOrderVo; |
||||
|
import com.bnyer.pay.dto.AddPayInfoDto; |
||||
|
import com.bnyer.pay.dto.UnifiedOrderDto; |
||||
|
import com.bnyer.pay.mapper.PayInfoMapper; |
||||
|
import com.bnyer.pay.service.PayInfoService; |
||||
|
import com.bnyer.pay.design.factory.PayFactory; |
||||
|
import com.bnyer.pay.vo.PayInOrderVo; |
||||
|
import com.bnyer.pay.design.strategy.PayStrategy; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @description : |
||||
|
*/ |
||||
|
@Service |
||||
|
public class PayInfoServiceImpl extends ServiceImpl<PayInfoMapper, PayInfo> implements PayInfoService { |
||||
|
|
||||
|
@Autowired |
||||
|
private RemoteVipOrderService remoteVipOrderService; |
||||
|
|
||||
|
/** |
||||
|
* 统一下单,并生成支付订单 |
||||
|
* @param dto |
||||
|
* @param request |
||||
|
* @return |
||||
|
*/ |
||||
|
@Override |
||||
|
public PayInOrderVo addPayInOrder(AddPayInfoDto dto, HttpServletRequest request) { |
||||
|
//支付金额
|
||||
|
String payAmount = ""; |
||||
|
EnumSceneCode sceneCodeByCode = EnumSceneCode.getSceneCodeByCode(dto.getSceneCode()); |
||||
|
switch (sceneCodeByCode){ |
||||
|
//会员充值场景
|
||||
|
case VIP_RECHARGE: |
||||
|
QueryVipOrderDto queryVipOrderDto = new QueryVipOrderDto(); |
||||
|
queryVipOrderDto.setOrderId(dto.getOrderId()); |
||||
|
//查询会员业务订单信息
|
||||
|
R<List<VipOrderVo>> vipOrderVoListR = remoteVipOrderService.getVipOrderList(queryVipOrderDto); |
||||
|
if (!vipOrderVoListR.isSuccess()){ |
||||
|
throw new ServiceException(vipOrderVoListR.getMsg()); |
||||
|
} |
||||
|
VipOrderVo vipOrderVo = vipOrderVoListR.getData().get(0); |
||||
|
payAmount = vipOrderVo.getPayAmount().toString(); |
||||
|
break; |
||||
|
default: |
||||
|
throw new ServiceException("sceneCode未匹配上对应支付场景"); |
||||
|
} |
||||
|
//ip地址
|
||||
|
String ip = IpUtils.getIpAddr(request); |
||||
|
//当前时间
|
||||
|
Date currDate = new Date(); |
||||
|
UnifiedOrderDto unifiedOrderDto = buildUnifiedOrderDto(dto, payAmount, ip, currDate); |
||||
|
//构建统一下单请求实体
|
||||
|
PayStrategy payStrategy = PayFactory.getInstance().getConcreteStrategy(dto.getPayType()); |
||||
|
PayInOrderVo payInOrderVo = payStrategy.unifiedOrder(unifiedOrderDto); |
||||
|
return payInOrderVo; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 构建统一下单请求实体 |
||||
|
* @param dto |
||||
|
* @param payAmount |
||||
|
* @param ip |
||||
|
* @param currDate |
||||
|
* @return |
||||
|
*/ |
||||
|
private UnifiedOrderDto buildUnifiedOrderDto(AddPayInfoDto dto, String payAmount, String ip, Date currDate) { |
||||
|
String wxCode = SecurityContextHolder.get("wxCode"); |
||||
|
UnifiedOrderDto unifiedOrderDto = EntityConvertUtil.copy(dto, UnifiedOrderDto.class); |
||||
|
unifiedOrderDto.setIp(ip); |
||||
|
unifiedOrderDto.setCurrDate(currDate); |
||||
|
unifiedOrderDto.setPayAmount(payAmount); |
||||
|
unifiedOrderDto.setOpenId(wxCode); |
||||
|
return unifiedOrderDto; |
||||
|
} |
||||
|
} |
||||
@ -1,15 +0,0 @@ |
|||||
package com.bnyer.pay.service.impl; |
|
||||
|
|
||||
import org.springframework.stereotype.Service; |
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
||||
import com.bnyer.common.core.domain.PayInfo; |
|
||||
import com.bnyer.pay.mapper.PayPayInfoMapper; |
|
||||
import com.bnyer.pay.service.PayPayInfoService; |
|
||||
/** |
|
||||
* @author :WXC |
|
||||
* @description : |
|
||||
*/ |
|
||||
@Service |
|
||||
public class PayPayInfoServiceImpl extends ServiceImpl<PayPayInfoMapper, PayInfo> implements PayPayInfoService{ |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,47 @@ |
|||||
|
package com.bnyer.pay.vo; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
/** |
||||
|
* @author :WXC |
||||
|
* @Date :2023/04/03 |
||||
|
* @description :统一第三方支付下单返回参数 |
||||
|
*/ |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@NoArgsConstructor |
||||
|
public class PayInOrderVo { |
||||
|
|
||||
|
@ApiModelProperty(value = "appid") |
||||
|
private String appid; |
||||
|
|
||||
|
@ApiModelProperty(value = "商户号") |
||||
|
private String mchid; |
||||
|
|
||||
|
@ApiModelProperty(value = "交易类型:JSAPI等") |
||||
|
private String tradeType; |
||||
|
|
||||
|
@ApiModelProperty(value = "微信返回的字段") |
||||
|
private String prepayid; |
||||
|
|
||||
|
@ApiModelProperty(value = "随机串") |
||||
|
private String noncestr; |
||||
|
|
||||
|
@ApiModelProperty(value = "时间戳") |
||||
|
private String timestamp; |
||||
|
|
||||
|
@ApiModelProperty(value = "签名") |
||||
|
private String sign; |
||||
|
|
||||
|
@ApiModelProperty(value = "支付宝") |
||||
|
private String outStr; |
||||
|
|
||||
|
@ApiModelProperty(value = "订单号") |
||||
|
private String orderId; |
||||
|
|
||||
|
@ApiModelProperty(value = "调微信支付接口地址") |
||||
|
private String mwebUrl; |
||||
|
} |
||||
@ -1,6 +1,6 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.bnyer.pay.mapper.PayAlipayConfigMapper"> |
<mapper namespace="com.bnyer.pay.mapper.AlipayConfigMapper"> |
||||
<resultMap id="BaseResultMap" type="com.bnyer.common.core.domain.AlipayConfig"> |
<resultMap id="BaseResultMap" type="com.bnyer.common.core.domain.AlipayConfig"> |
||||
<!--@mbg.generated--> |
<!--@mbg.generated--> |
||||
<!--@Table pay_alipay_config--> |
<!--@Table pay_alipay_config--> |
||||
@ -1,6 +1,6 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.bnyer.pay.mapper.PayPayInfoMapper"> |
<mapper namespace="com.bnyer.pay.mapper.PayInfoMapper"> |
||||
<resultMap id="BaseResultMap" type="com.bnyer.common.core.domain.PayInfo"> |
<resultMap id="BaseResultMap" type="com.bnyer.common.core.domain.PayInfo"> |
||||
<!--@mbg.generated--> |
<!--@mbg.generated--> |
||||
<!--@Table pay_pay_info--> |
<!--@Table pay_pay_info--> |
||||
@ -1,6 +1,6 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.bnyer.pay.mapper.PayWxpayConfigMapper"> |
<mapper namespace="com.bnyer.pay.mapper.WxpayConfigMapper"> |
||||
<resultMap id="BaseResultMap" type="com.bnyer.common.core.domain.WxpayConfig"> |
<resultMap id="BaseResultMap" type="com.bnyer.common.core.domain.WxpayConfig"> |
||||
<!--@mbg.generated--> |
<!--@mbg.generated--> |
||||
<!--@Table pay_wxpay_config--> |
<!--@Table pay_wxpay_config--> |
||||
Loading…
Reference in new issue