Explorar o código

支付、提现功能

pengcheng hai 1 día
pai
achega
6e246815b0

+ 4 - 5
ruoyi-admin/src/main/resources/application-dev.yml

@@ -203,10 +203,10 @@ wx:
       #keyPath: "E:/工作/所有项目/全民霸王猜/overlord-guess-admin/ruoyi-admin/src/main/resources/cert/apiclient_cert.p12" # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头)
       apiv3: 5Bc8eR7zQ1X9gK3lMp2vN6sD4hJ0fAqW #公司的:7f279a5423a15118e9cb1fc381631f61   客户的:5Bc8eR7zQ1X9gK3lMp2vN6sD4hJ0fAqW
       certSerialNo: 5C8AB18A9CC11514B1343E422C0C57D620B157DC #证书序列号公司的:5DDEE5F70C50743B6B3BFC92263696D2A68AC951,客户的:5C8AB18A9CC11514B1343E422C0C57D620B157DC
-      privateKeyPath: "ruoyi-admin/src/main/resources/cert/apiclient_key.pem"
+      privateKeyPath: "E:/xc/project/yicangshop/api/shop_system/src/main/resources/wxpay/partner/apiclient_key.pem"
       #privateKeyPath: "E:/工作/所有项目/全民霸王猜/overlord-guess-admin/ruoyi-admin/src/main/resources/cert/apiclient_key.pem"
       publicKeyId: PUB_KEY_ID_0117039808242025041700351608000401   #公司的:PUB_KEY_ID_0116405774802025022100326400001700 客户的:PUB_KEY_ID_0117039808242025041700351608000401
-      publicKeyPath: "ruoyi-admin/src/main/resources/cert/pub_key.pem"
+      publicKeyPath: "E:/xc/project/yicangshop/api/shop_system/src/main/resources/wxpay/partner/pub_key.pem"
       #publicKeyPath: "E:/工作/所有项目/全民霸王猜/overlord-guess-admin/ruoyi-admin/src/main/resources/cert/pub_key.pem"
       transferNotifyUrl: "https://frp.songlanyun.com/api/wx/transfer/notify"
     partner:
@@ -219,14 +219,13 @@ wx:
       #keyPath: "E:/工作/所有项目/全民霸王猜/overlord-guess-admin/ruoyi-admin/src/main/resources/cert/apiclient_cert.p12" # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头)
       apiv3: 5Bc8eR7zQ1X9gK3lMp2vN6sD4hJ0fAqW #公司的:7f279a5423a15118e9cb1fc381631f61   客户的:5Bc8eR7zQ1X9gK3lMp2vN6sD4hJ0fAqW
       certSerialNo: 5C8AB18A9CC11514B1343E422C0C57D620B157DC #证书序列号公司的:5DDEE5F70C50743B6B3BFC92263696D2A68AC951,客户的:5C8AB18A9CC11514B1343E422C0C57D620B157DC
-      privateKeyPath: "ruoyi-admin/src/main/resources/cert/apiclient_key.pem"
+      privateKeyPath: "E:/xc/project/yicangshop/api/shop_system/src/main/resources/wxpay/partner/apiclient_key.pem"
       #privateKeyPath: "E:/工作/所有项目/全民霸王猜/overlord-guess-admin/ruoyi-admin/src/main/resources/cert/apiclient_key.pem"
       publicKeyId: PUB_KEY_ID_0117039808242025041700351608000401   #公司的:PUB_KEY_ID_0116405774802025022100326400001700 客户的:PUB_KEY_ID_0117039808242025041700351608000401
-      publicKeyPath: "ruoyi-admin/src/main/resources/cert/pub_key.pem"
+      publicKeyPath: "E:/xc/project/yicangshop/api/shop_system/src/main/resources/wxpay/partner/pub_key.pem"
       #publicKeyPath: "E:/工作/所有项目/全民霸王猜/overlord-guess-admin/ruoyi-admin/src/main/resources/cert/pub_key.pem"
       payNotifyUrl: "https://frp.songlanyun.com/api/pay/wx/notify"
       refundNotifyUrl: "https://frp.songlanyun.com/api/wx/refund/notify"
-      transferNotifyUrl: "https://frp.songlanyun.com/api/wx/transfer/notify"
 
 # 支付宝
 alipay:

+ 6 - 6
ruoyi-newwxpay/src/main/java/com/ruoyi/newwxpay/config/NewWxPayConfig.java

@@ -18,12 +18,12 @@ public class NewWxPayConfig {
     @ConditionalOnBean(NewWxPayProperties.class)
     public RSAPublicKeyConfig rsaPublicKeyConfig() {
         RSAPublicKeyConfig config = new RSAPublicKeyConfig.Builder()
-            .merchantId(newWxPayProperties.getMchId())
-            .privateKeyFromPath(newWxPayProperties.getPrivateKeyPath())
-            .publicKeyFromPath(newWxPayProperties.getPublicKeyPath())
-            .publicKeyId(newWxPayProperties.getPublicKeyId())
-            .merchantSerialNumber(newWxPayProperties.getCertSerialNo())
-            .apiV3Key(newWxPayProperties.getApiv3())
+            .merchantId(newWxPayProperties.getPartner().getMchId())
+            .privateKeyFromPath(newWxPayProperties.getPartner().getPrivateKeyPath())
+            .publicKeyFromPath(newWxPayProperties.getPartner().getPublicKeyPath())
+            .publicKeyId(newWxPayProperties.getPartner().getPublicKeyId())
+            .merchantSerialNumber(newWxPayProperties.getPartner().getCertSerialNo())
+            .apiV3Key(newWxPayProperties.getPartner().getApiv3())
             .build();
         return config;
     }

+ 0 - 1
ruoyi-newwxpay/src/main/java/com/ruoyi/newwxpay/config/NewWxPayProperties.java

@@ -56,7 +56,6 @@ public class NewWxPayProperties
         private String publicKeyPath;
         private String payNotifyUrl;
         private String refundNotifyUrl;
-        private String transferNotifyUrl;
     }
 
     /**

+ 5 - 3
ruoyi-newwxpay/src/main/java/com/ruoyi/newwxpay/transfer/service/TransferService.java

@@ -9,11 +9,13 @@ import java.math.BigDecimal;
 import java.security.GeneralSecurityException;
 
 public interface TransferService {
+
     /**
-     * 商家转账到零钱
-     * @param withdrawBo
+     * 转账给用户
+     * @param outBillNo
+     * @param openid
+     * @param amount
      * @return
-     * @throws Exception
      */
     public TransferToUser.TransferToUserResponse transferBills(String outBillNo, String openid, BigDecimal amount);
 

