diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/AliPayConfig.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/AliPayConfig.java new file mode 100644 index 000000000..ac2eeca24 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/AliPayConfig.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.framework.pay.config; + +import cn.iocoder.yudao.framework.pay.properties.AliPayProperties; +import cn.iocoder.yudao.framework.pay.properties.WxPayProperties; +import com.alipay.api.AlipayClient; +import com.alipay.api.DefaultAlipayClient; +import com.github.binarywang.wxpay.service.WxPayService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @Title:AliPayConfig + * @Description: TODO + * @author: tangqian + * @date: 2023/5/16 13:29 + * @version: V1.0.0 + */ +@Configuration +@ConditionalOnClass(AlipayClient.class) +@EnableConfigurationProperties(AliPayProperties.class) +@ConditionalOnProperty(prefix = "ali.pay.one", value = "enabled", matchIfMissing = true) +public class AliPayConfig { + private AliPayProperties aliPayProperties; + + @Autowired + public AliPayConfig(AliPayProperties aliPayProperties) { + this.aliPayProperties = aliPayProperties; + } + @Bean + @ConditionalOnMissingBean(AlipayClient.class) + public AlipayClient alipayClient() { + return new DefaultAlipayClient(aliPayProperties.getGatewayUrl(), aliPayProperties.getAppId(), + aliPayProperties.getMerchantPrivateKey(), "json", "UTF-8", aliPayProperties.getAlipayPublicKey(), "RSA2"); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/AliPayProperties.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/AliPayProperties.java new file mode 100644 index 000000000..44d11e9f3 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/properties/AliPayProperties.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.framework.pay.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @Title:AliPayProperties + * @Description: TODO + * @author: tangqian + * @date: 2023/5/16 13:35 + * @version: V1.0.0 + */ +@Data +@Component +@ConfigurationProperties(prefix = AliPayProperties.PREFIX) +public class AliPayProperties { + public static final String PREFIX = "ali.pay.one"; + /** + * appId. + */ + private String appId; + /** + * 私钥. + */ + private String merchantPrivateKey; + /** + * 公钥. + */ + private String alipayPublicKey; + /** + * 支付宝网关. + */ + private String gatewayUrl; + /** + * 回调地址. + */ + private String notifyUrl; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 3a42b1c47..84f15f29a 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,3 +1,4 @@ cn.iocoder.yudao.framework.pay.config.YudaoPayAutoConfiguration cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration -cn.iocoder.yudao.framework.pay.config.WxPayTwoAutoConfiguration \ No newline at end of file +cn.iocoder.yudao.framework.pay.config.WxPayTwoAutoConfiguration +cn.iocoder.yudao.framework.pay.config.AliPayConfig \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderContentRequest.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderContentRequest.java new file mode 100644 index 000000000..94ab77d3b --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderContentRequest.java @@ -0,0 +1,60 @@ +package cn.iocoder.yudao.module.shop.request.member; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * @Title:OrderContentRequest + * @Description: 会员充值下单入参 + * @author: tangqian + * @date: 2023/5/15 20:45 + * @version: V1.0.0 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description="会员充值下单请求入参") +public class OrderContentRequest implements Serializable { + private static final long serialVersionUID = -9170167938995005780L; + @Schema(description = "用户电话") + private String userPhone; + + @Schema(description = "确认手机号") + private String confirmPhone; + + @Schema(description = "openid(支付者微信支付)") + private String openid; + + @Schema(description = "支付类型 支付宝ALIPAY 微信WXPAY") + @NotEmpty(message = "支付类型不能为空") + private String payType; + + @Schema(description = "订单信息") + private List orderInfos; + @Data + public static class OrderInfo implements Serializable{ + private static final long serialVersionUID = -4967251473044468810L; + @Schema(description = "订单id") + @NotNull(message = "挡位id不能为空") + private Integer gearId; + + @Schema(description = "档位名称") + @NotEmpty(message = "挡位名称不能为空") + private String name; + + @Schema(description = "挡位备注不能为空") + @NotEmpty(message = "挡位备注不能为空") + private String gearRemarks; + + @Schema(description = "挡位金额不能为空") + @NotNull(message = "挡位金额不能为空") + private Integer gearAmount; + } +} diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderPayRequest.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderPayRequest.java new file mode 100644 index 000000000..cc02169c8 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderPayRequest.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.shop.request.member; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; + +/** + * @Title:OrderPayRequest + * @Description: 订单选择支付方式发起支付入参 + * @author: tangqian + * @date: 2023/5/15 20:54 + * @version: V1.0.0 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description="订单选择支付方式发起支付入参") +public class OrderPayRequest implements Serializable { + private static final long serialVersionUID = 6720933184418303650L; + + @Schema(description = "订单id") + @NotEmpty(message = "orderId不能为空") + private String orderId; + + @Schema(description = "支付类型 支付宝ALIPAY 微信WXPAY") + @NotEmpty(message = "支付类型不能为空") + private String payType; + +} diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/RefundRequest.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/RefundRequest.java new file mode 100644 index 000000000..afba30285 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/RefundRequest.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.shop.request.member; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * @Title:OrderContentRequest + * @Description: 退款入参 + * @author: tangqian + * @date: 2023/5/15 20:45 + * @version: V1.0.0 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description="退款") +public class RefundRequest implements Serializable { + private static final long serialVersionUID = -9170167938995005780L; + @Schema(description = "数据id") + private String orderId; + + +} diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/AliPayOrderResponse.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/AliPayOrderResponse.java new file mode 100644 index 000000000..bbdae987b --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/AliPayOrderResponse.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.shop.response.member; + +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * @Title:AliPayOrderResponse + * @Description: TODO + * @author: tangqian + * @date: 2023/5/15 21:09 + * @version: V1.0.0 + */ +@Data +@Accessors(chain = true) +public class AliPayOrderResponse extends PayResponse { + //支付宝统一下单返回参数 + private String body; +} diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/ChangeOrderPayTypeResponse.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/ChangeOrderPayTypeResponse.java new file mode 100644 index 000000000..596505058 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/ChangeOrderPayTypeResponse.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.shop.response.member; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * @Title:ChangeOrderPayTypeResponse + * @Description: 订单选择订单支付方式-返回参数 + * @author: tangqian + * @date: 2023/5/15 21:05 + * @version: V1.0.0 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description="订单选择订单支付方式-返回参数") +public class ChangeOrderPayTypeResponse implements Serializable { + private static final long serialVersionUID = -4147278073881962962L; + @Schema(description = "订单id") + private String orderId; + + @Schema(description = "支付类型 支付宝ALIPAY 微信WXPAY") + private String payType; + + @Schema(description = "订单金额(分)") + private String orderPay; + + @Schema(description = "需要支付金额(分)") + private String needPay; + + @Schema(description = "商品名称") + private String goodsName; + + @Schema(description = "此参数根据支付类型的不同,返回的参数有所不同。") + private PayResponse orderInfo; +} diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/InitOrderResponse.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/InitOrderResponse.java new file mode 100644 index 000000000..d5cd2df2a --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/InitOrderResponse.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.shop.response.member; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +/** + * @Title:InitOrderResponse + * @Description: TODO + * @author: tangqian + * @date: 2023/5/15 21:20 + * @version: V1.0.0 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description="预下单返回参数") +public class InitOrderResponse implements Serializable { + private static final long serialVersionUID = 6894715033655337607L; + + @Schema(description = "h5_url") + private String h5Url; + + @Schema(description ="二维码链接") + private String codeUrl; +} diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/PayResponse.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/PayResponse.java new file mode 100644 index 000000000..eda911eea --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/PayResponse.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.shop.response.member; + +import java.io.Serializable; + +/** + * @Title:PayResponse + * @Description: 根据支付返回父类 + * @author: tangqian + * @date: 2023/5/15 21:06 + * @version: V1.0.0 + */ +public class PayResponse implements Serializable { + private static final long serialVersionUID = 9219937300257494629L; +} diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/WxPayOrderResponse.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/WxPayOrderResponse.java new file mode 100644 index 000000000..e909dd55e --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/WxPayOrderResponse.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.shop.response.member; + +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * @Title:WxPayOrderResponse + * @Description: TODO + * @author: tangqian + * @date: 2023/5/15 21:11 + * @version: V1.0.0 + */ +@Data +@Accessors(chain = true) +public class WxPayOrderResponse extends PayResponse{ + //交易类型 + private String tradeType; + //预支付ID + private String prepayId; + //支付跳转链接 + private String mwebUrl; +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java new file mode 100644 index 000000000..1f107cfaa --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.shop.controller.admin.notify; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.shop.service.order.StoreOrderService; +import io.swagger.v3.oas.annotations.tags.Tag; +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 java.util.Map; + +/** + * @Title:AliPayNotifyController + * @Description: TODO + * @author: tangqian + * @date: 2023/5/16 16:45 + * @version: V1.0.0 + */ +@Slf4j +@RequestMapping("notify/ali") +@RestController +@Tag(name = "支付宝支付回调 - 订单支付") +public class AliPayNotifyController { + @Autowired + private StoreOrderService storeOrderService; + + @PostMapping("pay_notify") + public CommonResult payNotify(HttpServletRequest request, @RequestBody Map params) { + return CommonResult.success(storeOrderService.aliNotify(request, params)); + } + + @PostMapping("refund_notify") + public CommonResult refundNotify(HttpServletRequest request, @RequestBody Map params) { + return CommonResult.success(storeOrderService.refundNotify(request, params)); + } +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/buy/TopUpOrderController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/buy/TopUpOrderController.java new file mode 100644 index 000000000..10ae23ee9 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/buy/TopUpOrderController.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.shop.controller.app.buy; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.shop.request.member.OrderContentRequest; +import cn.iocoder.yudao.module.shop.request.member.RefundRequest; +import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; +import cn.iocoder.yudao.module.shop.service.order.StoreOrderService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +/** + * @Title:TopUpOrderController + * @Description: 会员充值 + * @author: tangqian + * @date: 2023/5/15 20:12 + * @version: V1.0.0 + */ +@Slf4j +@RestController +@RequestMapping("api/order/member") +@Tag(name = "用户 APP - 会员充值订单管理") +public class TopUpOrderController { + + @Autowired + private StoreOrderService storeOrderService; + + @Operation(summary = "会员充值") + @RequestMapping(value = "/memberTopUp", method = RequestMethod.POST) + public CommonResult memberTopUp(@Valid @RequestBody OrderContentRequest request, HttpServletRequest servletRequest) throws Exception { + log.info("initOrder会员充值===>{}", request); + return CommonResult.success(storeOrderService.memberTopUp(request, servletRequest)); + } + + @Operation(summary = "退款") + @RequestMapping(value = "/memberRefund", method = RequestMethod.POST) + public CommonResult memberRefund(@Valid @RequestBody RefundRequest request, HttpServletRequest servletRequest) throws Exception { + log.info("memberRefund会员退款===>{}", request); + return CommonResult.success(storeOrderService.memberRefund(request, servletRequest)); + } + + + +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java index ce078009b..980267c3f 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java @@ -2,15 +2,24 @@ package cn.iocoder.yudao.module.shop.service.order; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder; +import cn.iocoder.yudao.module.shop.request.member.OrderContentRequest; +import cn.iocoder.yudao.module.shop.request.member.OrderPayRequest; +import cn.iocoder.yudao.module.shop.request.member.RefundRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderRefundRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderSearchRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderSendRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderUpdatePriceRequest; +import cn.iocoder.yudao.module.shop.response.member.ChangeOrderPayTypeResponse; +import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; import cn.iocoder.yudao.module.shop.response.order.*; import cn.iocoder.yudao.module.shop.vo.order.LogisticsResultVo; import com.baomidou.mybatisplus.extension.service.IService; +import com.github.binarywang.wxpay.exception.WxPayException; import com.github.pagehelper.PageInfo; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -370,4 +379,23 @@ public interface StoreOrderService extends IService { * @param spreadId 推广人uid */ OrderBrokerageData getBrokerageData(Integer uid, Integer spreadId); + + /** + * 会员充值 + * @param request + * @return + */ + InitOrderResponse memberTopUp(OrderContentRequest request, HttpServletRequest servletRequest) throws WxPayException; + + /** + * 第三方回调 + * @param request + * @param params + * @return + */ + Object aliNotify(HttpServletRequest request, Map params); + + Object memberRefund(RefundRequest request, HttpServletRequest servletRequest); + + Object refundNotify(HttpServletRequest request, Map params); } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java index 29cba6ae6..b951b5294 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java @@ -9,28 +9,44 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.DateLimitUtilVo; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration; +import cn.iocoder.yudao.framework.pay.properties.AliPayProperties; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder; +import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; +import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderInfoDO; import cn.iocoder.yudao.module.shop.dal.mysql.order.StoreOrderMapper; +import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderInfoMapper; +import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderMapper; +import cn.iocoder.yudao.module.shop.request.member.OrderContentRequest; +import cn.iocoder.yudao.module.shop.request.member.RefundRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderRefundRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderSearchRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderSendRequest; import cn.iocoder.yudao.module.shop.request.order.StoreOrderUpdatePriceRequest; +import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; import cn.iocoder.yudao.module.shop.response.order.*; import cn.iocoder.yudao.module.shop.service.order.StoreOrderInfoService; import cn.iocoder.yudao.module.shop.service.order.StoreOrderRefundService; import cn.iocoder.yudao.module.shop.service.order.StoreOrderService; import cn.iocoder.yudao.module.shop.service.order.StoreOrderStatusService; +import cn.iocoder.yudao.module.shop.support.StrategySupport; +import cn.iocoder.yudao.module.shop.support.pay.IPayStrategy; import cn.iocoder.yudao.module.shop.utils.CommonPage; import cn.iocoder.yudao.module.shop.utils.OrderUtil; import cn.iocoder.yudao.module.shop.utils.RedisUtil; import cn.iocoder.yudao.module.shop.vo.order.LogisticsResultVo; import cn.iocoder.yudao.module.shop.vo.order.StoreDateRangeSqlPram; import cn.iocoder.yudao.module.shop.vo.order.StoreOrderInfoOldVo; +import com.alipay.api.AlipayApiException; +import com.alipay.api.internal.util.AlipaySignature; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.Page; @@ -40,14 +56,16 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionTemplate; +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.time.LocalDateTime; +import java.util.*; import java.util.stream.Collectors; /** @@ -90,7 +108,15 @@ public class StoreOrderServiceImpl extends ServiceImpl lqw = new LambdaQueryWrapper<>(); orderUtil.statusApiByWhere(lqw, status); - lqw.eq(StoreOrder::getUid,userId); + lqw.eq(StoreOrder::getUid, userId); return mapper.selectCount(lqw); } @Override public List getOrderGroupByDate(String dateLimit, int lefTime) { QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.select("sum(pay_price) as pay_price", "left(create_time, "+lefTime+") as orderId", "count(id) as id"); + queryWrapper.select("sum(pay_price) as pay_price", "left(create_time, " + lefTime + ") as orderId", "count(id) as id"); if (StringUtils.isNotBlank(dateLimit)) { DateLimitUtilVo dateLimitVo = DateUtils.getDateLimit(dateLimit); queryWrapper.between("create_time", dateLimitVo.getStartTime(), dateLimitVo.getEndTime()); @@ -421,20 +447,20 @@ public class StoreOrderServiceImpl extends ServiceImpl orderPerList = getOrderPayedByDateLimit(perDateStart,dateStart); + List orderPerList = getOrderPayedByDateLimit(perDateStart, dateStart); // 当前时间段 List orderCurrentList = getOrderPayedByDateLimit(dateStart, dateEnd); @@ -443,23 +469,23 @@ public class StoreOrderServiceImpl extends ServiceImpl e.getPayPrice().doubleValue()).sum(); double currentSumPrice = orderCurrentList.stream().mapToDouble(e -> e.getPayPrice().doubleValue()).sum(); - response.setChart(mapper.getOrderStatisticsPriceDetail(new StoreDateRangeSqlPram(dateStart,dateEnd))); - response.setTime(BigDecimal.valueOf(currentSumPrice).setScale(2,BigDecimal.ROUND_HALF_UP)); + response.setChart(mapper.getOrderStatisticsPriceDetail(new StoreDateRangeSqlPram(dateStart, dateEnd))); + response.setTime(BigDecimal.valueOf(currentSumPrice).setScale(2, BigDecimal.ROUND_HALF_UP)); // 当前营业额和上一个同比营业额增长区间 increasePrice = currentSumPrice - perSumPrice; if (increasePrice <= 0) response.setGrowthRate(0); else if (perSumPrice == 0) response.setGrowthRate((int) increasePrice * 100); - else response.setGrowthRate((int)((increasePrice * perSumPrice) * 100)); - }else if (type ==2) { - response.setChart(mapper.getOrderStatisticsOrderCountDetail(new StoreDateRangeSqlPram(dateStart,dateEnd))); + else response.setGrowthRate((int) ((increasePrice * perSumPrice) * 100)); + } else if (type == 2) { + response.setChart(mapper.getOrderStatisticsOrderCountDetail(new StoreDateRangeSqlPram(dateStart, dateEnd))); response.setTime(BigDecimal.valueOf(orderCurrentList.size())); increasePrice = orderCurrentList.size() - orderPerList.size(); if (increasePrice <= 0) response.setGrowthRate(0); else if (orderPerList.size() == 0) response.setGrowthRate((int) increasePrice); - else response.setGrowthRate((int)((increasePrice / orderPerList.size()) * 100)); + else response.setGrowthRate((int) ((increasePrice / orderPerList.size()) * 100)); } - response.setIncreaseTime(increasePrice+""); - response.setIncreaseTimeStatus(increasePrice >= 0 ? 1:2); + response.setIncreaseTime(increasePrice + ""); + response.setIncreaseTimeStatus(increasePrice >= 0 ? 1 : 2); return response; } @@ -532,7 +558,7 @@ public class StoreOrderServiceImpl extends ServiceImpl { // 修改订单价格 @@ -640,7 +666,7 @@ public class StoreOrderServiceImpl extends ServiceImpl params) { + boolean verifyResult = false; + try { + verifyResult = AlipaySignature.rsaCheckV1(params, aliPayProperties.getAlipayPublicKey(), "UTF-8", "RSA2"); + } catch (AlipayApiException e) { + e.printStackTrace(); + } + + if (verifyResult) { + String orderId = params.get("out_trade_no"); + RechargeOrderDO orderDO = rechargeOrderMapper.selectOne(Wrappers.lambdaQuery().eq(RechargeOrderDO::getOrderId, orderId)); + // 处理相关逻辑 + + } + return null; + } + + @Override + public Object memberRefund(RefundRequest request, HttpServletRequest servletRequest) { + RechargeOrderDO orderDO = rechargeOrderMapper.selectById(request.getOrderId()); + // 获取支付策略 + IPayStrategy payStrategy = strategySupport.getPayStrategy(orderDO.getPayType()); + payStrategy.refund(orderDO); + return null; + } + + @Override + public Object refundNotify(HttpServletRequest request, Map params1) { + // 解析支付宝回调参数 + Map params = new HashMap<>(); + Map requestParams = request.getParameterMap(); + for (Map.Entry entry : requestParams.entrySet()) { + String name = entry.getKey(); + String[] values = entry.getValue(); + StringBuilder sb = new StringBuilder(); + for (String value : values) { + sb.append(value); + } + params.put(name, sb.toString()); + } + // 验证签名 + boolean isSignatureValid = false; + try { + isSignatureValid = AlipaySignature.rsaCheckV1(params, aliPayProperties.getAlipayPublicKey(), "UTF-8", "RSA2"); + } catch (AlipayApiException e) { + e.printStackTrace(); + } + if (isSignatureValid) { + // 验证通过,处理退款结果 + String tradeStatus = params.get("trade_status"); + if ("TRADE_SUCCESS".equals(tradeStatus)) { + // 退款成功逻辑 + } else { + // 退款失败逻辑 + } + return "success"; // 返回给支付宝表示接收成功 + } else { + // 签名验证失败 + return "failure"; + } + } + + + private RechargeOrderDO initializeOrder(OrderContentRequest request, String code, MemberUserRespDTO user) { + RechargeOrderDO orderDO = new RechargeOrderDO(); + List orderInfos = request.getOrderInfos(); + orderDO.setOrderId(code); + orderDO.setUid(user.getId().intValue()); + orderDO.setRealName(user.getNickname()); + orderDO.setUserPhone(StringUtils.isEmpty(request.getUserPhone()) ? user.getMobile() : request.getUserPhone()); + orderDO.setConfirmPhone(StringUtils.isEmpty(request.getConfirmPhone()) ? user.getMobile() : request.getConfirmPhone()); + orderDO.setTotalNum(orderInfos.size()); + BigDecimal sum = new BigDecimal(orderInfos.stream().mapToDouble(OrderContentRequest.OrderInfo::getGearAmount).sum()); + orderDO.setTotalPrice(sum); + orderDO.setPayPrice(sum); + orderDO.setPayTime(LocalDateTime.now()); + orderDO.setPayType(request.getPayType()); + orderDO.setMark("会员充值"); + orderDO.setCost(sum); + orderDO.setProTotalPrice(sum); + orderDO.setBeforePayPrice(sum); + rechargeOrderMapper.insert(orderDO); + List infoDOS = new ArrayList<>(); + orderInfos.forEach(info -> { + RechargeOrderInfoDO infoDO = new RechargeOrderInfoDO(); + infoDO.setRechargeOrderId(orderDO.getId()); + infoDO.setGiveIntegral(info.getGearId()); + infoDO.setOrderNo(code); + infoDO.setProductName(info.getName()); + infoDO.setPrice(new BigDecimal(info.getGearAmount())); + infoDO.setPayNum(1); + infoDO.setGiveIntegral(info.getGearAmount()); + infoDOS.add(infoDO); + }); + rechargeOrderInfoMapper.insertBatch(infoDOS); + return orderDO; + } + + /** + * 订单号 + * + * @param prefix + * @return + */ + public static String generateBillNo(String prefix) { + String idStr = IdWorker.getIdStr(); + idStr = prefix + "_" + idStr; + return idStr; + } + + private void orderCheck(OrderContentRequest request) { + Assert.isTrue(!CollectionUtils.isEmpty(request.getOrderInfos()), "订单信息不能为空!"); + if (StringUtils.isNotBlank(request.getUserPhone()) && StringUtils.isNotBlank(request.getConfirmPhone())) { + Assert.isTrue(StringUtils.equals(request.getUserPhone(), request.getConfirmPhone()), "输入号码不一致!"); + MemberUserRespDTO userByMobile = userService.getUserByMobile(request.getUserPhone()); + // 初始化一个账号 + if (Objects.isNull(userByMobile)) { + userService.saveMemberUser(request.getUserPhone()); + } + } + } + + private StoreOrder getInfoException(String orderNo) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.eq(StoreOrder::getOrderId, orderNo); @@ -1111,8 +1278,9 @@ public class StoreOrderServiceImpl extends ServiceImpl getOrderPayedByDateLimit(String startTime, String endTime) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); - lqw.eq(StoreOrder::getIsDel, false).eq(StoreOrder::getPaid, true).eq(StoreOrder::getRefundStatus,0) + lqw.eq(StoreOrder::getIsDel, false).eq(StoreOrder::getPaid, true).eq(StoreOrder::getRefundStatus, 0) .between(StoreOrder::getCreateTime, startTime, endTime); return mapper.selectList(lqw); } - /** 快递 - * @param request StoreOrderSendRequest 发货参数 + /** + * 快递 + * + * @param request StoreOrderSendRequest 发货参数 * @param storeOrder StoreOrder 订单信息 */ private void express(StoreOrderSendRequest request, StoreOrder storeOrder) { @@ -1259,19 +1433,22 @@ public class StoreOrderServiceImpl extends ServiceImpl 订单列表 * @return List */ private List formatOrder1(List orderList) { - List detailResponseList = new ArrayList<>(); + List detailResponseList = new ArrayList<>(); if (CollUtil.isEmpty(orderList)) { return detailResponseList; } @@ -1378,8 +1558,9 @@ public class StoreOrderServiceImpl extends ServiceImpl 表达式 - * @param request StoreOrderSearchRequest 请求参数 + * @param request StoreOrderSearchRequest 请求参数 */ private void getRequestTimeWhere(QueryWrapper queryWrapper, StoreOrderSearchRequest request) { if (StringUtils.isNotBlank(request.getDateLimit())) { @@ -1390,6 +1571,7 @@ public class StoreOrderServiceImpl extends ServiceImpl 表达式 - * @param status String 类型 + * @param status String 类型 */ private void getStatusWhereNew(QueryWrapper queryWrapper, String status) { if (StrUtil.isBlank(status)) { @@ -1554,7 +1737,7 @@ public class StoreOrderServiceImpl extends ServiceImpl 表达式 - * @param status String 类型 + * @param status String 类型 */ private void getStatusWhere(QueryWrapper queryWrapper, String status) { if (StrUtil.isBlank(status)) { @@ -1657,7 +1843,7 @@ public class StoreOrderServiceImpl extends ServiceImpl payMap = new HashMap<>(); + + + public StrategySupport(WxPayStrategy wxPayStrategy, + AliPayStrategy aliPayStrategy + + ) { + //支付策略 + payMap.put(PayConfigConstant.PAY_TYPE_ALIPAY,aliPayStrategy); + payMap.put(PayConfigConstant.PAY_TYPE_WXPAY,wxPayStrategy); + } + + /** + * 根据支付类型查找相对应的支付策略。 + * @param payType + * @return + */ + public IPayStrategy getPayStrategy(String payType){ + if (PayConfigConstant.PAY_TYPE_LIST.contains(payType)){ + return payMap.get(payType); + } + return null; + } + + + + + + +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/AliPayStrategy.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/AliPayStrategy.java new file mode 100644 index 000000000..528046449 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/AliPayStrategy.java @@ -0,0 +1,87 @@ +package cn.iocoder.yudao.module.shop.support.pay; + +import cn.hutool.json.JSONUtil; +import cn.iocoder.yudao.framework.pay.config.AliPayConfig; +import cn.iocoder.yudao.framework.pay.properties.AliPayProperties; +import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; +import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.request.AlipayTradeRefundRequest; +import com.alipay.api.request.AlipayTradeWapPayRequest; +import com.alipay.api.response.AlipayTradeRefundResponse; +import com.alipay.api.response.AlipayTradeWapPayResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Title:AliPayStrategy + * @Description: 支付宝支付策略 + * @author: tangqian + * @date: 2023/5/15 21:52 + * @version: V1.0.0 + */ +@Component +@Slf4j +public class AliPayStrategy implements IPayStrategy { + @Autowired + private AliPayProperties aliPayProperties; + @Autowired + private AliPayConfig aliPayConfig; + + @Override + public InitOrderResponse pay(RechargeOrderDO orderDO, HttpServletRequest servletRequest, String openId) { + AlipayClient alipayClient = aliPayConfig.alipayClient(); + Assert.notNull(alipayClient, "获取支付宝支付配置失败!"); + AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); + //异步接收地址,仅支持http/https,公网可访问 + request.setNotifyUrl(aliPayProperties.getNotifyUrl()); + //同步跳转地址,仅支持http/https + request.setReturnUrl(""); + /******必传参数******/ + JSONObject bizContent = new JSONObject(); + //商户订单号,商家自定义,保持唯一性 + bizContent.put("out_trade_no", orderDO.getOrderId()); + //支付金额,最小值0.01元 + bizContent.put("total_amount", orderDO.getPayPrice()); + //订单标题,不可使用特殊符号 + bizContent.put("subject", "会员充值"); + bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY"); + request.setBizContent(bizContent.toString()); + AlipayTradeWapPayResponse response = null; + try { + response = alipayClient.pageExecute(request); + } catch (AlipayApiException e) { + e.printStackTrace(); + } + if (response.isSuccess()) { + return new InitOrderResponse(); + } + return null; + } + + @Override + public void refund(RechargeOrderDO orderDO) { + AlipayClient alipayClient = aliPayConfig.alipayClient();; + AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); + JSONObject bizContent = new JSONObject(); + bizContent.put("trade_no", orderDO.getPaySerialNumber()); + bizContent.put("refund_amount", orderDO.getPayPrice()); + bizContent.put("out_request_no", orderDO.getOrderId()); + + request.setBizContent(bizContent.toString()); + AlipayTradeRefundResponse response = null; + try { + response = alipayClient.execute(request); + } catch (AlipayApiException e) { + e.printStackTrace(); + } + log.info("退款回调[{}]", JSONUtil.toJsonPrettyStr(response)); + } + +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/IPayStrategy.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/IPayStrategy.java new file mode 100644 index 000000000..c33ba649a --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/IPayStrategy.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.shop.support.pay; + +import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; +import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Title:IPayStrategy + * @Description: 支付策略接口 + * @author: tangqian + * @date: 2023/5/15 21:51 + * @version: V1.0.0 + */ +public interface IPayStrategy { + InitOrderResponse pay(RechargeOrderDO orderDO, HttpServletRequest servletRequest,String openId); + + void refund(RechargeOrderDO orderDO); +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/PayConfigConstant.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/PayConfigConstant.java new file mode 100644 index 000000000..12f5afef9 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/PayConfigConstant.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.shop.support.pay; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Title:PayConfigConstant + * @Description: TODO + * @author: tangqian + * @date: 2023/5/15 21:54 + * @version: V1.0.0 + */ +public interface PayConfigConstant { + List PAY_TYPE_LIST = Arrays.asList("ALIPAY", "WXPAY"); + String PAY_TYPE_ALIPAY = "ALIPAY"; + String PAY_TYPE_WXPAY = "WXPAY"; + Map PAY_NAMES_MAP = new HashMap() { + { + this.put("ALIPAY", "支付宝"); + this.put("WXPAY", "微信"); + } + }; + String PAY_TYPE_ALIPAY_FIRST = "ALIPAY"; + String PAY_TYPE_WXPAY_FIRST = "WXPAY"; + Map PAY_NAMES_MAP_FIRST = new HashMap() { + { + this.put("ALIPAY", "支付宝"); + this.put("WXPAY", "微信"); + } + }; +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/WxPayStrategy.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/WxPayStrategy.java new file mode 100644 index 000000000..4a00ba05a --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/WxPayStrategy.java @@ -0,0 +1,83 @@ +package cn.iocoder.yudao.module.shop.support.pay; + +import cn.hutool.json.JSONUtil; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; +import cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration; +import cn.iocoder.yudao.framework.pay.properties.WxPayProperties; +import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; +import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; +import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request; +import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request; +import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result; +import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result; +import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; +import com.github.binarywang.wxpay.service.WxPayService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; + +/** + * @Title:WxPayStrategy + * @Description: TODO + * @author: tangqian + * @date: 2023/5/15 21:53 + * @version: V1.0.0 + */ +@Component +@Slf4j +public class WxPayStrategy implements IPayStrategy{ + @Autowired + private WxPayOneAutoConfiguration wxPayOneAutoConfiguration; + @Autowired + private WxPayProperties payProperties; + @Override + public InitOrderResponse pay(RechargeOrderDO orderDO, HttpServletRequest servletRequest,String openid) { + InitOrderResponse response = new InitOrderResponse(); + WxPayService wxPayService = wxPayOneAutoConfiguration.wxPayOneService(); + Assert.notNull(wxPayService, "获取微信支付配置失败!"); + WxPayUnifiedOrderV3Request wxPayRequest = new WxPayUnifiedOrderV3Request(); + int sum = orderDO.getPayPrice().multiply(new BigDecimal("100")).intValue(); + wxPayRequest.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(sum)); + wxPayRequest.setDescription("会员充值"); + wxPayRequest.setOutTradeNo(orderDO.getOrderId()); + wxPayRequest.setNotifyUrl(payProperties.getNotifyUrl()); + wxPayRequest.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(openid)); + wxPayRequest.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(ServletUtils.getClientIP(servletRequest))); + wxPayRequest.setAppid(payProperties.getAppId()); + wxPayRequest.setMchid(payProperties.getMchId()); + try { + WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = wxPayService.unifiedOrderV3(TradeTypeEnum.JSAPI, wxPayRequest); + BeanUtils.copyProperties(wxPayUnifiedOrderV3Result, response); + } catch (Exception e) { + log.error(e.getMessage()); + } + return response; + } + + @Override + public void refund(RechargeOrderDO orderDO) { + WxPayRefundV3Request wxPayRefundV3Request = new WxPayRefundV3Request(); + wxPayRefundV3Request.setOutTradeNo(orderDO.getOrderId()); + wxPayRefundV3Request.setOutRefundNo(orderDO.getPaySerialNumber()); + wxPayRefundV3Request.setTransactionId(orderDO.getOrderId()); + wxPayRefundV3Request.setReason("商品已售完"); + wxPayRefundV3Request.setNotifyUrl(payProperties.getRefundNotifyUrl()); + int sum = orderDO.getPayPrice().multiply(new BigDecimal("100")).intValue(); + wxPayRefundV3Request.setAmount(new WxPayRefundV3Request.Amount().setTotal(sum).setRefund(sum).setCurrency("CNY")); + + try { + WxPayService wxPayService = wxPayOneAutoConfiguration.wxPayOneService(); + WxPayRefundV3Result wxPayRefundV3Result = wxPayService.refundV3(wxPayRefundV3Request); + log.info("退款回调[{}]", JSONUtil.toJsonPrettyStr(wxPayRefundV3Request)); + }catch (Exception e){ + log.error(e.getMessage(),e); + } + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java index 043f1c8f3..5499cccf3 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.api.user; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserBillDTO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import java.util.Collection; @@ -76,4 +77,7 @@ public interface MemberUserApi { Long getUserId(); MemberUserRespDTO getInfo(); + + + void saveMemberUser(String phone); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java index 366766f36..e39100c9d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java @@ -92,6 +92,11 @@ public class MemberUserApiImpl implements MemberUserApi { return UserConvert.INSTANCE.convert2(userService.getUser(getUserId())); } + @Override + public void saveMemberUser(String phone) { + userService.saveMemberUser(phone); + } + /** * 获取个人资料 * diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 6a76ed71a..041e75940 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -116,4 +116,5 @@ public interface MemberUserService { */ int updateById(MemberUserDO member); + void saveMemberUser(String phone); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index fb3c0fd23..4005d4ada 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -170,6 +170,17 @@ public class MemberUserServiceImpl implements MemberUserService { return memberUserMapper.updateById(member); } + @Override + public void saveMemberUser(String phone) { + MemberUserDO memberUserDO = new MemberUserDO(); + memberUserDO.setMobile(phone); + memberUserDO.setNickname("初始化人员"); + memberUserDO.setAvatar(""); + memberUserDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); + memberUserDO.setPassword(passwordEncoder.encode(phone.substring(phone.length() - 6))); + memberUserMapper.insert(memberUserDO); + } + /** * 对密码进行加密 * diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 5e2e4f573..813f7d87f 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -202,7 +202,14 @@ wx: notify-url: http://yuxy.perrymake.com/app-api/pay/wxpay/pay_notify refund-notify-url: http://yuxy.perrymake.com/app-api/pay/wxpay/refund_notify --- #################### 芋道相关配置 #################### - +ali: + pay: + one: + appId: 2021003194654312 + merchantPrivateKey: MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQC+m33MrrmGiSBCBTQMkBH9AN7ZKi/ECmgpjIbVIzAbUThqfiKvuWe8haVq0/F5nETZVYKb3kqqcdt5NkUbGkCrCNCOPvQ2FI8VWOalXGSQNA6ItA644m1dv84Khs5K3Tpu6RgcrL5uqmfNzid7YpLlGeSxMq8uqu/adZnEbm+coJAvEH423pnMjsdkI93FUibaDkDQ06V7Z0Su6l4ZoVzLavvPeP/u8NCvelyf5h+BY159rU8XjCaSYYF/2u4DzDV1LqQcSC+fQg/aVd+QcpnhEF715fbNmN3TLuh1ysnfUSFdVMsdWDrOsgriJ7g0D32uWwhR4Brz3dAFs0KdWTmFAgMBAAECggEBAKdX2JCVbijhx0JvUw0ch856ryw2T41sHZss10vVAu1Y15EXgNiKjLsFEv/BaCX+vquY2XyDI0aVg7zdmrp6x//hU0kvmDTKw/xX+td/UIMSURhQDQThNmeyd/Dh/cfYhu7NEvBJ8T8zuMMFlcBMAO/HVfMErqzoQoCn8wJ0euUkxU+0yWjddC5QHdhPwPgfpmPvL/DCPfSCudFy80ix7CP3YID7RwgCy5niZg3e7aDK6DgYTmk2DmoC7B8ES/7Crvf04fH4XzGrSCzL9aGKOWql6dZisbDioRdm67DEWUSjQGTggEZ+eCd9Tr0gnndVWegG5HYJhSpB/JoLsc5J/dkCgYEA8Tumn60cfJU440LWaJ+40gJWcNrOlvpPEX69DRXKG3PlTAk62sSvVBos2nstqNjhHPQDG7rFerQhmSPeGyezVcwPCbWLvLC61vpbfau+RyWvMvm33A1hgP+zXlt9C3etb9w6LUfuqh0Lzi61K3ZNKQGo4ERxgGoMlNZWO0X/mBMCgYEAykZ9PH1b3be9M55BsnCnnrzENV5Bbfj7BToRleiUWA0f0Juurxy9ZACr8rU1oa7+UF32TpXAOL1Peri5vhYF7hdSnlSk5f9lyEzQijbtRytBC9Mexagb4BZWMlars9jMhhsdWiXA2O6Pz9ykLacGOr0DHM8/6HaVJRlPydXHywcCgYEAzwIgT1/vVR18jtD5SxjdMiJdaUTrCXZNSbcXplXvdLV0rFYzUi58QlCf8vDHUuCh9QWUcURKWKyhNFgqLeVYqKSOtwc6nbaO7xIyVtp9U3KMMNNIKqa06E0E8FDUMnYFuDslFVxn+0Unr0w3nc9MEYdiEunI+KiImWSA5SaBWk8CgYEAlbwshRS/ZpfXZVinhXJDgwx1qpQFl2USXUIpNnGfLrc4b/JvE44Q3PBqWRavhurFs7R62p2cV+Q767rHNOGUrjVxoWdDUkcHj4jdbxNN/rsUQa6dPvA9AltGn6jtHgtFC5kS12LPKUcgCl1o46qav+yfWzpIMstliLr+B4lLhw0CgYEA7Bpm0s2uoyC1XtYCqeWzbjODciq/hgIpmBjnP4Xs0ELB0VE95m9CVQk47dSngRqbkrEO2G2zdMTYj5Mr5bm5AXQfUpwMv89fxCxSXq1Andqe1/UphigltW/PXOfvpD1JcHNfalEcTOTdzENVYH4lN3HAoPobj04gCsFZFcqWfps= + alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw21teFhHze8ltibg/mBE0Lo1gTvcRUszQpsiTLWLoYvLxfaEVD+5bkpTYrVFczLNqOw93MJxwF0Pj62T3BZU6IXPdXtkKhcflKiZxleSIaTxPFml8mQ8dfdcT25BPidRaeztxv/FCL+0MUTMVh29Ffm9/DHqkjozs4o/Vcf/BoDssw9L7JQffwo/h69B0O688E+s+SivqvXGbiRdARzPrvuQjUMPwUf9vQZ4/ZgGNlwsEhnF90ESCuBZDm8atOoZlqYSNw6g+TZQH5CVS0WCR41TQoW+R8OsX1cv3ERvJXvh/50dEhl8b4CN3nvdaSYcw93o/nkkTZkdZ7BdcNuW2wIDAQAB + gatewayUrl: https://openapi.alipay.com/gateway.do + notify-url: http://yuxy.perrymake.com/app-api/pay/ali/pay_notify # 芋道配置项,设置当前项目所有自定义的配置 yudao: captcha: