1

我正在做一个“应用内购买 - 消耗品”系统。第一次可以正常购买,但是下次尝试购买时,就不行了。所以我换了一个测试用户,它也只能第一次购买。显示“SK payment transaction state failed”,我该如何解决?

- (void)buyProduct:(int)myNumber{
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:[appDelegate.ArrayProductName objectAtIndex:myNumber]];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions){
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:

                break;
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
                [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                break;
            case SKPaymentTransactionStateFailed:
                if (transaction.error.code != SKErrorPaymentCancelled){
                    NSLog(@"An error encounterd : %@",transaction.error.code);
                }
                break;
            default:
                break;
        }
    }
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction { 
    [self verifyReceipt:(SKPaymentTransaction *)transaction];
}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction {

}

- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction {
    NSString* jsonObjectString =  [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];    
    NSString* completeString = [NSString stringWithFormat: @"myurl?receipt=%@", jsonObjectString];
    NSURL* urlForValidation = [NSURL URLWithString: completeString];
    NSMutableURLRequest* validationRequest = [[NSMutableURLRequest alloc] initWithURL: urlForValidation];
   [validationRequest setHTTPMethod: @"GET"];
    NSData * responseData = [NSURLConnection sendSynchronousRequest:validationRequest  returningResponse: nil  error: nil];
    NSString* responseString = [[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding];
    NSLog(@"return data : %@",responseString);
    int success = [responseString intValue];
    return (success == 0);
}
4

1 回答 1

0

我试着买。系统提示“您已购买但尚未下载。点击确定立即下载”

我们是否需要先将数据发送到Apple的服务器才能使用PHP作为链接重新购买完整的系统?

http://www.phpriot.com/articles/verifying-app-store-receipts-php-curl

http://developer.apple.com/library/ios/#releasenotes/StoreKit/IAP_ReceiptValidation/_index.html#//apple_ref/doc/uid/TP40012484

于 2012-09-25T03:44:20.513 回答