订d
This commit is contained in:
@@ -199,7 +199,8 @@ public class AppleyPay {
|
|||||||
// 获取关键信息
|
// 获取关键信息
|
||||||
String transactionId = latestTransaction.getTransactionId();
|
String transactionId = latestTransaction.getTransactionId();
|
||||||
String productId = latestTransaction.getProductId();
|
String productId = latestTransaction.getProductId();
|
||||||
String expiresDateMs = latestTransaction.getExpiresDateMs();
|
// 获取过期时间(北京时间)
|
||||||
|
Long expiresDateMsInBeijing = latestTransaction.getExpiresDateMsInBeijing();
|
||||||
|
|
||||||
// 查询交易信息是否已经存在
|
// 查询交易信息是否已经存在
|
||||||
OrderInfo selectOrderInfo = orderInfoMapper.selectByTradeNo(transactionId);
|
OrderInfo selectOrderInfo = orderInfoMapper.selectByTradeNo(transactionId);
|
||||||
@@ -229,19 +230,14 @@ public class AppleyPay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证订阅是否过期(对于订阅类型)
|
// 验证订阅是否过期(对于订阅类型,使用北京时间)
|
||||||
if (StringUtils.isNotEmpty(expiresDateMs)) {
|
if (expiresDateMsInBeijing != null) {
|
||||||
try {
|
|
||||||
long expiresTimestamp = Long.parseLong(expiresDateMs);
|
|
||||||
long currentTimestamp = System.currentTimeMillis();
|
long currentTimestamp = System.currentTimeMillis();
|
||||||
if (expiresTimestamp < currentTimestamp) {
|
if (expiresDateMsInBeijing < currentTimestamp) {
|
||||||
log.warn("订阅已过期。交易ID: {}, 过期时间: {}, 当前时间: {}",
|
log.warn("订阅已过期。交易ID: {}, 过期时间(北京时间): {}, 当前时间: {}",
|
||||||
transactionId, new Date(expiresTimestamp), new Date(currentTimestamp));
|
transactionId, new Date(expiresDateMsInBeijing), new Date(currentTimestamp));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
log.warn("无法解析过期时间: {}", expiresDateMs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据产品ID处理不同的订阅类型
|
// 根据产品ID处理不同的订阅类型
|
||||||
|
|||||||
@@ -105,4 +105,65 @@ public class InAppTransaction {
|
|||||||
* 订阅组标识符
|
* 订阅组标识符
|
||||||
*/
|
*/
|
||||||
private String subscriptionGroupIdentifier;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user