SDKInterface.m
10.1 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//
// 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 <XFLoginSDK/XFLoginViewSDK.h>
#import <PaymentSDK/XFPayment.h>
#import <XFTrackIO/XFTrackIO.h>
@implementation SDKInterface : Interface
NSString *_openId;
NSString *_serverId;
NSString *_serverName;
NSString *_roleId;
NSString *_roleName;
/**
初始化SDK
*/
- (void)SDKinit:(UIViewController *) control
{
//必须继承
[super SDKinit:control];
[PoolConfig getInstance];
_openId = nil;
_serverId = nil;
_serverName = nil;
_roleId = nil;
_roleName = nil;
NSString* appId = [[PoolConfig getInstance]getValueByKey:@"sdkAppId"];
NSString* packageId = [[PoolConfig getInstance]getValueByKey:@"sdkPackageId"];
NSString* appKey = [[PoolConfig getInstance]getValueByKey:@"sdkAppKey"];
NSString* reyunKey = [[PoolConfig getInstance]getValueByKey:@"sdkReyunKey"];
[[XFPayment sharedInstance]
initWithAppid:appId //应用id(三端通用)
andPackageId:packageId //包id(三端通用)
andAppKey:appKey];//应用key(三端通用)
[[XFLoginViewSDK sharedInstance]
initWithAPPId:appId //应用id(三端通用)
andPackageId:packageId //包id(三端通用)
andAppKey:appKey];//应用key(三端通用)
[[XFTrackIO sharedInstance]
initWithAppid:appId //应用id(三端通用)
andPackageId:packageId //包id(三端通用)
andAppKey:appKey //应用key(三端通用)
andReyunKey:reyunKey];//热云key
[[XFTrackIO sharedInstance] setLogPrint:YES];//是否显示日志,默认NO
[[XFLoginViewSDK sharedInstance] setXFLoginDelegate:self];
[[XFPayment sharedInstance] setXFpayDelegate:self];
[[PoolChecker getInstance] sendNotice:PoolSDKNotificationInitSDK notiName:@"InitSuccess" statusCode:POOLSDK_NO_ERROR description:@"initSuccess" extendData:nil];
}
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
[[XFPayment sharedInstance] application:application openUrl:url];
return YES;
}
//#ifdef __IPHONE_9_0
//-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
// [[XFPayment sharedInstance] application:app openUrl:url];
// return YES;
//}
//#else
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
[[XFPayment sharedInstance] application:application openUrl:url];
return YES;
}
//#endif
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
/**
登录SDK
*/
- (void)SDKloginSDK
{
NSLog(@"调用了LoginSDK");
[[XFLoginViewSDK sharedInstance] OnLogin];
}
#pragma mark - Login Delegate//返回登录ID和登录标识
-(void)SDKLoginSuccessWithData:(NSDictionary *)dic{
NSLog(@"登录成功:%@",dic);//返回openId和token
PoolLoginInfo *loginInfo = [[PoolLoginInfo alloc]init];
loginInfo.openId = [dic objectForKey:@"openId"];//渠道userId
loginInfo.timestamp = [self getCurrentTimestamp];
loginInfo.sign = [dic objectForKey:@"token"];//渠道SDK的token
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[PoolChecker getInstance]startCheck:loginInfo];//登录验证请求
});
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:[dic objectForKey:@"openId"] forKey:@"openId"]; //帐号唯一ID
[[XFTrackIO sharedInstance]
startTrackWithType:XFTrackIOTypeAccountRegist
andTrackData:dict];
}
- (void)SDKreport:(PoolReportInfo *)reportInfo
{
NSLog(@"reportInfo");
if ([REPORT_CREATEROLE isEqualToString:[reportInfo reportType]]) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:[reportInfo openId] forKey:@"openId"];//登录ID
[dict setValue:[reportInfo serverId] forKey:@"serverId"];//服务器ID
[dict setValue:[reportInfo serverName] forKey:@"serverName"];//服务器名称
[dict setValue:[reportInfo playerId] forKey:@"roleId"];//角色ID
[dict setValue:[reportInfo playerName] forKey:@"roleName"];//角色名称
[[XFTrackIO sharedInstance]
startTrackWithType:XFTrackIOTypeEnterGame
andTrackData:dict];
}else if ([[reportInfo reportType] isEqualToString:REPORT_ENTER]) {
#if ! __has_feature(objc_arc)
if (_openId) {
[_openId release];
}
_openId = [reportInfo openId];
[_openId retain];
#else
_openId = [reportInfo openId];
#endif
#if ! __has_feature(objc_arc)
if (_serverId) {
[_serverId release];
}
_serverId = [reportInfo openId];
[_serverId retain];
#else
_serverId = [reportInfo openId];
#endif
#if ! __has_feature(objc_arc)
if (_serverName) {
[_serverName release];
}
_serverName = [reportInfo openId];
[_serverName retain];
#else
_serverName = [reportInfo openId];
#endif
#if ! __has_feature(objc_arc)
if (_roleId) {
[_roleId release];
}
_roleId = [reportInfo openId];
[_roleId retain];
#else
_roleId = [reportInfo openId];
#endif
#if ! __has_feature(objc_arc)
if (_roleName) {
[_roleName release];
}
_roleName = [reportInfo openId];
[_roleName retain];
#else
_roleName = [reportInfo openId];
#endif
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:[reportInfo openId] forKey:@"openId"];//登录ID
[dict setValue:[reportInfo serverId] forKey:@"serverId"];//服务器ID
[dict setValue:[reportInfo serverName] forKey:@"serverName"];//服务器名称
[dict setValue:[reportInfo playerId] forKey:@"roleId"];//角色ID
[dict setValue:[reportInfo playerName] forKey:@"roleName"];//角色名称
[[XFTrackIO sharedInstance]
startTrackWithType:XFTrackIOTypeEnterGame
andTrackData:dict];
}
}
/**
@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 *openId = [payInfo playerId];
NSString *myamount = [payInfo postAmount];
NSString *queryId = [payInfo queryId];
NSString *productId = [self getProductIdByAmount:payInfo.products amount:myamount];
NSLog(@"receiveCreateOrder openid %@ amount %@ queryId %@, product %@", openId, myamount, queryId, productId);
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:openId forKey:@"openId"];
[dict setValue:myamount forKey:@"money"];
[dict setValue:queryId forKey:@"extra"];
[dict setValue:productId forKey:@"orderid"];
[[XFPayment sharedInstance] payWithOrderInfo:dict];
}
#pragma mark - Pay Delegate //支付返回订单号和金额
-(void)ApplePayResult:(PayResultNum)result resultData:(NSDictionary *)data{
if (result == PayResultNumSuccess) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:_openId forKey:@"openId"];//登录ID
[dict setValue:_serverId forKey:@"serverId"];//服务器ID
[dict setValue:_serverName forKey:@"serverName"]; //服务器名称
[dict setValue:_roleId forKey:@"roleId"];//角色ID
[dict setValue:_roleName forKey:@"roleName"];//角色名称
[dict setValue:[data objectForKey:@"money"] forKey:@"money"];// 支付金额
[dict setValue:[data objectForKey:@"orderId"] forKey:@"orderId"]; // 支付订单ID
[[XFTrackIO sharedInstance]
startTrackWithType:XFTrackIOTypePay
andTrackData:dict];
}
}
-(NSString*)getCurrentTimestamp{
// 时间戳转时间
NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;
NSString* timeStr = [[NSString alloc]initWithFormat:@"%.f",interval];
return timeStr;
}
@end