|
@@ -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) {
|