首先确认你的API key和RSA Key是否已正确设置,特别是在生产环境中需要注意。也可以尝试在不同的环境中重新设置这些密钥,包括在测试环境和生产环境中使用不同的密钥。
如果以上步骤均无效,可以尝试增加retry逻辑来解决错误520,代码示例如下:
RevenueCatClient client = Purchases.sharedInstance().getRevenueCatClient(); client.addPurchasesUpdatedListener(purchases -> {
final List updatedPurchases = purchases.getPurchasesList();
final List newPurchases = new ArrayList<>();
for (Purchase updatedPurchase : updatedPurchases) {
if (isRelevantNewPurchase(updatedPurchase)) {
newPurchases.add(updatedPurchase);
}
}
if (!newPurchases.isEmpty()) {
client.postReceipts(newPurchases, new ReceiptPostResponseListener() {
@Override
public void onReceived(List postDetails) {
// TODO handle success
}
@Override
public void onError(Error error) {
if (error.getCode() == 520) {
retryReceiptPost(newPurchases, error);
} else {
// TODO handle error
}
}
});
}
});
private void retryReceiptPost(List
// Retry the post a maximum of 3 times with a 5 second delay in between
int retryCount = 0;
while (retryCount < 3) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// ignore
}
RevenueCatClient client = Purchases.sharedInstance().getRevenueCatClient();
client.postReceipts(newPurchases, new ReceiptPostResponseListener() {
@Override
public void onReceived(List postDetails) {
// TODO handle success
}
@Override
public void onError(Error error) {