【问题标题】:In-app purchase receipt not sent to server when production生产时未将应用内购买收据发送到服务器
【发布时间】:2014-09-16 16:51:44
【问题描述】:

我一直在尝试上传包含非续订应用内购买的应用的新版本,但没有成功。被吊销了快两个月了,找不到问题。

当我使用 沙盒 帐户进行测试时,购买会转到我的服务器,我验证收据,然后更新我的用户状态。但是当我的应用程序进行审查时,审查者说我的应用程序没有提供用户的付费内容,但我在我的服务器上没有一次尝试。

我对我的 Objective-C 代码进行了一些更改,希望错误可能是超时,现在我将其更改为 45.0 秒。应该是多长时间?

我还对我的服务器代码进行了一些更改,以检查购买是否是由沙盒或生产帐户进行的。

所以...这是SKPaymentTransactionStatePurchased之后调用的方法。

#pragma mark pagamento
-(void)completarTransacao:(SKPaymentTransaction *)transacao
{
    [SVProgressHUD dismiss];

    receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle]  appStoreReceiptURL]];

    if (!receipt)
    {
       receipt = transacao.transactionReceipt;
    }

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    [SVProgressHUD showWithStatus:NSLocalizedString(@"Efetuando assinatura...", nil)];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@assinaturaplano/", [[NSDictionary dictionaryWithContentsOfFile:configuracoes_plist] objectForKey:@"Dominio"]]] cachePolicy:nil timeoutInterval:45.0];

    [request setHTTPMethod:@"POST"];

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"];

    [request setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:@"http://temp"]]]];

    NSString *postString = [NSString stringWithFormat:@"receipt=%@&transactionIdentifier=%@&origem=%@", [receipt.base64Encoding urlencode], transacao.transactionIdentifier, [[NSDictionary dictionaryWithContentsOfFile:[home_documents stringByAppendingPathComponent:@"compra"]] objectForKey:@"origem"]];

   [request setHTTPBody:[NSData dataWithBytes:[postString UTF8String] length:postString.length]];

   [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *erro)
   {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

        [SVProgressHUD dismiss];

        if ([(NSHTTPURLResponse*)response statusCode] == 200 || [(NSHTTPURLResponse*)response statusCode] == 201)
        {
            // SUBSCRIPTION CONFIRMED
            [SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"Assinatura efetuada com sucesso!", nil)];

            [[NSNotificationCenter defaultCenter] postNotificationName:@"atualizarGold" object:nil];
        }
        else
        {
            // SUBSCRIPTION NOT CONFIRMED
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"Assinatura não efetuada. Tente novamente.", nil)];
        }

        [[SKPaymentQueue defaultQueue] finishTransaction:transacao];
    }];
}

我的购买方式在审核时总是转到 else。

审核回复

原因 2.2:出现错误的应用程序将被拒绝 ----- 2.2 ----- 我们发现您的应用程序在运行 iOS 8 的 iPad 和运行 iOS 8 的 iPhone 5s 上审查时出现一个或多个错误,在 Wi-Fi 和蜂窝网络,这不符合 应用商店审查指南。应用内购买未完成。后 用户点击 In App Purchase,输入 Apple ID 和密码,然后 确认购买,会产生一条错误消息。的步骤 重现是: 1.启动应用 2. 使用提供的凭据登录 3. 选择“黄金会员” 4. 点击“7 天” 5.输入用户的Apple ID和密码 6.确认购买 7. 出现错误提示

我做错了什么?为什么它只能通过沙盒工作?

【问题讨论】:

  • 你检查过你得到的是哪个 HTTP 状态码吗?
  • 问题是我在错误的地方搜索收据信息。

标签: ios in-app-purchase appstore-approval


【解决方案1】:

要查找收据信息,我执行了以下操作:

// Transaction: SKPaymentTransaction
// storeURL: Sandbox - https://sandbox.itunes.apple.com/verifyReceipt | Production - https://buy.itunes.apple.com/verifyReceipt
-(void)validateTransaction:(SKPaymentTransaction *)transaction storeURL:(NSString *)url
{
     receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle]  appStoreReceiptURL]];

     if (!receipt)
     {
         receipt = transacao.transactionReceipt;
     }

     NSError *error;

     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];

     [request setHTTPMethod:@"POST"];

     [request setHTTPBody:[NSJSONSerialization dataWithJSONObject:@{@"receipt-data": [receipt base64EncodedStringWithOptions:0], @"password" : @"yourpassword"} options:0 error:&error]];

     [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {        
         if (!connectionError)
         {
              NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

              if ([[jsonResponse objectForKey:@"status"] intValue] == 0)
              {
                  NSDictionary *purchaseInfo;

                  NSArray *inApp = [[jsonResponse objectForKey:@"receipt"] objectForKey:@"in_app"];

                  if (inApp)
                  {
                      for (NSDictionary *receptDictionary in inApp)
                      {
                          if ([[receptDictionary objectForKey:@"transaction_id"] isEqualToString:transacao.transactionIdentifier])
                          {
                              purchaseInfo = receptDictionary;

                              break;
                          }
                      }
                  }

                  // The recent has been found
                  // Send it to your server
              }
              else
              {
                  switch ([[jsonResponse objectForKey:@"status"] intValue])
                  {
                  case 21003:
                          // Receipt not authenticated

                          [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                          break;
                  case 21005:
                          // Server not available 

                          break;
                 case 21007:
                          // Sandbox receipt send it to sandbox server
                          [self validateTransaction:transaction storeURL:@"https://sandbox.itunes.apple.com/verifyReceipt"];
                          break;
                 case 21008:
                          // Production receipt send it to production
                          [self validateTransaction:transaction storeURL:@"https://buy.itunes.apple.com/verifyReceipt"];
                          break;
                  }
              }
          }
          else
          {
              // It was not possible to connect AppStore
          }
      }];
 }

【讨论】:

  • @user337658 希望对您有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-23
  • 1970-01-01
  • 1970-01-01
  • 2017-08-15
相关资源
最近更新 更多