This commit is contained in:
menxipeng
2025-11-09 22:09:57 +08:00
parent ad95b13b1c
commit 9f87272433
2 changed files with 70 additions and 13 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}