Selaa lähdekoodia

Merge branch 'develop/v1.0' of http://git.kdan.cc:8865/Server_Service/pdf_office_back_end into develop/v1.0

Bob 4 kuukautta sitten
vanhempi
commit
af525d0a12

+ 1 - 0
pdf-office-common/src/main/java/cn/kdan/cloud/pdf/office/common/enums/ExceptionEnum.java

@@ -99,6 +99,7 @@ public enum ExceptionEnum {
     EXCEPTION_USER_ALREADY_LOTTERY(364, "用户已经抽过奖啦!"),
     EXCEPTION_PRODUCT_TYPE_ERROR(365, "产品类型错误"),
     EXCEPTION_USER_ALREADY_SUBSCRIBED(366, "您已经是订阅会员,无需重复订阅"),
+    EXCEPTION_TEST_BUY(367, "测试订单"),
     ;
     private final Integer value;
     private final String msg;

+ 1 - 1
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/client/GooglePayClient.java

@@ -146,7 +146,7 @@ public class GooglePayClient {
         RestTemplate restTemplate = new RestTemplate();
         String url = "https://backend.pdfreaderpro.com/system/google/getSubscriptionGoogleOrderV2" +
                 "?packageName=" + "com.pdftechnologies.pdfreaderpro" + "&purchaseToken="
-                + "ciakhdogdhngcciamhfgeoac.AO-J1Ozzc45cKdz61hjcmAhF1D7RWdqMUICmdtZYFoi7h9cwU8wT2Pq2mYfScT38EeKRvmjMPkzEXu8NfBJuayzS2vXjaLZBPppIkK10bJRyjx-d4nXgkBM";
+                + "opajmgohldedlcaneafhjibe.AO-J1OxaTTocxdvDeUROv4lNFQXdw7hz9S2EfVkeQZBed4D6IUBmX9elKLQ04_2BbBE0vgaZulHWa2ZtTswBN-UDsFZVrL2EMJknSJUnraA_mPsGrD3Y8sQ";
 
         // 设置请求头
         HttpHeaders headers = new HttpHeaders();

+ 1 - 1
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/service/impl/AppStoreServiceImpl.java

@@ -104,7 +104,7 @@ public class AppStoreServiceImpl implements AppStoreService {
             CreateSubscriptionDTO createSubscription = new CreateSubscriptionDTO();
             ProductVO product = productApi.getProductByCode(equityVerificationDTO.getProductCode()).getResult();
             String subscriptionId = CommonUtils.generateId();
-            String orderId = CommonUtils.generateId();
+            String orderId = cn.kdan.cloud.pdf.office.payment.utils.CommonUtils.generateRightsId((long) ((Math.random() * 9999 + 1) * 10000));
             String appId = product.getAppId();
             createSubscription.setId(subscriptionId);
             createSubscription.setUserId(equityVerificationDTO.getUserId());

+ 7 - 5
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/service/impl/GooglePayServiceImpl.java

@@ -20,6 +20,7 @@ import cn.kdan.cloud.pdf.office.common.utils.MyDateUtils;
 import cn.kdan.cloud.pdf.office.common.vo.UserInfoVO;
 import cn.kdan.cloud.pdf.office.common.vo.UserVO;
 import cn.kdan.cloud.pdf.office.payment.client.GooglePayClient;
+import cn.kdan.cloud.pdf.office.payment.properties.GooglePayConfig;
 import cn.kdan.cloud.pdf.office.payment.service.GooglePayService;
 import cn.kdan.cloud.pdf.office.payment.service.OrderService;
 import cn.kdan.cloud.pdf.office.payment.service.SubscriptionsService;
@@ -32,9 +33,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
+import org.springframework.http.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.LinkedMultiValueMap;
@@ -75,6 +74,7 @@ public class GooglePayServiceImpl implements GooglePayService {
 
     private final EmailApi emailApi;
     private static final RestTemplate restTemplate = new RestTemplate();
+    private final GooglePayConfig googlePayConfig;
     @Value("${htmlToPdfUrl:http://139.196.160.101:3060/api/get-invoice}")
     private String htmlToPdfUrl;
 
@@ -90,6 +90,9 @@ public class GooglePayServiceImpl implements GooglePayService {
         }
         log.info("谷歌权益校验,用户id:{}", googlePayDTO.getUserId());
         SubscriptionPurchaseV3 subscriptionPurchaseV2 = this.verify(googlePayDTO.getPurchaseToken(),googlePayDTO.getPackageName());
+        if (subscriptionPurchaseV2.getTestPurchase() != null) {
+            throw new BackendRuntimeException(ExceptionEnum.EXCEPTION_COUPON_INVALID);
+        }
         // 获取票据订单信息
         if(ObjectUtils.isEmpty(subscriptionPurchaseV2.getExternalAccountIdentifiers())){
             throw new BackendRuntimeException(ExceptionEnum.EXCEPTION_MSG_GOOGLE_STORE_TRANSACTION_ID_VALIDATION_FAILED);
@@ -117,7 +120,7 @@ public class GooglePayServiceImpl implements GooglePayService {
 
         CreateSubscriptionDTO createSubscription = new CreateSubscriptionDTO();
         String subscriptionId = CommonUtils.generateId();
-        String orderId = CommonUtils.generateId();
+        String orderId = cn.kdan.cloud.pdf.office.payment.utils.CommonUtils.generateRightsId((long) ((Math.random() * 9999 + 1) * 10000));
         String appId = product.getAppId().toString();
         createSubscription.setId(subscriptionId);
         createSubscription.setUserId(googlePayDTO.getUserId());
@@ -164,7 +167,6 @@ public class GooglePayServiceImpl implements GooglePayService {
         result.setDigestPassword(null);
         return result;
     }
-
     private void sendBuyEmail(ProductVO product, UserVO userVO,CreateOrderManualDTO orderManualDTO) {
         if(product.getCode().contains("upgrade")){
             EmailSendBO bo = new EmailSendBO();

+ 1 - 1
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/service/impl/WebhookServiceImpl.java

@@ -102,7 +102,7 @@ public class WebhookServiceImpl implements WebhookService {
     public void handleSubsequentAutomaticDeduction(BigDecimal price, String thirdTradeNo, String thirdOrderId, OrdersVO orderByTradeNo, Integer payTime, String result) {
         log.info("自动订阅业务处理开始(非首期)订单id:{}", thirdOrderId);
         String subId = CommonUtils.generateId();
-        String orderId = CommonUtils.generateId();
+        String orderId = cn.kdan.cloud.pdf.office.payment.utils.CommonUtils.generateRightsId((long) ((Math.random() * 9999 + 1) * 10000));;
         // 创建新订单
         CreateOrderManualDTO createOrderManual = new CreateOrderManualDTO();
         BeanUtils.copyProperties(orderByTradeNo, createOrderManual);

+ 5 - 5
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/webhook/GoogleWebhookMonitor.java

@@ -73,17 +73,17 @@ public class GoogleWebhookMonitor {
             SubscriptionPurchaseV3 subscriptionGoogleOrderV2 = googlePayClient.getSubscription(developerNotification.getPackageName(), purchaseToken);
             //测试订单
             log.info("谷歌 订阅:{}", subscriptionGoogleOrderV2.toString());
-            if (subscriptionGoogleOrderV2.getTestPurchase() != null) {
+            if(ObjectUtils.isEmpty(subscriptionGoogleOrderV2.getExternalAccountIdentifiers())){
+                log.info("没有订阅id,旧产品订阅回调不处理,谷歌订阅回调:{}", notificationType);
+                return ResponseEntity.status(HttpStatus.OK).build(); // 返回 200 OK
+            }
+            if(subscriptionGoogleOrderV2.getExternalAccountIdentifiers().getObfuscatedExternalAccountId().contains("test")){
                 if (googlePayConfig.getIsSandbox().equals("false")) {
                     log.info("正式环境转发测试回调", purchaseToken);
                     sandboxCallBack(body);
                     return ResponseEntity.status(HttpStatus.OK).build(); // 返回 200 OK
                 }
             }
-            if(ObjectUtils.isEmpty(subscriptionGoogleOrderV2.getExternalAccountIdentifiers())){
-                log.info("没有订阅id,旧产品订阅回调不处理,谷歌订阅回调:{}", notificationType);
-                return ResponseEntity.status(HttpStatus.OK).build(); // 返回 200 OK
-            }
             //判断订单状态
             if (!googlePayClient.checkSubscriptionSuccess(subscriptionGoogleOrderV2)) {
                 log.error("谷歌订单验证状态异常:{}", subscriptionGoogleOrderV2);

+ 9 - 1
pdf-office-pdf-website/src/main/java/cn/kdan/cloud/pdf/office/website/controller/GoogleController.java

@@ -8,6 +8,7 @@ import cn.kdan.cloud.pdf.office.common.vo.UserInfoVO;
 import cn.kdan.cloud.pdf.office.website.service.PaymentService;
 import cn.kdan.cloud.pdf.office.website.utils.SecurityUtils;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 
@@ -21,6 +22,8 @@ public class GoogleController {
 
     private final PaymentService paymentService;
 
+    @Value("${isSandbox}")
+    private String isSandbox;
 
     /**
      * 谷歌 权益校验
@@ -38,7 +41,12 @@ public class GoogleController {
      */
     @GetMapping("/generateSubscriptionId")
     public ResultMap<String> generateSubscriptionId() {
+        if (isSandbox.equals("false")) {
+            return ResultMap.success(MyDateUtils.getTimeStamp() + "-" + "google" + "-" + (int) ((Math.random() * 9 + 1) * 1000)+"-pro"); // 返回生成的订阅 ID
+        }else{
+            return ResultMap.success(MyDateUtils.getTimeStamp() + "-" + "google" + "-" + (int) ((Math.random() * 9 + 1) * 1000)+"-test"); // 返回生成的订阅 ID
+
+        }
         // 生成一个唯一的订阅 ID
-        return ResultMap.success(MyDateUtils.getTimeStamp() + "-" + "google" + "-" + (int) ((Math.random() * 9 + 1) * 1000)); // 返回生成的订阅 ID
     }
 }