內(nèi)購流程
一本讥、填寫協(xié)議,稅務(wù)和銀行業(yè)務(wù)
1应媚、登錄登錄 https://appstoreconnect.apple.com严沥,選擇進入App Store Connect。
2中姜、進入“協(xié)議消玄、稅務(wù)和銀行業(yè)務(wù)”
3、內(nèi)購用的是付費應(yīng)用程序丢胚,先簽署《付費應(yīng)用程序協(xié)議》翩瓜,同意后狀態(tài)變更為“用戶信息待處理”,等待審核携龟。
4兔跌、狀態(tài)更改完畢后,點擊“開始設(shè)置稅務(wù)峡蟋、銀行業(yè)務(wù)和聯(lián)系信息”坟桅。
a.添加銀行賬戶,按照要求填寫相關(guān)內(nèi)容即可华望。
b.選擇報稅表,并填寫仅乓。(我是可愛的中國公民赖舟,在美國有沒有商業(yè)活動, 所以我填的是否夸楣。)
然后繼續(xù)填寫報稅表宾抓,按照填寫要求填寫就行了(要是英文閱讀有點困難,那就雙擊網(wǎng)頁豫喧,應(yīng)該會有翻譯成中文的功能石洗;沒有的話,那就詞典紧显。讲衫。。你懂得鸟妙,哈哈哈)焦人, 我是個人開發(fā)者賬戶相對公司開發(fā)者賬戶填的會少一點,不過沒關(guān)系重父。都是一些基本信息。
c.填寫聯(lián)系信息忽匈,一共5個房午。高級管理、財務(wù)丹允、技術(shù)郭厌、法務(wù)、營銷(可重復(fù)雕蔽,像我這種人才就是5個職位都是我折柠,開玩笑的,勿當(dāng)真)批狐。
5扇售、稅務(wù)表填完了之后,點擊“我的APP”嚣艇,進入到項目APP的信息頁承冰,點擊功能,在彈出的頁面點擊App內(nèi)購買項目后面的+食零。
創(chuàng)建完成之后 填寫內(nèi)購買項目信息困乒、
信息填寫完成了點擊右上角的 “存儲”,然后點擊左邊 “App 內(nèi)購買項目”贰谣。出現(xiàn)“元數(shù)據(jù)丟失”說明里面信息沒填寫完整娜搂,在點進去填寫迁霎。直到顯示“準(zhǔn)備提交”。
6百宇、添加沙箱測試人員
7考廉、我們需要在工程里配置好證書,測試證書是必須的因為我們內(nèi)購需要連接到蘋果的App Store的恳谎,需要正式的測試證書才能測試芝此,同時把下圖工程中的這一配置打開
二、代碼部分
#import <StoreKit/StoreKit.h>
@interface LLMIneCoinRechargeController ()<UIAlertViewDelegate,SKProductsRequestDelegate,SKPaymentTransactionObserver>
@property(nonatomic, strong)NSArray<LLMIneCoinRechargeModel *> *coinModelArr;
@property(nonatomic,copy)NSString * bvip;
@property(nonatomic,copy)NSString * coin;
@property(nonatomic, strong)SKProductsRequest *request;
@property(nonatomic,copy)NSString * productID;
@implementation LLMIneCoinRechargeController{
UIAlertView* _alertView;
NSString *coinStr;
}
- (void)viewDidLoad {
[super viewDidLoad];
//一定要 開啟內(nèi)購檢測
[[SKPaymentQueue defaultQueue]addTransactionObserver:self];
}
// 在點擊事件中去添加代碼
- (void)payBtnClick:(UIButton *)sender{
__block LLMIneCoinRechargeModel *model = nil;
[self.coinModelArr enumerateObjectsUsingBlock:^(LLMIneCoinRechargeModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.selected) {
model = obj;
}
}];
if (!model) {
[HudManager showMessage:@"請選擇金額"];
return;
}
NSString *proID = [NSString stringWithFormat:@"charge%@",model.coinID];
WS(weakSelf);
if ([SKPaymentQueue canMakePayments]) {
[weakSelf requestProductData:proID];
weakSelf.productID = proID;
}else{
[HudManager showMessage:@"不允許程序內(nèi)付費"];
}
}
// 收到請求信息
- (void)requestProductData:(NSString *)productID{
NSLog(@"-------------請求對應(yīng)的產(chǎn)品信息----------------");
[SVProgressHUD showWithStatus:nil maskType:SVProgressHUDMaskTypeBlack];
NSArray *product = [[NSArray alloc] initWithObjects:productID,nil];
NSSet *nsset = [NSSet setWithArray:product];
_request = [[SKProductsRequest alloc]initWithProductIdentifiers:nsset];
_request.delegate = self;
[_request start];
}
// 收到返回信息
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSArray *product = response.products;
if (product.count == 0) {
[SVProgressHUD dismiss];
[HudManager showMessage:@"購買失敗"];
return;
}
SKProduct *prod = nil;
for (SKProduct *pro in product) {
if ([pro.productIdentifier isEqualToString:self.productID]) {
prod = pro;
}
}
// 發(fā)送購買請求
if (prod != nil) {
SKPayment *payment = [SKPayment paymentWithProduct:prod];
[[SKPaymentQueue defaultQueue]addPayment:payment];
}
}
// 失敗回調(diào)
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error{
[SVProgressHUD dismiss];
[HudManager showMessage:@"購買失敗"];
}
// 支付后的反饋信息
- (void)requestDidFinish:(SKRequest *)request{
[SVProgressHUD dismiss];
}
// 監(jiān)聽購買結(jié)果
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions{
for (SKPaymentTransaction *tran in transactions) {
switch (tran.transactionState) {
case SKPaymentTransactionStatePurchased:
[self verifyPurchaseWithPaymentTransactionWith:tran];
break;
case SKPaymentTransactionStatePurchasing:
NSLog(@"商品已經(jīng)添加進列表");
break;
case SKPaymentTransactionStateRestored:
NSLog(@"已經(jīng)購買過商品");
[[SKPaymentQueue defaultQueue] finishTransaction:tran];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"購買失敗");
[[SKPaymentQueue defaultQueue] finishTransaction:tran];
[HudManager showMessage:@"購買失敗"];
break;
default:
break;
}
}
}
/**
* 驗證購買因痛,避免越獄軟件模擬蘋果請求達到非法購買問題
*
*/
-(void)verifyPurchaseWithPaymentTransactionWith:(SKPaymentTransaction *)tran{
//從沙盒中獲取交易憑證并且拼接成請求體數(shù)據(jù)
NSURL *receiptUrl=[[NSBundle mainBundle] appStoreReceiptURL];
NSData *receiptData=[NSData dataWithContentsOfURL:receiptUrl];
NSString *receiptString = [receiptData base64EncodedStringWithOptions:0];
if (!receiptString) {
return;
}
// 將base64 編碼 發(fā)給后臺服務(wù)器 做驗證 以及是否是沙箱環(huán)境的參數(shù)
NSDictionary *dict = [NSDictionary universalParameteWithDictionary:@{@"receipt":receiptString,
@"sandbox":BOOLSandBox,
}];
[[LFBHTTPSessionManager manager]POSTwithURLString:KApplePay_Docheck parameters:dict success:^(id data) {
[self loadData];
[[SKPaymentQueue defaultQueue] finishTransaction:tran];
} failed:^(NSError *error) {
// [HudManager showMessage:error.description];
}];
}
- (void)dealloc{
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
}
三婚苹、注意事項
1.接入內(nèi)購后把支付寶、微信支付的SDK刪掉鸵膏,蘋果那邊能掃出來(因為這個原因我被拒過)膊升。
2.內(nèi)購商品是和項目一起提交然后審核過了商品才有效!
3.測試內(nèi)購一定要用真機測試谭企,商品信息如果無效廓译,一般是 商品還沒有審核通過 !