diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/util/AppleyPay.java b/ruoyi-system/src/main/java/com/ruoyi/system/util/AppleyPay.java index 768be8a..c3620ec 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/util/AppleyPay.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/util/AppleyPay.java @@ -199,7 +199,8 @@ public class AppleyPay { // 获取关键信息 String transactionId = latestTransaction.getTransactionId(); String productId = latestTransaction.getProductId(); - String expiresDateMs = latestTransaction.getExpiresDateMs(); + // 获取过期时间(北京时间) + Long expiresDateMsInBeijing = latestTransaction.getExpiresDateMsInBeijing(); // 查询交易信息是否已经存在 OrderInfo selectOrderInfo = orderInfoMapper.selectByTradeNo(transactionId); @@ -229,18 +230,13 @@ public class AppleyPay { } } - // 验证订阅是否过期(对于订阅类型) - if (StringUtils.isNotEmpty(expiresDateMs)) { - try { - long expiresTimestamp = Long.parseLong(expiresDateMs); - long currentTimestamp = System.currentTimeMillis(); - if (expiresTimestamp < currentTimestamp) { - log.warn("订阅已过期。交易ID: {}, 过期时间: {}, 当前时间: {}", - transactionId, new Date(expiresTimestamp), new Date(currentTimestamp)); - return null; - } - } catch (NumberFormatException e) { - log.warn("无法解析过期时间: {}", expiresDateMs); + // 验证订阅是否过期(对于订阅类型,使用北京时间) + if (expiresDateMsInBeijing != null) { + long currentTimestamp = System.currentTimeMillis(); + if (expiresDateMsInBeijing < currentTimestamp) { + log.warn("订阅已过期。交易ID: {}, 过期时间(北京时间): {}, 当前时间: {}", + transactionId, new Date(expiresDateMsInBeijing), new Date(currentTimestamp)); + return null; } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/util/InAppTransaction.java b/ruoyi-system/src/main/java/com/ruoyi/system/util/InAppTransaction.java index 963689c..e3f2e92 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/util/InAppTransaction.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/util/InAppTransaction.java @@ -105,4 +105,65 @@ public class InAppTransaction { * 订阅组标识符 */ private String subscriptionGroupIdentifier; + + /** + * 获取过期日期时间戳(北京时间,毫秒) + * 将太平洋时间转换为北京时间(UTC+8) + * 太平洋时间(PST/PDT)到北京时间需要加16小时(PST)或15小时(PDT) + * 这里使用16小时(57600000毫秒)作为标准转换 + * + * @return 北京时间的时间戳(毫秒),如果expiresDateMs为空则返回null + */ + public Long getExpiresDateMsInBeijing() { + if (expiresDateMs == null || expiresDateMs.isEmpty()) { + return null; + } + try { + long pacificTimestamp = Long.parseLong(expiresDateMs); + // 太平洋时间到北京时间:PST(UTC-8)到UTC+8需要加16小时,PDT(UTC-7)到UTC+8需要加15小时 + // 使用16小时(57600000毫秒)作为标准转换,确保覆盖PST和PDT + long beijingTimestamp = pacificTimestamp + 16 * 60 * 60 * 1000L; // 加16小时 + return beijingTimestamp; + } catch (NumberFormatException e) { + return null; + } + } + + /** + * 获取购买日期时间戳(北京时间,毫秒) + * 将太平洋时间转换为北京时间 + * + * @return 北京时间的时间戳(毫秒),如果purchaseDateMs为空则返回null + */ + public Long getPurchaseDateMsInBeijing() { + if (purchaseDateMs == null || purchaseDateMs.isEmpty()) { + return null; + } + try { + long pacificTimestamp = Long.parseLong(purchaseDateMs); + long beijingTimestamp = pacificTimestamp + 16 * 60 * 60 * 1000L; // 加16小时 + return beijingTimestamp; + } catch (NumberFormatException e) { + return null; + } + } + + /** + * 获取原始购买日期时间戳(北京时间,毫秒) + * 将太平洋时间转换为北京时间 + * + * @return 北京时间的时间戳(毫秒),如果originalPurchaseDateMs为空则返回null + */ + public Long getOriginalPurchaseDateMsInBeijing() { + if (originalPurchaseDateMs == null || originalPurchaseDateMs.isEmpty()) { + return null; + } + try { + long pacificTimestamp = Long.parseLong(originalPurchaseDateMs); + long beijingTimestamp = pacificTimestamp + 16 * 60 * 60 * 1000L; // 加16小时 + return beijingTimestamp; + } catch (NumberFormatException e) { + return null; + } + } }