iOS内购自动续费验证交易凭证 status返回21003

去苹果后台->功能->苹果应用内购买项目
生成专用秘钥
   NSDictionary *requestContents = @{
                                          @"receipt-data": @"交易凭证",
                                          @"password"  :  @"将生成的专用秘钥填入"
                                          };
        NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
                                                              options:0
                                                                error:&error];
        if (!requestData) { // 交易凭证为空验证失败
//            [self handleActionWithType:SIAPPurchVerFailed data:nil];
            return;
        }
         
  //生产环境
        NSString *serverString = @"https://buy.itunes.apple.com/verifyReceipt";
        if (isTest) {
//沙盒环境
            serverString = @"https://sandbox.itunes.apple.com/verifyReceipt";
        }
        NSURL *storeURL = [NSURL URLWithString:serverString];
        NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
        [storeRequest setHTTPMethod:@"POST"];
        [storeRequest setHTTPBody:requestData];
         
        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        [NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
                               completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                                   if (connectionError) {
                                       // 无法连接服务器,购买校验失败
                                   } else {
                                       NSError *error;
                                       NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
                                       if (!jsonResponse) {
                                           // 苹果服务器校验数据返回为空校验失败
                                       }
                   // 先验证正式服务器,如果正式服务器返回21007再去苹果测试服务器验证,沙盒测试环境苹果用的是测试服务器
                                       NSString *status = [NSString stringWithFormat:@"%@",jsonResponse[@"status"]];
                                       if (status && [status isEqualToString:@"21007"]) {
                                        
                                       }else if(status && [status isEqualToString:@"0"]){

                                            
                                       }
//    #if DEBUG
                                       NSLog(@"----验证结果 %@",jsonResponse);
//    #endif
                                       
                                   }
                               }];

你可能感兴趣的:(iOS内购自动续费验证交易凭证 status返回21003)