SDKInterface.m
8.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//
// UnionInterface.m
// PoolSdk
//
// Created by winFan on 11/23/15.
// Copyright (c) 2015 winFan. All rights reserved.
//
#include "SDKInterface.h"
#import <UIKit/UIKit.h>
#import <CSSYGameSDK/CSSYGameSDK.h>
@interface SDKInterface()
{
UIViewController* gameViewController;
NSString* sessionId;
}
@end
@implementation SDKInterface : Interface
/**
初始化SDK
*/
- (void)SDKinit:(UIViewController *) control
{
//必须继承
[super SDKinit:control];
gameViewController = control;
[PoolConfig getInstance];
NSString* referer = [[PoolConfig getInstance]getValueByKey:@"gamechannelid"];
NSString* gameId = [[PoolConfig getInstance]getValueByKey:@"gameID"];
NSString* gameName = [[PoolConfig getInstance]getValueByKey:@"gamename"];
NSString* key = [[PoolConfig getInstance]getValueByKey:@"key"];
[CSGameActivation connectionSDK:referer gameID:gameId gameName:gameName statisticsKey:key];
int platform = [[PoolConfig getInstance]getValueByKey:@"platform"].intValue;
[CSGameActivation setPlatform:platform];
[CSGameActivation setDebug:YES];
[[PoolChecker getInstance] sendNotice:PoolSDKNotificationInitSDK notiName:@"InitSuccess" statusCode:POOLSDK_NO_ERROR description:@"initSuccess" extendData:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AccountLogout) name:CSGame_Account_LogoutSuccess object:nil];
}
/**
登录SDK
*/
- (void)SDKloginSDK
{
NSLog(@"调用了LoginSDK");
[CSGameAuth connectionLoginForController:gameViewController animated:NO block:^(NSString *userName, NSString *sessionID, NSString *timestamp, NSString *token) {
NSLog(@"userName:%@",userName);
sessionId = sessionID;
PoolLoginInfo* loginInfo = [PoolLoginInfo alloc];
[loginInfo setTimestamp:timestamp];
[loginInfo setOpenId:userName];
[loginInfo setSign:token];
[loginInfo setOther:sessionID];
[self loginCheck:loginInfo];
} dismissSuccess:^{
}];
}
- (void)loginCheck:(PoolLoginInfo*) loginInfo{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[PoolChecker getInstance] startCheck:loginInfo];
});
}
/**
支付 创建订单
*/
- (void)SDKpayWithPaymentInfo:(PoolCreateOrderInfo *)payInfo
{
[super SDKpayWithPaymentInfo:payInfo];
}
/**
SDK
*/
- (void)SDKgotoUserCenter
{
}
- (void)SDKreport:(PoolReportInfo *)reportInfo
{
NSLog(@"reportInfo");
if ([REPORT_CREATEROLE isEqualToString:[reportInfo reportType]]) {
}else if ([[reportInfo reportType] isEqualToString:REPORT_ENTER]) {
[CSGameActivation setServer:[reportInfo serverId]];
[CSGameAuth loginValidationWithSessionID:sessionId block:^(BOOL loginState) {
if (loginState) {
[CSGameAuth EnterData];
}
}];
}else if([[reportInfo reportType ]isEqualToString:REPORT_ROLEUPGRADE]){
[CSGamePush setlevel:[reportInfo playerLevel].intValue];
}
}
/**
SDK
*/
- (void)SDKexitSDK
{
}
-(void)AccountLogout
{
//do someting
[[PoolChecker getInstance] sendNotice:PoolSDKNotificationLogout notiName:@"logoutSuccess" statusCode:POOLSDK_NO_ERROR description:@"logoutSuccess" extendData:nil];
}
-(BOOL)hasLogout
{
return YES;
}
- (void)SDKlogoutSDK
{
NSLog(@"切换账号");
[CSGameAuth connectionLogoutWithBlock:^(BOOL state) {
[self AccountLogout];
}];
}
- (void)handleOpenurl:(NSURL *)url
{
}
- (void)receivePayMessage : (NSNotification *)notification;
{
NSString *order_id = [notification object];
NSLog(@"订单ID:%@", order_id);
}
/**
@return 商品名称
*/
- (NSString*)getProductNameByAmount:(NSString*)products amount:(NSString*)amount
{
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:products options:NSJSONWritingPrettyPrinted error:nil];
if(jsonData){
NSDictionary* productList = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
if(productList){
NSEnumerator* keysList = [productList keyEnumerator];
id keyValue;
while (keyValue = [keysList nextObject])
{
NSString* appleAmount = [[productList objectForKey:keyValue] objectForKey:@"amount"];
if(appleAmount.intValue == amount.intValue){
NSString* productName = [[productList objectForKey:keyValue] objectForKey:@"name"];
return productName;
}
}
}
}
NSLog(@"get product name error amount:%@",amount);
return @"元宝";
}
/**
@return 商品ID
*/
- (NSString*)getProductIdByAmount:(NSString*)products amount:(NSString*)amount
{
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:products options:NSJSONWritingPrettyPrinted error:nil];
if(jsonData){
NSDictionary* productList = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
if(productList){
NSEnumerator* keysList = [productList keyEnumerator];
id keyValue;
while (keyValue = [keysList nextObject])
{
NSLog(@"i found %@",keyValue);
NSString* appleAmount = [[productList objectForKey:keyValue] objectForKey:@"amount"];
NSLog(@"appleAmount:%@ amount:%@",appleAmount,amount);
if(appleAmount.intValue == amount.intValue){
return keyValue;
}
}
}
}
return @"unknow";
}
- (void)receiveCreateOrder:(NSNotification *)notification
{
NSLog(@"创建订单成功");
PoolPayInfo *payInfo = [notification object];
NSString *myamount = [payInfo postAmount];
NSString *queryId = [payInfo queryId];
NSString* productId = [self getProductIdByAmount:[payInfo products] amount:myamount];
[CSGameIAPShare IAPShareBuyObject:productId Amount:myamount ExtraInfo:queryId block:^(BOOL state, NSString *error) {
}];
}
-(NSString*)getCurrentTimestamp{
// 时间戳转时间
NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;
NSString* timeStr = [[NSString alloc]initWithFormat:@"%.f",interval];
return timeStr;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[CSGamePush handleLaunching:launchOptions
successCallback:^{
NSLog(@"Handle receive success");
} errorCallback:^{
NSLog(@"Handle receive error");
}];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *deviceTokenStr = [CSGamePush registerDevice:deviceToken successCallback:^{
NSLog(@"register push success");
} errorCallback:^{
NSLog(@" register push error");
}];
NSLog(@"device token is %@", deviceTokenStr);
}
// 收到通知的回调
// @param application UIApplication 实例
// @param userInfo 推送时指定的参数
// */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@" receive Notification");
[CSGamePush handleReceiveNotification:userInfo
successCallback:^{
NSLog(@" Handle receive success");
} errorCallback:^{
NSLog(@" Handle receive error");
}];
}
/**
收到静默推送的回调
@param application UIApplication 实例
@param userInfo 推送时指定的参数
@param completionHandler 完成回调
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@" receive slient Notification");
[CSGamePush handleReceiveNotification:userInfo
successCallback:^{
NSLog(@" Handle receive success");
} errorCallback:^{
NSLog(@" Handle receive error");
}];
completionHandler(UIBackgroundFetchResultNewData);
}
@end