瀏覽代碼

平台化

wangqifan 3 年之前
父節點
當前提交
b2ec712c1e

+ 1 - 1
pom.xml

@@ -172,7 +172,7 @@
         <dependency>
             <groupId>com.github.binarywang</groupId>
             <artifactId>weixin-java-pay</artifactId>
-            <version>4.2.0</version>
+            <version>${javawx.version}</version>
         </dependency>
 
         <dependency>

+ 1 - 1
src/main/java/com/izouma/zhumj/config/WxPayConfiguration.java

@@ -18,7 +18,7 @@ import org.springframework.context.annotation.Configuration;
 @ConditionalOnClass(WxPayService.class)
 @EnableConfigurationProperties(WxPayProperties.class)
 public class WxPayConfiguration {
-    private WxPayProperties properties;
+    private final WxPayProperties properties;
 
     @Autowired
     public WxPayConfiguration(WxPayProperties properties) {

+ 116 - 126
src/main/java/com/izouma/zhumj/service/client/ClientRoomInfoService.java

@@ -1,19 +1,9 @@
 package com.izouma.zhumj.service.client;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.alipay.api.AlipayApiException;
-import com.alipay.api.domain.AlipayTradeAppPayModel;
-import com.alipay.api.request.AlipayTradeAppPayRequest;
-import com.alipay.api.request.AlipayTradeWapPayRequest;
-import com.alipay.api.response.AlipayTradeAppPayResponse;
-import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsRequest;
-import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
-import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
 import com.github.binarywang.wxpay.constant.WxPayConstants;
 import com.github.binarywang.wxpay.exception.WxPayException;
-import com.github.binarywang.wxpay.service.EcommerceService;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.izouma.zhumj.config.Constants;
 import com.izouma.zhumj.domain.*;
@@ -341,107 +331,60 @@ public class ClientRoomInfoService {
         }
     }
 
-    public Object subRecharge(Long userId, BigDecimal amount, RechargeType type, PayMethod payMethod) throws WxPayException, AlipayApiException {
-        if (amount.compareTo(BigDecimal.valueOf(0.01)) < 0) {
-            throw new BusinessException("最少充值0.01元");
-        }
-        User user = userRepo.findById(userId).orElseThrow(new BusinessException("无记录"));
-        CheckinInfo checkinInfo = checkinInfoRepo.findFirstByIdNoOrderByCheckinTimeDescCreatedAtDesc(user.getIdNo())
-                .orElseThrow(new BusinessException("无记录"));
-        String storeName = Optional.ofNullable(checkinInfo.getStoreInfo())
-                .map(StoreInfo::getStoreName)
-                .orElse(null);
-        String bedName = Optional.ofNullable(checkinInfo.getBedInfo())
-                .map(BedInfo::getBedName)
-                .orElse(null);
-        String body = "";
-        switch (type) {
-            case ROOM:
-                body = "房间余额充值";
-                break;
-            case PERSON:
-                body = "账户余额充值";
-                break;
-            case AMMETER:
-                body = "电表充值";
-                break;
-            default:
-                body = "充值";
-        }
-        if (StringUtils.isNotEmpty(storeName)) {
-            body += "," + storeName;
-        }
-        if (StringUtils.isNotEmpty(bedName)) {
-            body += "," + bedName;
-        }
-
-
-        switch (payMethod) {
-            case WEIXIN:
-                WxPayUnifiedOrderRequest request;
-                PartnerTransactionsRequest partnerTransactionsRequest;
-                partnerTransactionsRequest = new PartnerTransactionsRequest();
-                partnerTransactionsRequest.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
-                partnerTransactionsRequest.setNotifyUrl(wxNotifyUrl);
-
-                PartnerTransactionsRequest.Payer payer = new PartnerTransactionsRequest.Payer();
-                payer.setSpOpenid(user.getOpenId());
-                payer.setSpOpenid(user.getOpenId());
-                partnerTransactionsRequest.setPayer(payer);
-
-                PartnerTransactionsRequest.SettleInfo settleInfo = new PartnerTransactionsRequest.SettleInfo();
-                partnerTransactionsRequest.setSettleInfo(settleInfo);
-                partnerTransactionsRequest.setDescription(body);
-
-                partnerTransactionsRequest.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
-                partnerTransactionsRequest.setAttach(new JsonUtils.Builder()
-                        .add(Constants.ATTACH_TYPE, "recharge")
-                        .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
-                        .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
-                        .add(Constants.ATTACH_USER_ID, userId)
-                        .add(Constants.ATTACH_AMOUNT, amount)
-                        .add(Constants.ATTACH_REMARK, "")
-                        .build());
-
-
-                PartnerTransactionsRequest.Amount requestAmount = new PartnerTransactionsRequest.Amount();
-                requestAmount.setTotal(amount.multiply(BigDecimal.valueOf(100)).intValue());
-                requestAmount.setCurrency("CNY");
-                partnerTransactionsRequest.setAmount(requestAmount);
-                request = new WxPayUnifiedOrderRequest();
-                request.setSpbillCreateIp("180.102.110.170");
-                request.setNotifyUrl(wxNotifyUrl);
-                request.setTradeType(WxPayConstants.TradeType.JSAPI);
-                request.setOpenid(user.getOpenId());
-                request.setSignType("MD5");
-                request.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
-                request.setTotalFee(amount.multiply(BigDecimal.valueOf(100)).intValue());
-                request.setAttach(new JsonUtils.Builder()
-                        .add(Constants.ATTACH_TYPE, "recharge")
-                        .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
-                        .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
-                        .add(Constants.ATTACH_USER_ID, userId)
-                        .add(Constants.ATTACH_AMOUNT, amount)
-                        .add(Constants.ATTACH_REMARK, "")
-                        .build());
-
-                request.setBody(body);
-
-                // 测试环境设为1分
-                if (Arrays.stream(environment.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
-                    // request.setTotalFee(1);
-                }
-                return wxPayService.getEcommerceService()
-                        .partnerTransactions(TradeTypeEnum.JSAPI, partnerTransactionsRequest);
-//            case ALIPAY:
-//                AlipayTradeAppPayRequest alipayRequest = new AlipayTradeAppPayRequest();
-//                AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
-//                model.setOutTradeNo(UUID.randomUUID().toString());
-//                model.setSubject(body);
-//                model.setTotalAmount(amount.toString());
-//                model.setDisablePayChannels("pcredit,creditCard");
-//                model.setProductCode("QUICK_MSECURITY_PAY");
-//                model.setBody(new JsonUtils.Builder()
+//    public Object subRecharge(Long userId, BigDecimal amount, RechargeType type, PayMethod payMethod) throws WxPayException, AlipayApiException {
+//        if (amount.compareTo(BigDecimal.valueOf(0.01)) < 0) {
+//            throw new BusinessException("最少充值0.01元");
+//        }
+//        User user = userRepo.findById(userId).orElseThrow(new BusinessException("无记录"));
+//        CheckinInfo checkinInfo = checkinInfoRepo.findFirstByIdNoOrderByCheckinTimeDescCreatedAtDesc(user.getIdNo())
+//                .orElseThrow(new BusinessException("无记录"));
+//        String storeName = Optional.ofNullable(checkinInfo.getStoreInfo())
+//                .map(StoreInfo::getStoreName)
+//                .orElse(null);
+//        String bedName = Optional.ofNullable(checkinInfo.getBedInfo())
+//                .map(BedInfo::getBedName)
+//                .orElse(null);
+//        String body = "";
+//        switch (type) {
+//            case ROOM:
+//                body = "房间余额充值";
+//                break;
+//            case PERSON:
+//                body = "账户余额充值";
+//                break;
+//            case AMMETER:
+//                body = "电表充值";
+//                break;
+//            default:
+//                body = "充值";
+//        }
+//        if (StringUtils.isNotEmpty(storeName)) {
+//            body += "," + storeName;
+//        }
+//        if (StringUtils.isNotEmpty(bedName)) {
+//            body += "," + bedName;
+//        }
+//
+//
+//        switch (payMethod) {
+//            case WEIXIN:
+//                WxPayUnifiedOrderRequest request;
+//                PartnerTransactionsRequest partnerTransactionsRequest;
+//                partnerTransactionsRequest = new PartnerTransactionsRequest();
+//                partnerTransactionsRequest.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
+//                partnerTransactionsRequest.setNotifyUrl(wxNotifyUrl);
+//
+//                PartnerTransactionsRequest.Payer payer = new PartnerTransactionsRequest.Payer();
+//                payer.setSpOpenid(user.getOpenId());
+//                payer.setSpOpenid(user.getOpenId());
+//                partnerTransactionsRequest.setPayer(payer);
+//
+//                PartnerTransactionsRequest.SettleInfo settleInfo = new PartnerTransactionsRequest.SettleInfo();
+//                partnerTransactionsRequest.setSettleInfo(settleInfo);
+//                partnerTransactionsRequest.setDescription(body);
+//
+//                partnerTransactionsRequest.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
+//                partnerTransactionsRequest.setAttach(new JsonUtils.Builder()
 //                        .add(Constants.ATTACH_TYPE, "recharge")
 //                        .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
 //                        .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
@@ -449,22 +392,69 @@ public class ClientRoomInfoService {
 //                        .add(Constants.ATTACH_AMOUNT, amount)
 //                        .add(Constants.ATTACH_REMARK, "")
 //                        .build());
-//                if (Arrays.stream(environment.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
-//                    // 测试环境设为1分
-////                    model.setTotalAmount("0.01");
-//                }
 //
-//                alipayRequest.setNotifyUrl(aliNotifyUrl);
-//                alipayRequest.setBizModel(model);
 //
-//                AlipayTradeAppPayResponse response = alipayClient.sdkExecute(alipayRequest);
-//                if (response.isSuccess()) {
-//                    return response.getBody();
-//                } else {
-//                    throw new BusinessException("支付宝下单失败");
+//                PartnerTransactionsRequest.Amount requestAmount = new PartnerTransactionsRequest.Amount();
+//                requestAmount.setTotal(amount.multiply(BigDecimal.valueOf(100)).intValue());
+//                requestAmount.setCurrency("CNY");
+//                partnerTransactionsRequest.setAmount(requestAmount);
+//                request = new WxPayUnifiedOrderRequest();
+//                request.setSpbillCreateIp("180.102.110.170");
+//                request.setNotifyUrl(wxNotifyUrl);
+//                request.setTradeType(WxPayConstants.TradeType.JSAPI);
+//                request.setOpenid(user.getOpenId());
+//                request.setSignType("MD5");
+//                request.setOutTradeNo(String.valueOf(new SnowflakeIdWorker(1, 1).nextId()));
+//                request.setTotalFee(amount.multiply(BigDecimal.valueOf(100)).intValue());
+//                request.setAttach(new JsonUtils.Builder()
+//                        .add(Constants.ATTACH_TYPE, "recharge")
+//                        .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
+//                        .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
+//                        .add(Constants.ATTACH_USER_ID, userId)
+//                        .add(Constants.ATTACH_AMOUNT, amount)
+//                        .add(Constants.ATTACH_REMARK, "")
+//                        .build());
+//
+//                request.setBody(body);
+//
+//                // 测试环境设为1分
+//                if (Arrays.stream(environment.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
+//                    // request.setTotalFee(1);
 //                }
-            default:
-                throw new BusinessException("不支持此支付方式");
-        }
-    }
+//                return wxPayService.getEcommerceService()
+//                        .partnerTransactions(TradeTypeEnum.JSAPI, partnerTransactionsRequest);
+////            case ALIPAY:
+////                AlipayTradeAppPayRequest alipayRequest = new AlipayTradeAppPayRequest();
+////                AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
+////                model.setOutTradeNo(UUID.randomUUID().toString());
+////                model.setSubject(body);
+////                model.setTotalAmount(amount.toString());
+////                model.setDisablePayChannels("pcredit,creditCard");
+////                model.setProductCode("QUICK_MSECURITY_PAY");
+////                model.setBody(new JsonUtils.Builder()
+////                        .add(Constants.ATTACH_TYPE, "recharge")
+////                        .add(Constants.ATTACH_RECHARGE_TYPE, type.name())
+////                        .add(Constants.ATTACH_CHECKIN_ID, checkinInfo.getId())
+////                        .add(Constants.ATTACH_USER_ID, userId)
+////                        .add(Constants.ATTACH_AMOUNT, amount)
+////                        .add(Constants.ATTACH_REMARK, "")
+////                        .build());
+////                if (Arrays.stream(environment.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
+////                    // 测试环境设为1分
+//////                    model.setTotalAmount("0.01");
+////                }
+////
+////                alipayRequest.setNotifyUrl(aliNotifyUrl);
+////                alipayRequest.setBizModel(model);
+////
+////                AlipayTradeAppPayResponse response = alipayClient.sdkExecute(alipayRequest);
+////                if (response.isSuccess()) {
+////                    return response.getBody();
+////                } else {
+////                    throw new BusinessException("支付宝下单失败");
+////                }
+//            default:
+//                throw new BusinessException("不支持此支付方式");
+//        }
+//    }
 }