内购流程以及要注意的地方
前言
# 一. 票据验证
# 1. APP 端票据验证
代码:
/**
APP端 内购票据验证
*/
+ (void)ls_appCheckReceipt:(NSString *)receipt
success:(SuccessBlock)success
failure:(FailureBlock)failure {
if (receipt == nil) {
return;
}
// 获取票据信息
NSError *error;
NSDictionary *receiptDict = @{@"receipt-data": receipt};
NSData *params = [NSJSONSerialization dataWithJSONObject:receiptDict options:0 error:&error];
if (params == nil) {
return;
}
// 沙盒验证
NSURL *storeUrl = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:storeUrl];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:params];
NSOperationQueue *queque = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queque completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
if (connectionError) {
if (error) {
failure(connectionError);
}
}else {
NSError *error;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (!jsonResponse) {
if (error) {
failure(error);
}
}else {
if (success) {
LSSuccessInfo *info = [[LSSuccessInfo alloc] init];
info.response = jsonResponse;
success(info);
}
}
}
}];
}
← 关于【代理模式】 重绘之 drawRect →