内购推广测试

2019-11-01  本文已影响0人  雨城枫盛

测试用:

itms-services://?action=purchaseIntent&bundleId=bundleID&productIdentifier=produceID

bundID :项目的bundle identifier

produceID :app connect 我的App,功能列表里面对应的商品ID

做自己的逻辑需要关闭苹果协议的添加商品:

-(BOOL)paymentQueue:(SKPaymentQueue*)queue shouldAddStorePayment:(SKPayment*)payment forProduct:(SKProduct*)product

{

//自己的逻辑,直接走下单余额支付道路

return NO;

}

不关闭的话苹果自动下单.

支付结果协议:

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions

{

}

判断支付状态,先获取base64数据,交易流水账号,产品ID,再向自己服务器验证(自己服务器向苹果认证)可能某些服务器还有自己另外的配置,看后台需要

单纯验证沙河测试结果

-(void)verifyReceiptData:(NSString*)ReceiptDataWithQueue:(SKPaymentQueue*)queueAndTransactions:(SKPaymentTransaction*)transaction

{

    NSMutableDictionary *params = [NSMutableDictionary dictionary];

    [paramssetValue:ReceiptDataforKey:@"receipt-data"];

    [paramssetValue:@""forKey:@"password"];

    NSError*jsonError;

    NSData*josonData = [NSJSONSerializationdataWithJSONObject:params

                                                        options:NSJSONWritingPrettyPrinted

                                                          error:&jsonError];

    if(jsonError) {

        NSLog(@"verifyRequestData failed: error = %@", jsonError);

    }

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"]];

    request.HTTPBody= josonData;

    staticNSString*requestMethod =@"POST";

    request.HTTPMethod= requestMethod;

    NSURLSession * session = [NSURLSession sharedSession];

    NSURLSessionDataTask* task = [sessiondataTaskWithRequest:requestcompletionHandler:^(NSData*_Nullabledata,NSURLResponse*_Nullableresponse,NSError*_Nullableerror) {

        NSError*jsonError;

        NSDictionary*responseJSON = [NSJSONSerializationJSONObjectWithData:dataoptions:0error:&jsonError];

        if(!responseJSON) {

            NSLog(@"Failed To Parse Server Response");

        }

        NSSLog(@"result === %@\n",responseJSON);

        staticNSString*statusKey =@"status";

        NSIntegerstatusCode = [responseJSON[statusKey]integerValue];

        staticNSIntegersuccessCode =0;

        staticNSIntegersandboxCode =21007;

        if(statusCode == successCode) {

            [queuefinishTransaction:transaction];

        }elseif(statusCode == sandboxCode) {

            [queuefinishTransaction:transaction];

        }else{

            NSLog(@"Verification Failed With Code %ld", (long)statusCode);

        }

    }];

    [taskresume];

}

状态码:点这里

上一篇 下一篇

猜你喜欢

热点阅读