======================第一部分協(xié)議===============
第一步.png
第二步.jpg
第三步.jpg
第四步.png
第五步.png
第六步.png
第七步.jpg
第八步.jpg
第九步.jpg
第十步.png
CNAPS CODE 查詢地址
https://e.czbank.com/CORPORBANK/query_unionBank_index.jsp
十一步.jpg
十二步.jpg
十三步.png
十四步.png
十五步.jpg
十七步.jpg
十八步.jpg
十九步.png
2016/11/18號(hào)更新
十九步(1).png
十九步(2).png
沒(méi)顯示的都是可以不填的,主要是打鉤? title 和最后面的Self
二十步.png
=============第二部分創(chuàng)建內(nèi)購(gòu)項(xiàng)目============
1.png
2.png
3.png
4.png
5.png
6.png
7.png
===========第三部分貼加內(nèi)購(gòu)項(xiàng)目測(cè)試賬號(hào)==========
創(chuàng)建測(cè)試賬號(hào).png
沙盒測(cè)試員.png
賬號(hào)信息.png
=============第四部分主要實(shí)現(xiàn)代碼==========
首先導(dǎo)入StoreKit.framework庫(kù)
.h文件
#import<StoreKit/StoreKit.h>
enum{
IAP0p20=20,
IAP1p100,
IAP4p600,
IAP9p1000,
IAP24p6000
}buyCoinsTag;
//代理
@interfaceRechargeVC:UIViewController<SKPaymentTransactionObserver,SKProductsRequestDelegate>
{
intbuyType;
}
- (void) requestProUpgradeProductData;
-(void)RequestProductData;
-(void)buy:(int)type;
- (void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*)transactions;
-(void) PurchasedTransaction: (SKPaymentTransaction*)transaction;
- (void) completeTransaction: (SKPaymentTransaction*)transaction;
- (void) failedTransaction: (SKPaymentTransaction*)transaction;
-(void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentTransaction*)transaction;
-(void) paymentQueue:(SKPaymentQueue*) paymentQueue restoreCompletedTransactionsFailedWithError:(NSError*)error;
- (void) restoreTransaction: (SKPaymentTransaction*)transaction;
-(void)provideContent:(NSString*)product;
-(void)recordTransaction:(NSString*)product;
@end
.m文件
#import"RechargeVC.h"
//在內(nèi)購(gòu)項(xiàng)目中創(chuàng)的商品單號(hào)
#define ProductID_IAP0p20@"Nada.JPYF01"http://20
#define ProductID_IAP1p100 @"Nada.JPYF02"http://100
#define ProductID_IAP4p600 @"Nada.JPYF03"http://600
#define ProductID_IAP9p1000 @"Nada.JPYF04"http://1000
#define ProductID_IAP24p6000@"Nada.JPYF05"http://6000
@interfaceRechargeVC()
@end
@implementation RechargeVC
- (void)viewDidLoad {
? [superviewDidLoad];? ?
[[SKPaymentQueuedefaultQueue] addTransactionObserver:self];? ?
[selfbuy:IAP0p20];
}
-(void)buy:(int)type{?
? buyType = type;
if([SKPaymentQueuecanMakePayments]) {
? [selfRequestProductData];
NSLog(@"允許程序內(nèi)付費(fèi)購(gòu)買(mǎi)");
}else{
NSLog(@"不允許程序內(nèi)付費(fèi)購(gòu)買(mǎi)");
UIAlertView*alerView =? [[UIAlertViewalloc] initWithTitle:@"提示"message:@"您的手機(jī)沒(méi)有打開(kāi)程序內(nèi)付費(fèi)購(gòu)買(mǎi)"delegate:nilcancelButtonTitle:NSLocalizedString(@"關(guān)閉",nil) otherButtonTitles:nil];? ?
[alerView show];? ?
}
}
-(void)RequestProductData{
NSLog(@"---------請(qǐng)求對(duì)應(yīng)的產(chǎn)品信息------------");
NSArray*product =nil;
switch(buyType) {
caseIAP0p20:? ? ? ?
product=[[NSArrayalloc] initWithObjects:ProductID_IAP0p20,nil];
break;
caseIAP1p100:? ? ??
product=[[NSArrayalloc] initWithObjects:ProductID_IAP1p100,nil];
break;
caseIAP4p600:? ? ? ?
product=[[NSArrayalloc] initWithObjects:ProductID_IAP4p600,nil];
break;
caseIAP9p1000:? ? ??
product=[[NSArrayalloc] initWithObjects:ProductID_IAP9p1000,nil];
break;
caseIAP24p6000:? ? ? ?
product=[[NSArrayalloc] initWithObjects:ProductID_IAP24p6000,nil];
break;
default:
break;
}
NSSet*nsset = [NSSetsetWithArray:product];
SKProductsRequest*request=[[SKProductsRequestalloc] initWithProductIdentifiers: nsset];? ? request.delegate=self;?
? [request start];
}
// 請(qǐng)求協(xié)議//收到的產(chǎn)品信息
- (void)productsRequest:(SKProductsRequest*)request didReceiveResponse:(SKProductsResponse*)response{
NSLog(@"-----------收到產(chǎn)品反饋信息--------------");
NSArray*myProduct = response.products;
NSLog(@"產(chǎn)品Product ID:%@",response.invalidProductIdentifiers);
NSLog(@"產(chǎn)品付費(fèi)數(shù)量: %d", (int)[myProduct count]);
// populate UI
for(SKProduct*productinmyProduct){
NSLog(@"product info");
NSLog(@"SKProduct 描述信息%@", [product description]);
NSLog(@"產(chǎn)品標(biāo)題 %@", product.localizedTitle);
NSLog(@"產(chǎn)品描述信息: %@", product.localizedDescription);
NSLog(@"價(jià)格: %@", product.price);
NSLog(@"Product id: %@", product.productIdentifier);
}
SKPayment*payment =nil;
switch(buyType) {
caseIAP0p20:? ? ? ?
payment? = [SKPaymentpaymentWithProductIdentifier:ProductID_IAP0p20];//支付25
break;
caseIAP1p100:? ? ?
payment? = [SKPaymentpaymentWithProductIdentifier:ProductID_IAP1p100];//支付108
break;
caseIAP4p600:? ? ? ?
payment? = [SKPaymentpaymentWithProductIdentifier:ProductID_IAP4p600];//支付618
break;
caseIAP9p1000:? ? ??
payment? = [SKPaymentpaymentWithProductIdentifier:ProductID_IAP9p1000];//支付1048
break;
caseIAP24p6000:? ? ? ?
payment? = [SKPaymentpaymentWithProductIdentifier:ProductID_IAP24p6000];//支付5898
break;
default:
break;
}NSLog(@"---------發(fā)送購(gòu)買(mǎi)請(qǐng)求------------");?
? [[SKPaymentQueuedefaultQueue] addPayment:payment];
}
- (void)requestProUpgradeProductData{
NSLog(@"------請(qǐng)求升級(jí)數(shù)據(jù)---------");
NSSet*productIdentifiers = [NSSetsetWithObject:@"com.productid"];
SKProductsRequest* productsRequest = [[SKProductsRequestalloc] initWithProductIdentifiers:productIdentifiers];??
productsRequest.delegate =self;??
[productsRequest start];
}
//彈出錯(cuò)誤信息
- (void)request:(SKRequest*)request didFailWithError:(NSError*)error{
NSLog(@"-------彈出錯(cuò)誤信息----------");
UIAlertView*alerView =? [[UIAlertViewalloc] initWithTitle:NSLocalizedString(@"Alert",NULL) message:[error localizedDescription]? ? delegate:nilcancelButtonTitle:NSLocalizedString(@"Close",nil) otherButtonTitles:nil];?
? [alerView show];
}
-(void) requestDidFinish:(SKRequest*)request{
NSLog(@"----------反饋信息結(jié)束--------------");
}
-(void) PurchasedTransaction: (SKPaymentTransaction*)transaction{
NSLog(@"-----PurchasedTransaction----");
NSArray*transactions =[[NSArrayalloc] initWithObjects:transaction,nil];??
[selfpaymentQueue:[SKPaymentQueuedefaultQueue] updatedTransactions:transactions];
}
// 千萬(wàn)不要忘記綁定庞溜,代碼如下://----監(jiān)聽(tīng)購(gòu)買(mǎi)結(jié)果//[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
- (void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*)transactions
//交易結(jié)果
{
NSLog(@"-----paymentQueue--------");
for(SKPaymentTransaction*transactionintransactions)? ? {
switch(transaction.transactionState){
caseSKPaymentTransactionStatePurchased:{
//交易完成
[selfcompleteTransaction:transaction];
NSLog(@"-----交易完成 --------");
UIAlertView*alerView =? [[UIAlertViewalloc] initWithTitle:@""message:@"購(gòu)買(mǎi)成功"delegate:nilcancelButtonTitle:NSLocalizedString(@"關(guān)閉",nil) otherButtonTitles:nil];? ? ? ? ? ? [alerView show];?
? ? ? }
break;
caseSKPaymentTransactionStateFailed:/
/交易失敗
{
[selffailedTransaction:transaction];
NSLog(@"-----交易失敗 --------");
UIAlertView*alerView2 =? [[UIAlertViewalloc] initWithTitle:@"提示"message:@"購(gòu)買(mǎi)失敗,請(qǐng)重新嘗試購(gòu)買(mǎi)"delegate:nilcancelButtonTitle:NSLocalizedString(@"關(guān)閉",nil) otherButtonTitles:nil];? ? ? ? ? ? [alerView2 show];? ??
? }
break;
caseSKPaymentTransactionStateRestored:
//已經(jīng)購(gòu)買(mǎi)過(guò)該商品[selfrestoreTransaction:transaction];
NSLog(@"-----已經(jīng)購(gòu)買(mǎi)過(guò)該商品 --------");
caseSKPaymentTransactionStatePurchasing:
//商品添加進(jìn)列表NSLog(@"-----商品添加進(jìn)列表 --------");
break;
default:
break;? ??
}??
}
}
- (void) completeTransaction: (SKPaymentTransaction*)transaction{
NSLog(@"-----completeTransaction--------");
// Your application should implement these two methods.
NSString*product = transaction.payment.productIdentifier;
if([product length] >0) {
NSArray*tt = [product componentsSeparatedByString:@"."];
NSString*bookid = [tt lastObject];
if([bookid length] >0) {
? [selfrecordTransaction:bookid];
? [selfprovideContent:bookid];
}
}
// Remove the transaction from the payment queue.
[[SKPaymentQueuedefaultQueue] finishTransaction: transaction];
}
//記錄交易
-(void)recordTransaction:(NSString*)product{
NSLog(@"-----記錄交易--------");
}
//處理下載內(nèi)容
-(void)provideContent:(NSString*)product{NSLog(@"-----下載--------");
}
- (void) failedTransaction: (SKPaymentTransaction*)transaction{
NSLog(@"失敗");
if(transaction.error.code !=SKErrorPaymentCancelled)? ? {?
? }??
[[SKPaymentQueuedefaultQueue] finishTransaction: transaction];
}
-(void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentTransaction*)transaction{
}
- (void) restoreTransaction: (SKPaymentTransaction*)transaction{
NSLog(@" 交易恢復(fù)處理");
}
-(void) paymentQueue:(SKPaymentQueue*) paymentQueue restoreCompletedTransactionsFailedWithError:(NSError*)error{
NSLog(@"-------paymentQueue----");
}
#pragma mark connection delegate
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data{
NSLog(@"%@",? [[NSStringalloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
- (void)connectionDidFinishLoading:(NSURLConnection*)connection{}- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response{
switch([(NSHTTPURLResponse*)response statusCode]) {
case200:
case206:
break;
case304:
break;
case400:
break;
case404:
break;
case416:
break;
case403:
break;
case401:
case500:
break;
default:
break;??
}
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error {
NSLog(@"test");
}
-(void)dealloc{
? ? [[SKPaymentQueuedefaultQueue] removeTransactionObserver:self];
//解除監(jiān)聽(tīng)
}
@end
2016/11/22更新
內(nèi)購(gòu)項(xiàng)目不再是單獨(dú)提交審核了跌造,只要app提交審核內(nèi)購(gòu)項(xiàng)目自然跟著改變狀態(tài)鼻由,不消耗物品請(qǐng)不要選擇 托管那一項(xiàng),不然會(huì)出現(xiàn)問(wèn)題