内购遇见的那些坑

来源:互联网 发布:数据实时可视化 编辑:程序博客网 时间:2024/05/16 11:53

1. 苹果需要上传内购手机截屏  截到的图片上传失败 提示你上传有效的图片。 记着 你的图片一定要把手机连接电脑直接取 不要经过第三方的应用传递!

2. 内购支付的时候 上传给苹果的是。内购的项目ID。不是订单号码。另外苹果没有一个字段是记录订单号码的  

需要我们手动的改变苹果API的某一个字段的值。例如::


// 收到商品详细信息回掉的方法

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {

    self.request =nil;

    NSLog(@"response.products = %@", response.products);

    NSLog(@"-----------收到产品反馈信息--------------");

    

    NSArray *products = response.products;

    if (products.count !=0) {

        SKProduct *product = products[0];

        SKMutablePayment *payment = [SKMutablePaymentpaymentWithProduct:product];

        

      //这里赋值。商品订单

        if (_IAPOrderId.length >0) {

            payment.applicationUsername =_IAPOrderId;//充值用户的id,也就是uid.

        }

        [[SKPaymentQueuedefaultQueue] addPayment:payment];//发起购买

    }


3.支付完成之后 需要服务器验证。我们需要传递给服务器支付凭证。目前该是这样的

332.

}33

    NSURL *receiptUrl;

    NSData *receiptData;

  receiptUrl = [[NSBundlemainBundle] appStoreReceiptURL];

    receiptData = [NSDatadataWithContentsOfURL:receiptUrl];


  进行base64转码
-(NSString *)encode:(constuint8_t *)input length:(NSInteger)length
{
    static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    NSMutableData *data = [NSMutableDatadataWithLength:((length + 2) /3) * 4];
    uint8_t *output = (uint8_t *)data.mutableBytes;
    for (NSInteger i =0; i < length; i += 3)
    {
        NSInteger value =0;
        for (NSInteger j = i; j < (i +3); j++)
        {
            value <<= 8;
            if (j < length)
            {
                value |= (0xFF & input[j]);
            }
        }
        NSInteger index = (i /3) * 4;
        output[index + 0] =                    table[(value >>18) & 0x3F];
        output[index + 1] =                    table[(value >>12) & 0x3F];
        output[index + 2] = (i +1) < length ? table[(value >> 6)  & 0x3F] :'=';
        output[index + 3] = (i +2) < length ? table[(value >> 0)  & 0x3F] :'=';
    }
    return [[NSStringalloc] initWithData:dataencoding:NSASCIIStringEncoding];
}