提交新功能 分销商 积分 会员体系
This commit is contained in:
@ -71,6 +71,32 @@
|
||||
<version>2.11.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-express-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-member-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-order-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@ -6,9 +6,6 @@ import co.yixiang.yshop.module.pay.strategy.PayFactory;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
@Getter
|
||||
public class PayContext {
|
||||
|
||||
@ -3,11 +3,15 @@ package co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo;
|
||||
import co.yixiang.yshop.module.pay.dal.dataobject.merchantdetails.MerchantDetailsDO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public class PayParam {
|
||||
/***
|
||||
* 商户订单号
|
||||
@ -22,7 +26,7 @@ public class PayParam {
|
||||
/***
|
||||
* 用户openid
|
||||
*/
|
||||
String openid;
|
||||
String openId;
|
||||
|
||||
String ip;
|
||||
|
||||
@ -34,4 +38,8 @@ public class PayParam {
|
||||
String payDesc;
|
||||
|
||||
MerchantDetailsDO merchantDetailsDO;
|
||||
|
||||
private Long uid;
|
||||
|
||||
String redirectType;
|
||||
}
|
||||
|
||||
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2022
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.yshop.module.pay.controller.app;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.CommonResult;
|
||||
import co.yixiang.yshop.framework.security.core.annotations.PreAuthenticated;
|
||||
import co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import co.yixiang.yshop.module.member.api.user.MemberUserApi;
|
||||
import co.yixiang.yshop.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
import co.yixiang.yshop.module.pay.controller.app.vo.AppPayParam;
|
||||
import co.yixiang.yshop.module.pay.dal.dataobject.merchantdetails.MerchantDetailsDO;
|
||||
import co.yixiang.yshop.module.pay.enums.PayOrderConstants;
|
||||
import co.yixiang.yshop.module.pay.enums.PayTypeEnum;
|
||||
import co.yixiang.yshop.module.pay.processor.PayOrderProcessor;
|
||||
import co.yixiang.yshop.module.pay.service.merchantdetails.MerchantDetailsService;
|
||||
import co.yixiang.yshop.module.pay.strategy.PayClient;
|
||||
import co.yixiang.yshop.module.pay.strategy.PayClientFactory;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisUtils;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
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.annotation.Resource;
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
import static co.yixiang.yshop.module.order.enums.ErrorCodeConstants.USER_NOT_BINDING_WX;
|
||||
import static co.yixiang.yshop.module.order.enums.ErrorCodeConstants.USER_NOT_BINDING_WX_APPLET;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
/**
|
||||
* 统一支付
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
@Tag(name = "APP - 支付模块")
|
||||
@RequestMapping("/pay")
|
||||
public class AppPayController {
|
||||
|
||||
@Resource
|
||||
private PayClientFactory payClientFactory;
|
||||
|
||||
@Resource
|
||||
private PayOrderProcessor payOrderProcessor;
|
||||
|
||||
@Resource
|
||||
private MerchantDetailsService merchantDetailsService;
|
||||
|
||||
@Resource
|
||||
private MemberUserApi memberUserApi;
|
||||
|
||||
@PreAuthenticated
|
||||
@PostMapping(value = "/payment")
|
||||
@Operation(summary = "统一支付")
|
||||
public CommonResult<Map<String, String>> payment(@Valid @RequestBody AppPayParam param) throws Exception {
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
log.info("=========进入统一支付,param参数:{}", param.toString());
|
||||
MerchantDetailsDO merchantDetailsDO = merchantDetailsService.getMerchantByType(param.getPayType());
|
||||
// 获取支付客户端
|
||||
PayClient client = payClientFactory.getClient(param.getPayType());
|
||||
// 处理规则
|
||||
PayParam payParam = payOrderProcessor.getPayParam(param.getOrderId(), param.getPayType());
|
||||
log.info("=========处理规则后,payParam参数:{}", payParam.toString());
|
||||
//如果是小程序或APP 先获取用户openid
|
||||
MemberUserRespDTO user = memberUserApi.getUser(userId);
|
||||
|
||||
log.info("=========用戶,MemberUserRespDTO参数:{}", user.toString());
|
||||
if (PayTypeEnum.WEIXIN_APPLET.getType().equals(param.getPayType())) {
|
||||
//小程序支付需要openid
|
||||
if (Objects.isNull(user.getRoutineOpenId())) throw exception(USER_NOT_BINDING_WX_APPLET);
|
||||
}
|
||||
if (PayTypeEnum.WEIXIN.getType().equals(param.getPayType())) {
|
||||
//小程序支付需要openid
|
||||
if (Objects.isNull(user.getRoutineOpenId())) throw exception(USER_NOT_BINDING_WX);
|
||||
}
|
||||
payParam.setType(param.getPayType());
|
||||
payParam.setMerchantDetailsDO(merchantDetailsDO);
|
||||
payParam.setUid(userId);
|
||||
// 拉起支付
|
||||
Map<String, String> payment = client.payment(payParam);
|
||||
log.info("=========拉起支付,payment:{}", payParam);
|
||||
payOrderProcessor.handelWait(param.getOrderId(), payment);
|
||||
return success(payment);
|
||||
}
|
||||
|
||||
@RequestMapping("/wxPayNotify")
|
||||
@Operation(summary = "统一微信支付回调")
|
||||
@PermitAll
|
||||
public void wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
// 处理回调
|
||||
payOrderProcessor.handleWeChatPayNotify(request);
|
||||
response.getWriter().write(PayOrderConstants.WEINXIN_RESULT);
|
||||
}
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@RequestMapping("/flush")
|
||||
@Operation(summary = "清空redis")
|
||||
@PermitAll
|
||||
public void flush () throws Exception {
|
||||
redisTemplate.execute((RedisCallback<Void>) connection -> {
|
||||
connection.flushDb();
|
||||
return null;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package co.yixiang.yshop.module.pay.controller.app.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName PayDto
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2013/6/20
|
||||
**/
|
||||
@Data
|
||||
public class AppPayParam implements Serializable {
|
||||
|
||||
@Schema(description = "来源", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String from;
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
@NotBlank(message = "选择支付类型 PayTypeEnum类型(weixin_h5|weixin_applet|weixin_app)")
|
||||
@Schema(description = "支付类型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String payType;
|
||||
|
||||
@NotBlank(message = "参数错误")
|
||||
@Schema(description = "支付订单ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String orderId;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package co.yixiang.yshop.module.pay.processor;
|
||||
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付订单处理器
|
||||
*/
|
||||
public interface PayOrderProcessor {
|
||||
|
||||
// 获取支付参数
|
||||
PayParam getPayParam(String orderId, String payType);
|
||||
|
||||
// 处理待支付
|
||||
void handelWait(String orderId, Map<String, String> packageParams);
|
||||
|
||||
void handleWeChatPayNotify(HttpServletRequest request) throws Exception;
|
||||
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
package co.yixiang.yshop.module.pay.processor;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.yshop.framework.common.util.servlet.ServletUtils;
|
||||
import co.yixiang.yshop.module.member.api.user.MemberUserApi;
|
||||
import co.yixiang.yshop.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import co.yixiang.yshop.module.order.api.productorder.ProductOrderApi;
|
||||
import co.yixiang.yshop.module.order.api.productorder.dto.ProductOrderDTO;
|
||||
import co.yixiang.yshop.module.order.api.rechargeorder.RechargeOrderApi;
|
||||
import co.yixiang.yshop.module.order.api.rechargeorder.dto.RechargeOrderDTO;
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
import co.yixiang.yshop.module.pay.dal.dataobject.merchantdetails.MerchantDetailsDO;
|
||||
import co.yixiang.yshop.module.pay.enums.PayOrderConstants;
|
||||
import co.yixiang.yshop.module.pay.enums.PayTypeEnum;
|
||||
import co.yixiang.yshop.module.pay.service.merchantdetails.MerchantDetailsService;
|
||||
import co.yixiang.yshop.module.pay.strategy.weixin.skd.HttpKit;
|
||||
import co.yixiang.yshop.module.pay.strategy.weixin.skd.PaymentKit;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static co.yixiang.yshop.module.order.enums.ErrorCodeConstants.USER_NOT_BINDING_WX_APPLET;
|
||||
|
||||
/**
|
||||
* 支付订单处理器实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PayOrderProcessorImpl implements PayOrderProcessor {
|
||||
|
||||
@Resource
|
||||
private MemberUserApi memberUserApi;
|
||||
|
||||
@Resource
|
||||
private RechargeOrderApi rechargeOrderApi;
|
||||
|
||||
@Resource
|
||||
private ProductOrderApi productOrderApi;
|
||||
|
||||
@Resource
|
||||
private MerchantDetailsService merchantDetailsService;
|
||||
|
||||
@Override
|
||||
public PayParam getPayParam(String orderId, String payType) {
|
||||
Long userId = getLoginUserId();
|
||||
MemberUserRespDTO user = memberUserApi.getUser(userId);
|
||||
if (PayTypeEnum.WEIXIN_APPLET.getType().equals(payType)) {
|
||||
//小程序支付需要openid
|
||||
if (Objects.isNull(user.getRoutineOpenId())) throw exception(USER_NOT_BINDING_WX_APPLET);
|
||||
}
|
||||
// 充值参数
|
||||
PayParam payParam = new PayParam();
|
||||
payParam.setOrderId(orderId);
|
||||
payParam.setOpenId(user.getRoutineOpenId());
|
||||
payParam.setIp(ServletUtils.getClientIP());
|
||||
payParam.setPayDesc(PayOrderConstants.PAY_DESC);
|
||||
|
||||
// 判断是否为充值
|
||||
if (StrUtil.startWith(orderId, PayOrderConstants.RECHARGE_ORDER_PREFIX)){
|
||||
RechargeOrderDTO rechargeOrderDTO = rechargeOrderApi.getPayParam(orderId);
|
||||
payParam.setMoney(new BigDecimal(rechargeOrderDTO.getRechargeAmount()));
|
||||
payParam.setRedirectType(PayOrderConstants.RECHARGE_REDIRECT_URL);
|
||||
}else {
|
||||
// 不是充值就是购买
|
||||
ProductOrderDTO productOrderDTO = productOrderApi.getPayParam(orderId);
|
||||
payParam.setMoney(productOrderDTO.getAmount());
|
||||
payParam.setRedirectType(PayOrderConstants.PAY_REDIRECT_URL);
|
||||
}
|
||||
|
||||
return payParam;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handelWait(String orderId, Map<String, String> packageParams) {
|
||||
// 判断是否为充值
|
||||
if (StrUtil.startWith(orderId, PayOrderConstants.RECHARGE_ORDER_PREFIX)) {
|
||||
// 充值
|
||||
|
||||
}else {
|
||||
// 不是充值就是购买
|
||||
productOrderApi.handleOrder(orderId, packageParams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleWeChatPayNotify(HttpServletRequest request) throws Exception {
|
||||
log.info("进入微信支付回调");
|
||||
String xmlMsg = HttpKit.readData(request);
|
||||
log.info("微信回调通知信息" + xmlMsg);
|
||||
if (StringUtils.isEmpty(xmlMsg)) {
|
||||
log.info("回调接口内容为空!");
|
||||
return;
|
||||
}
|
||||
Map<String, String> resultMap = PaymentKit.xmlToMap(xmlMsg);
|
||||
//验签
|
||||
MerchantDetailsDO merchantDetailsDO = merchantDetailsService.getMerchantDetails("4");
|
||||
boolean validSignResult = PaymentKit.verifyNotify(resultMap, merchantDetailsDO.getKeyPrivate());
|
||||
log.info("验签结果{}", validSignResult);
|
||||
if (MapUtils.isEmpty(resultMap)) {
|
||||
log.info("map为null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resultMap.get("return_code").equals("SUCCESS")) {
|
||||
log.info("return_code不是SUCCESS");
|
||||
return;
|
||||
}
|
||||
String orderNo = resultMap.get("out_trade_no");
|
||||
log.info("回调out_trade_no=" + orderNo);
|
||||
log.info("回调transaction_id=" + resultMap.get("transaction_id"));
|
||||
//截取订单编号
|
||||
String[] split = orderNo.split("-");
|
||||
if (split.length == 0) {
|
||||
log.info("截取id为null");
|
||||
}
|
||||
String orderId = split[0];
|
||||
if (StringUtils.isEmpty(orderId)) {
|
||||
log.info("orderId为null");
|
||||
}
|
||||
// 判断是否为充值
|
||||
if (StrUtil.startWith(orderId, PayOrderConstants.RECHARGE_ORDER_PREFIX)) {
|
||||
// 充值
|
||||
rechargeOrderApi.handleWeChatPayNotify(orderId);
|
||||
}else {
|
||||
// 不是充值就是购买
|
||||
productOrderApi.handleWeChatPayNotify(orderId, resultMap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -43,6 +43,8 @@ public interface MerchantDetailsService {
|
||||
*/
|
||||
MerchantDetailsDO getMerchantDetails(String id);
|
||||
|
||||
MerchantDetailsDO getMerchantByType(String type);
|
||||
|
||||
/**
|
||||
* 获得支付服务商配置列表
|
||||
*
|
||||
|
||||
@ -64,6 +64,11 @@ public class MerchantDetailsServiceImpl implements MerchantDetailsService {
|
||||
return merchantDetailsMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MerchantDetailsDO getMerchantByType(String type) {
|
||||
return merchantDetailsMapper.selectOne(MerchantDetailsDO::getPayType, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MerchantDetailsDO> getMerchantDetailsList(Collection<String> ids) {
|
||||
return merchantDetailsMapper.selectBatchIds(ids);
|
||||
|
||||
@ -4,6 +4,6 @@ import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface Pay {
|
||||
public interface Pay{
|
||||
Map<String,String> selectPayWay(String payCode, PayParam param) throws Exception;
|
||||
}
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package co.yixiang.yshop.module.pay.strategy;
|
||||
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付客户端
|
||||
*/
|
||||
public interface PayClient {
|
||||
|
||||
/**
|
||||
* 获取支付信息
|
||||
* @return 支付信息
|
||||
*/
|
||||
Map<String, String> payment(PayParam param) throws Exception;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package co.yixiang.yshop.module.pay.strategy;
|
||||
|
||||
/**
|
||||
* 获取支付方式工厂
|
||||
*/
|
||||
public interface PayClientFactory {
|
||||
|
||||
/**
|
||||
* 获取支付客户端
|
||||
* @param payType 支付类型
|
||||
* @return 支付客户端
|
||||
*/
|
||||
PayClient getClient(String payType);
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package co.yixiang.yshop.module.pay.strategy;
|
||||
|
||||
import co.yixiang.yshop.module.order.api.productorder.ProductOrderApi;
|
||||
import co.yixiang.yshop.module.pay.enums.PayTypeEnum;
|
||||
import co.yixiang.yshop.module.pay.strategy.type.AliPay;
|
||||
import co.yixiang.yshop.module.pay.strategy.type.IntegralPay;
|
||||
import co.yixiang.yshop.module.pay.strategy.type.NowMoneyPay;
|
||||
import co.yixiang.yshop.module.pay.strategy.type.WeChatPay;
|
||||
import co.yixiang.yshop.module.pay.strategy.weixin.service.WxPayServiceUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.pay.enums.ErrorCodeConstants.PAY_TYPE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 支付工厂实现
|
||||
*/
|
||||
@Component
|
||||
public class PayClientFactoryImpl implements PayClientFactory {
|
||||
|
||||
@Resource
|
||||
private WxPayServiceUtils wxPayServiceUtils;
|
||||
@Resource
|
||||
private ProductOrderApi productOrderApi;
|
||||
|
||||
@Override
|
||||
public PayClient getClient(String payType) {
|
||||
// 支付类型
|
||||
PayTypeEnum type = PayTypeEnum.toType(payType);
|
||||
|
||||
switch (type) {
|
||||
// 微信
|
||||
case WEIXIN:
|
||||
case WEIXIN_H5:
|
||||
case WEIXIN_APPLET:
|
||||
case WEIXIN_APP:
|
||||
return new WeChatPay(wxPayServiceUtils);
|
||||
case YUE:
|
||||
return new NowMoneyPay(productOrderApi);
|
||||
case INTEGRAL:
|
||||
return new IntegralPay();
|
||||
}
|
||||
throw exception(PAY_TYPE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@ package co.yixiang.yshop.module.pay.strategy;
|
||||
|
||||
import co.yixiang.yshop.module.pay.strategy.type.AliPay;
|
||||
import co.yixiang.yshop.module.pay.strategy.type.WeChatPay;
|
||||
import co.yixiang.yshop.module.pay.strategy.type.YuePay;
|
||||
import co.yixiang.yshop.module.pay.strategy.type.NowMoneyPay;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -18,7 +18,6 @@ public class PayFactory {
|
||||
static {
|
||||
PayMap.put(PayEnum.ALI.getCode(),new AliPay());
|
||||
PayMap.put(PayEnum.WEIXIN.getCode(),new WeChatPay());
|
||||
PayMap.put(PayEnum.YUE.getCode(),new YuePay());
|
||||
}
|
||||
|
||||
public Pay create(String payCode){
|
||||
|
||||
@ -1,20 +1,15 @@
|
||||
package co.yixiang.yshop.module.pay.strategy.type;
|
||||
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
import co.yixiang.yshop.module.pay.enums.PayTypeEnum;
|
||||
import co.yixiang.yshop.module.pay.strategy.Pay;
|
||||
import co.yixiang.yshop.module.pay.strategy.weixin.skd.RandomStringUtil;
|
||||
import com.egzosn.pay.spring.boot.core.bean.MerchantPayOrder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import co.yixiang.yshop.module.pay.strategy.PayClient;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class AliPay implements Pay {
|
||||
|
||||
public class AliPay implements PayClient {
|
||||
|
||||
@Override
|
||||
public Map<String,String> selectPayWay(String payCode, PayParam param) throws Exception{
|
||||
public Map<String,String> payment(PayParam param) throws Exception{
|
||||
|
||||
return Collections.emptyMap();
|
||||
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package co.yixiang.yshop.module.pay.strategy.type;
|
||||
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
import co.yixiang.yshop.module.pay.strategy.PayClient;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class IntegralPay implements PayClient {
|
||||
|
||||
@Override
|
||||
public Map<String,String> payment(PayParam param) throws Exception{
|
||||
//do something
|
||||
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package co.yixiang.yshop.module.pay.strategy.type;
|
||||
|
||||
import co.yixiang.yshop.module.order.api.productorder.ProductOrderApi;
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
import co.yixiang.yshop.module.pay.strategy.PayClient;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class NowMoneyPay implements PayClient {
|
||||
private final ProductOrderApi productOrderApi;
|
||||
|
||||
public NowMoneyPay(ProductOrderApi productOrderApi) {
|
||||
this.productOrderApi = productOrderApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,String> payment(PayParam param) throws Exception{
|
||||
productOrderApi.yuePay(param.getOrderId(),param.getUid());
|
||||
//do something
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
@ -1,26 +1,27 @@
|
||||
package co.yixiang.yshop.module.pay.strategy.type;
|
||||
|
||||
import co.yixiang.yshop.module.pay.controller.admin.merchantdetails.vo.PayParam;
|
||||
import co.yixiang.yshop.module.pay.enums.PayTypeEnum;
|
||||
import co.yixiang.yshop.module.pay.strategy.Pay;
|
||||
import co.yixiang.yshop.module.pay.strategy.PayClient;
|
||||
import co.yixiang.yshop.module.pay.strategy.weixin.service.WxPayServiceUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WeChatPay implements Pay {
|
||||
public class WeChatPay implements PayClient {
|
||||
|
||||
@Resource
|
||||
private WxPayServiceUtils wxPayServiceUtils;
|
||||
|
||||
public WeChatPay(){
|
||||
}
|
||||
|
||||
public WeChatPay(WxPayServiceUtils wxPayServiceUtils){
|
||||
this.wxPayServiceUtils = wxPayServiceUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> selectPayWay(String payCode, PayParam param) throws Exception {
|
||||
//根据微信type选择不同的支付 H5/APPLET/APP
|
||||
if (Objects.equals(param.getType(), PayTypeEnum.WEIXIN_H5.getValue()) ||
|
||||
Objects.equals(param.getType(), PayTypeEnum.WEIXIN_APP.getValue()) ||
|
||||
Objects.equals(param.getType(), PayTypeEnum.WEIXIN_APPLET.getValue())
|
||||
) {
|
||||
return new WxPayServiceUtils().gotoPay(param);
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
public Map<String, String> payment(PayParam param) throws Exception {
|
||||
// 支付
|
||||
return wxPayServiceUtils.gotoPay(param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,21 +68,28 @@ public class WxPayServiceUtils implements InitializingBean {
|
||||
//获取商户信息
|
||||
//h5
|
||||
String outTradeNo = "";
|
||||
if(PayTypeEnum.WEIXIN_H5.getValue().equals(param.getType())){
|
||||
if(PayTypeEnum.WEIXIN_H5.getType().equals(param.getType())){
|
||||
outTradeNo=param.getOrderId()+"-"+ RandomStringUtil.getRandomCode(3,0)+"H5";
|
||||
reqParams.put("appid", param.getMerchantDetailsDO().getAppid());
|
||||
//交易类型
|
||||
reqParams.put("trade_type", "MWEB");
|
||||
}else if(PayTypeEnum.WEIXIN_APP.getValue().equals(param.getType())){
|
||||
}else if(PayTypeEnum.WEIXIN_APP.getType().equals(param.getType())){
|
||||
//微信app分配的APPID
|
||||
//app_appid
|
||||
outTradeNo=param.getOrderId()+"-"+ RandomStringUtil.getRandomCode(3,0)+"APP";
|
||||
reqParams.put("appid", param.getMerchantDetailsDO().getAppid());
|
||||
//交易类型
|
||||
reqParams.put("trade_type", "APP");
|
||||
}else if(PayTypeEnum.WEIXIN_APPLET.getValue().equals(param.getType())){
|
||||
}else if(PayTypeEnum.WEIXIN_APPLET.getType().equals(param.getType())){
|
||||
//微信app分配的APPID
|
||||
reqParams.put("openid",param.getOpenid());
|
||||
reqParams.put("openid",param.getOpenId());
|
||||
outTradeNo=param.getOrderId()+"-"+ RandomStringUtil.getRandomCode(3,0)+"APPLET";
|
||||
reqParams.put("appid", param.getMerchantDetailsDO().getAppid());
|
||||
//交易类型
|
||||
reqParams.put("trade_type", "JSAPI");
|
||||
}else {
|
||||
//微信app分配的APPID
|
||||
reqParams.put("openid",param.getOpenId());
|
||||
outTradeNo=param.getOrderId()+"-"+ RandomStringUtil.getRandomCode(3,0)+"APPLET";
|
||||
reqParams.put("appid", param.getMerchantDetailsDO().getAppid());
|
||||
//交易类型
|
||||
@ -139,8 +146,8 @@ public class WxPayServiceUtils implements InitializingBean {
|
||||
Map map = PaymentApi.queryByOutTradeNo(param.getMerchantDetailsDO().getAppid(),param.getMerchantDetailsDO().getMchId(),param.getMerchantDetailsDO().getKeyPrivate(),outTradeNo);
|
||||
log.info("查询到微信订单信息:" + map.toString());
|
||||
// payInfo.setTransaction_id(map.get("transaction_id"))
|
||||
if (PayTypeEnum.WEIXIN_H5.getValue().equals(param.getType())) {
|
||||
packageParams.put("mwebUrl", result.get("mweb_url") + "&redirect_url="+ URLEncoder.encode(param.getMerchantDetailsDO().getReturnUrl(), "GBK"));
|
||||
if (PayTypeEnum.WEIXIN_H5.getType().equals(param.getType())) {
|
||||
packageParams.put("mwebUrl", result.get("mweb_url") + "&redirect_url="+ URLEncoder.encode(param.getMerchantDetailsDO().getReturnUrl() + param.getRedirectType(), "GBK"));
|
||||
}
|
||||
return packageParams;
|
||||
}
|
||||
|
||||
@ -9,12 +9,8 @@ import co.yixiang.yshop.module.pay.strategy.weixin.skd.RandomStringUtil;
|
||||
import co.yixiang.yshop.module.pay.strategy.weixin.skd.WXPayUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
@ -72,19 +68,19 @@ public class WxPayServiceImpl implements WxPayService {
|
||||
//获取商户信息
|
||||
//h5
|
||||
String outTradeNo = "";
|
||||
if(PayTypeEnum.WEIXIN_H5.getValue().equals(type)){
|
||||
if(PayTypeEnum.WEIXIN_H5.getType().equals(type)){
|
||||
outTradeNo=orderId+"-"+ RandomStringUtil.getRandomCode(3,0)+"H5";
|
||||
reqParams.put("appid", merchantDetailsDO.getAppid());
|
||||
//交易类型
|
||||
reqParams.put("trade_type", "MWEB");
|
||||
}else if(PayTypeEnum.WEIXIN_APP.getValue().equals(type)){
|
||||
}else if(PayTypeEnum.WEIXIN_APP.getType().equals(type)){
|
||||
//微信app分配的APPID
|
||||
//app_appid
|
||||
outTradeNo=orderId+"-"+ RandomStringUtil.getRandomCode(3,0)+"APP";
|
||||
reqParams.put("appid", merchantDetailsDO.getAppid());
|
||||
//交易类型
|
||||
reqParams.put("trade_type", "APP");
|
||||
}else if(PayTypeEnum.WEIXIN_APPLET.getValue().equals(type)){
|
||||
}else if(PayTypeEnum.WEIXIN_APPLET.getType().equals(type)){
|
||||
//微信app分配的APPID
|
||||
//app_appid
|
||||
outTradeNo=orderId+"-"+ RandomStringUtil.getRandomCode(3,0)+"APPLET";
|
||||
@ -143,7 +139,7 @@ public class WxPayServiceImpl implements WxPayService {
|
||||
Map map = PaymentApi.queryByOutTradeNo(merchantDetailsDO.getAppid(),merchantDetailsDO.getMchId(),merchantDetailsDO.getKeyPrivate(),outTradeNo);
|
||||
log.info("查询到微信订单信息:" + map.toString());
|
||||
// payInfo.setTransaction_id(map.get("transaction_id"))
|
||||
if (PayTypeEnum.WEIXIN_H5.getValue().equals(type)) {
|
||||
if (PayTypeEnum.WEIXIN_H5.getType().equals(type)) {
|
||||
packageParams.put("mwebUrl", result.get("mweb_url") + "&redirect_url="+ URLEncoder.encode(merchantDetailsDO.getReturnUrl(), "GBK"));
|
||||
}
|
||||
return packageParams;
|
||||
|
||||
Reference in New Issue
Block a user