Explorar o código

Merge branch 'develop/v1.0' into master-test

tangxiangan hai 4 meses
pai
achega
82333d7fdd

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

@@ -60,8 +60,6 @@ public class GooglePayClient {
 
     private final RestTemplate restTemplate = new RestTemplate();
 
-    private GooglePayConfig properties;
-
 
     private AndroidPublisher androidPublisher;// 注入进来咔咔用
 
@@ -69,7 +67,6 @@ public class GooglePayClient {
 
 
     public GooglePayClient(GooglePayConfig properties, GoogleClientHttpRequestInterceptor googleClientHttpRequestInterceptor, RabbitTemplate rabbitTemplate) {
-        this.properties = properties;
         this.rabbitTemplate = rabbitTemplate;
         SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
         restTemplate.setRequestFactory(factory);
@@ -108,6 +105,7 @@ public class GooglePayClient {
         HttpEntity<String> entity = new HttpEntity<>(headers);
 
         // 发起请求
+
         ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
         SubscriptionPurchaseV3 subscriptionsV2 = JSON.parseObject(response.getBody(),SubscriptionPurchaseV3.class);
         return subscriptionsV2;
@@ -147,7 +145,7 @@ public class GooglePayClient {
 //        testID();
         RestTemplate restTemplate = new RestTemplate();
         String url = "https://backend.pdfreaderpro.com/system/google/getSubscriptionGoogleOrderV2" +
-                "?packageName=" + "com.pdftechnologies.pdfreaderpro" + "&purchaseToken=" + "kkocpfbdghkkhpponlnmecao.AO-J1OxH2Cn0M_vUA_SDglNA92yA6jOxahaU-nC8ZljmOvEcQlIGrUtA5YvlDraJL8uFty95fMzl7us6VvvA2ow1TmewRaMBKbdANHudEuQBLMIRSC9Qykw";
+                "?packageName=" + "com.pdftechnologies.pdfreaderpro" + "&purchaseToken=" + "addcgghjnngggjcmcciogdmc.AO-J1OwbnlU9brbdzMiRUTGYOyDJbdmPl1AaJWaIjqyYhTFQXkMlw2qdwTUsvNRNSf45PANqkhVghwYUdT8viJ8wfbMeILsj6S6BHLEtU4WKKH0GossQJrc";
 
         // 设置请求头
         HttpHeaders headers = new HttpHeaders();
@@ -177,7 +175,7 @@ public class GooglePayClient {
     private static void testID() {
         String appName = "PDF Reader Pro";
         String packageName = "com.pdftechnologies.pdfreaderpro";
-        String purchaseToken = "kkocpfbdghkkhpponlnmecao.AO-J1OxH2Cn0M_vUA_SDglNA92yA6jOxahaU-nC8ZljmOvEcQlIGrUtA5YvlDraJL8uFty95fMzl7us6VvvA2ow1TmewRaMBKbdANHudEuQBLMIRSC9Qykw" ;
+        String purchaseToken = "lcjenpgpddjefjihgknnhfgc.AO-J1Ow5p88lKdizid8BDaK_jV3vzjzIZM_qf_S0U9lCNmY6aACQIs_3cgs-ntM6-bC2PNWJdR2YhsN9fWHSu_9BEFhD3-uBJGG39zzgaYz9jimQIcUCvPs" ;
         InputStream content = new IOUtils().getGoogleKey();
         try {
             GoogleCredentials googleCredentials = GoogleCredentials.fromStream(content)

+ 1 - 1
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/properties/AppStoreProperties.java

@@ -38,5 +38,5 @@ public class AppStoreProperties {
     private String isSandbox;
 
     private String currency;
-    private  String testCallBack;
+    private String testCallBack;
 }

+ 1 - 16
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/properties/GooglePayConfig.java

@@ -21,23 +21,8 @@ import java.security.GeneralSecurityException;
 public class GooglePayConfig {
     private String appName;
     private String serviceAccountJson;
+    private String isSandbox;
 
-    @Bean
-    public GoogleCredentials googleCredentials() throws IOException {
-        // 懒得搞配置文件了,直接丢resources读进来
-//        return GoogleCredentials.fromStream(new ClassPathResource(serviceAccountJson).getInputStream())
-//                .createScoped(AndroidPublisherScopes.ANDROIDPUBLISHER);
-        return null;
-    }
-
-//    @Bean
-//    public AndroidPublisher androidPublisher(GoogleCredentials credentials) throws IOException, GeneralSecurityException {
-//        return new AndroidPublisher.Builder(
-//                GoogleNetHttpTransport.newTrustedTransport(),
-//                GsonFactory.getDefaultInstance(),
-//                new HttpCredentialsAdapter(credentials)
-//        ).setApplicationName(appName).build();
-//    }
 
 }
 

+ 3 - 2
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/webhook/AppStoreWebhookMonitor.java

@@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.*;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -49,8 +50,8 @@ public class AppStoreWebhookMonitor {
     private final AppStoreWebhookService appStoreWebhookService;
     private final RestTemplate restTemplate = new RestTemplate();
 
-    private AppStoreProperties properties;
-    private AppStoreService appStoreService;
+    private final AppStoreProperties properties;
+    private final AppStoreService appStoreService;
 
     @RequestMapping(value = "/webhook/subscription", method = RequestMethod.POST)
     public ResponseEntity<String> receiveSubscriptionCallback(@RequestBody(required = false) ResponseBodyV2 responseBodyV2) {

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

@@ -2,17 +2,15 @@ package cn.kdan.cloud.pdf.office.payment.webhook;
 
 import cn.kdan.cloud.pdf.office.common.enums.ExceptionEnum;
 import cn.kdan.cloud.pdf.office.common.exception.BackendRuntimeException;
-import cn.kdan.cloud.pdf.office.common.utils.JsonUtils;
 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.webhook.appstore.notification.ResponseBodyV2;
 import cn.kdan.cloud.pdf.office.payment.webhook.google.DeveloperNotification;
 import cn.kdan.cloud.pdf.office.payment.webhook.google.SubscriptionNotification;
 import cn.kdan.cloud.pdf.office.payment.webhook.google.SubscriptionNotifyTypeEnum;
 import cn.kdan.cloud.pdf.office.payment.webhook.google.SubscriptionPurchaseV3;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
-import com.google.api.services.androidpublisher.model.SubscriptionPurchaseV2;
 import jodd.net.URLDecoder;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -42,6 +40,7 @@ public class GoogleWebhookMonitor {
 
     private final GooglePayService googlePayService;
     private final GooglePayClient googlePayClient;
+    private final GooglePayConfig googlePayConfig;
     private final RestTemplate restTemplate = new RestTemplate();
 
     @RequestMapping(value = "/webhook/subscription", method = RequestMethod.POST)
@@ -62,7 +61,7 @@ public class GoogleWebhookMonitor {
             //        String data = "{\"version\":\"1.0\",\"packageName\":\"com.pdftechnologies.pdfreaderpro\",\"eventTimeMillis\":\"1730450275958\",\"subscriptionNotification\":{\"version\":\"1.0\",\"notificationType\":2,\"purchaseToken\":\"nbohocncnjkkfejblaegdjcn.AO-J1OzWC-iyg4Je_5ibj2dpsby49UShnZBn0D5jEXO_9OdB0M2E4aUDahXAYflW4udRFMY1VvKvjWmhRK-QDNOe6KCG8LooRPZKQ_suYWRoSXHJiLrJBz4\",\"subscriptionId\":\"new_all_access_pack_monthly\"}}";
             log.info("谷歌 接收回调通知值:{}", data);
             DeveloperNotification developerNotification = JSONObject.parseObject(data, DeveloperNotification.class);
-            if(ObjectUtils.isEmpty(developerNotification.getSubscriptionNotification())){
+            if (ObjectUtils.isEmpty(developerNotification.getSubscriptionNotification())) {
                 log.info("谷歌订阅回调:缺少SubscriptionNotification()");
                 return ResponseEntity.status(HttpStatus.OK).build(); // 返回 200 OK
             }
@@ -72,8 +71,16 @@ public class GoogleWebhookMonitor {
             log.info("谷歌 token:{}", purchaseToken);
             // 获取订阅订单信息
             SubscriptionPurchaseV3 subscriptionGoogleOrderV2 = googlePayClient.getSubscription(developerNotification.getPackageName(), purchaseToken);
-            if(subscriptionGoogleOrderV2.getTestPurchase() == null){
-                sandboxCallBack(body);
+            //测试订单
+            if (subscriptionGoogleOrderV2.getTestPurchase() != null) {
+                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
             }
             //判断订单状态
@@ -89,10 +96,6 @@ public class GoogleWebhookMonitor {
                 boolean resultLock = rLock.tryLock(30, 10, TimeUnit.SECONDS);
                 if (resultLock) {
                     log.info("上锁成功, 当前事件谷歌订阅回调:{}", notificationType);
-                    if(ObjectUtils.isEmpty(subscriptionGoogleOrderV2.getExternalAccountIdentifiers())){
-                        log.info("没有订阅id,谷歌订阅回调:{}", notificationType);
-                        return ResponseEntity.status(HttpStatus.OK).build(); // 返回 200 OK
-                    }
                     if (SubscriptionNotifyTypeEnum.SUBSCRIPTION_PURCHASED.getType() == notificationType) {
                         // 处理购买新订阅
                     } else if (SubscriptionNotifyTypeEnum.SUBSCRIPTION_CANCELED.getType() == notificationType) {