+ 4 - 2
ruoyi-newwxpay/src/main/java/com/ruoyi/newwxpay/transfer/service/impl/TransferServiceImpl.java

@@ -52,8 +52,10 @@ public class TransferServiceImpl implements TransferService {
     private NewWxPayProperties newWxPayProperties;
 
     /**
-     * 单笔转账到零钱
-     * @param withdrawBo
+     * 转账
+     * @param outBillNo
+     * @param openid
+     * @param amount
      * @return
      */
     public TransferToUser.TransferToUserResponse transferBills(String outBillNo,String openid,BigDecimal amount) {

+ 3 - 1
ruoyi-shop/src/main/java/com/ruoyi/shop/distribution/enums/RemitStatus.java

@@ -9,7 +9,9 @@ import java.util.Objects;
  */
 public enum RemitStatus implements IIntegerEnum<Integer> {
     WAIT_REMIT(0, "未打款"),
-    REMIT(1, "已打款")
+    REMIT(1, "已打款"),
+    REMIT_FAILED(2, "打款失败"),
+
     ;
     private Integer code;
 

+ 1 - 1
ruoyi-shop/src/main/java/com/ruoyi/shop/distribution/service/IWithdrawService.java

@@ -94,7 +94,7 @@ public interface IWithdrawService {
      *
      * @param request
      */
-    void transferCallback(HttpServletRequest request) throws GeneralSecurityException, IOException;
+    void transferCallback(HttpServletRequest request);
 
     /**
      * 校验会员分佣提现金额有没有超过会员当前提现上限

+ 28 - 16
ruoyi-shop/src/main/java/com/ruoyi/shop/distribution/service/impl/WithdrawServiceImpl.java

@@ -31,6 +31,7 @@ import com.ruoyi.user.domain.UserThirdIdentity;
 import com.ruoyi.user.enums.UserThirdType;
 import com.ruoyi.user.service.IUserService;
 import com.ruoyi.user.service.IUserThirdIdentityService;
+import com.wechat.pay.java.service.refund.model.Status;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -261,22 +262,33 @@ public class WithdrawServiceImpl implements IWithdrawService {
     }
 
     @Override
-    public void transferCallback(HttpServletRequest request) throws GeneralSecurityException, IOException {
-
-        WxTransferDataDTO wxTransferDataDTO =  transferService.transferCallback(request);
-        if(ObjectUtil.isNotNull(wxTransferDataDTO)){
-            String outBillNo = wxTransferDataDTO.getOutBillNo();
-            Withdraw withdraw = this.loadByBusinessCode(outBillNo);
-            //如果打款成功
-            withdraw.setRemitStatus(RemitStatus.REMIT);
-            withdraw.setRemitTime(new Date());
-            withdraw.setRemitMan("系统");
-            withdraw.setVerifyMan("系统");
-            this.baseMapper.updateById( withdraw);
-            billService.outBill(withdraw.getIdentityId(),
-                String.format("会员提现:%s,提现单号:%s", withdraw.getMoney(),withdraw.getBusinessCode()),
-                UserBillType.WITHDRAW,
-                withdraw.getMoney(), withdraw.getBusinessCode(),"系统");
+    public void transferCallback(HttpServletRequest request){
+        try{
+            WxTransferDataDTO wxTransferDataDTO = transferService.transferCallback(request);
+            if(ObjectUtil.isNotNull(wxTransferDataDTO)){
+                String state = wxTransferDataDTO.getState();
+                String outBillNo = wxTransferDataDTO.getOutBillNo();
+                Withdraw withdraw = this.loadByBusinessCode(outBillNo);
+                if(Status.SUCCESS.equals(state)){
+                    //如果打款成功
+                    withdraw.setRemitStatus(RemitStatus.REMIT);
+                    withdraw.setRemitTime(new Date());
+                    withdraw.setRemitMan("系统");
+                    withdraw.setVerifyMan("系统");
+                    this.baseMapper.updateById( withdraw);
+                    billService.outBill(withdraw.getIdentityId(),
+                        String.format("会员提现:%s,提现单号:%s", withdraw.getMoney(),withdraw.getBusinessCode()),
+                        UserBillType.WITHDRAW,
+                        withdraw.getMoney(), withdraw.getBusinessCode(),"系统");
+                }else{
+                    //转账失败
+                    withdraw.setRemitStatus(RemitStatus.REMIT_FAILED);
+                    this.baseMapper.updateById( withdraw);
+                }
+            }
+        }catch (IOException | GeneralSecurityException e){
+           e.printStackTrace();
+           throw new ServiceException(e.getMessage());
         }
     }