SDKInterface.m
9.99 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
#include "SDKInterface.h"
#import <UIKit/UIKit.h>
#import "Yeboda/YebodaAllManager.h"
#import "Yeboda/YebodaHuiTiaoNotification.h"
#import "Yeboda/YebodaInformation.h"
#import "TrackingIO.h"
@implementation SDKInterface : Interface
int mExchange;
NSString *YebodaAppId;
NSString *YebodaAppKey;
NSString *YebodaLeakOrderUrl;
- (void)SDKinit:(UIViewController *) control
{
[super SDKinit:control];
[HaiBaoJuheConfig getInstance];
[[YebodaAllManager YebodaInstance]YebodaChuShiHua];
[[YebodaAllManager YebodaInstance]YebodaYangShi:@"sdk"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveLoginMessage:) name:YebodaLoginNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(HCKAssetsToolCallBack:) name:@"YebodaToolCallBack" object:nil];
[[HaiBaoJuheChecker getInstance] sendNotice:HaiBaoJuheSDKNotificationInitSDK notiName:@"InitSuccess" statusCode:HaiBaoJuheSDK_NO_ERROR description:@"initSuccess" extendData:nil];
NSString* channelId = [[HaiBaoJuheConfig getInstance] getValueByKey:@"gamechannelid"];
if(channelId == nil || [channelId length] <= 0){
channelId = @"unknown";
}
[TrackingIO initWithappKey:[[HaiBaoJuheConfig getInstance] getValueByKey:@"renyunAppKey"] withChannelId:channelId];
}
/**
登录SDK
*/
- (void)SDKloginSDK
{
//APPID APPKEY
YebodaAppId = [[HaiBaoJuheConfig getInstance] getValueByKey:@"APP_ID"];
YebodaAppKey =[[HaiBaoJuheConfig getInstance] getValueByKey:@"APP_KEY"];
[[YebodaAllManager YebodaInstance]YebodaDengLu:YebodaAppId :YebodaAppKey :self.controller];
}
/**
loginCheck
*/
- (void)receiveLoginMessage:(NSNotification *)notification
{
NSLog(@"loginchek");
HaiBaoJuheLoginInfo *loginInfo = [HaiBaoJuheLoginInfo alloc];
loginInfo.openId = [[YebodaInformation getInstance]openId];
loginInfo.sign = [[YebodaInformation getInstance] token];
loginInfo.timestamp = [[YebodaInformation getInstance] timestamp];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[HaiBaoJuheChecker getInstance] startCheck:loginInfo];
});
}
-(NSString*)DataTojsonString:(id)object
{
NSString *jsonString = nil;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
jsonString = [jsonData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
return jsonString;
}
/**
苹果支付结果回调
*/
- (void)HCKAssetsToolCallBack:(NSNotification *)notification
{
NSDictionary* payResultDic = notification.object;
NSString* receiptStr = [payResultDic objectForKey:@"YebodaToolResult"];
NSString* queryId = [payResultDic objectForKey:@"query_id"];
//收到回调,保存queryid和data
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableArray* queryIdArray = [userDefaults objectForKey:@"queryIds"];
NSMutableArray* tempQueryIdArray = [[NSMutableArray alloc] initWithCapacity:10];
if (queryIdArray) {
}else{
queryIdArray = [[NSMutableArray alloc]initWithCapacity:10];
}
for (NSString* arrayQueryId in queryIdArray) {
[tempQueryIdArray addObject:arrayQueryId];
}
[tempQueryIdArray addObject:queryId];
[userDefaults setObject:tempQueryIdArray forKey:@"queryIds"];
[userDefaults setObject:receiptStr forKey:queryId];
NSDictionary* receiptDic = [NSDictionary dictionaryWithObjectsAndKeys:receiptStr,@"receipt",queryId,@"query_id", nil];
NSString* result = [[NetCenter getInstance] httpPostSyn:YebodaLeakOrderUrl :receiptDic];
if([@"success" isEqualToString:result]){//确认订单成功
//删除已保存的
[userDefaults removeObjectForKey:queryId];
[tempQueryIdArray removeObject:queryId];
[userDefaults setObject:tempQueryIdArray forKey:@"queryIds"];
[userDefaults removeObjectForKey:@"lastqueryid"];
}
[userDefaults synchronize];
}
/**
支付 创建订单
*/
- (void)SDKgzyazfWithGzyazfmentInfo:(HaiBaoJuheCreateOrderInfo *)payInfo
{
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
NSString* lastqueryid = [userDefaults objectForKey:@"lastqueryid"];
YebodaLeakOrderUrl = [[NSString alloc] initWithFormat:@"%@?uid=%@&playerid=%@",
[HaiBaoJuheUtils createGzyazfUrl],
[payInfo userId],
[payInfo playerId]];
[userDefaults setObject:YebodaLeakOrderUrl forKey:@"lastYebodaLeakOrderUrl"];
if (lastqueryid!=nil) {
//创建订单前进行补单
NSData* receiptData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSString* receiptStr = [receiptData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
if (receiptStr!=nil) {
receiptStr = [receiptStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
//如果不为空,进行最后一次补单
NSDictionary* receiptDic = [NSDictionary dictionaryWithObjectsAndKeys:receiptStr,@"receipt",lastqueryid,@"query_id", nil];
NSString* result = [[NetCenter getInstance] httpPostSyn:YebodaLeakOrderUrl :receiptDic];
if([@"success" isEqualToString:result]){//确认订单成功
//删除已保存的
[userDefaults removeObjectForKey:@"lastqueryid"];
}
}
}
mExchange = [payInfo exchange].intValue;
[super SDKgzyazfWithGzyazfmentInfo:payInfo];
YebodaLeakOrderUrl = [[NSString alloc] initWithFormat:@"%@?uid=%@&playerid=%@",
[HaiBaoJuheUtils createGzyazfUrl],
[payInfo userId],
[payInfo playerId]];
[userDefaults synchronize];
}
/**
SDK
*/
- (void)SDKgotoUserCenter
{
}
- (void)SDKreport:(HaiBaoJuheReportInfo *)reportInfo
{
NSLog(@"reportInfo");
NSString* reportType = [reportInfo reportType];
if (reportInfo) {
if ([reportType isEqualToString:REPORT_ENTER]) {
[TrackingIO setLoginWithAccountID:[reportInfo playerId]];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[self handlerLeakOrder];
});
}else if ([reportType isEqualToString:REPORT_CREATEROLE]){
[TrackingIO setRegisterWithAccountID:[reportInfo playerId]];
}
}
}
/**
SDK
*/
- (void)SDKexitSDK
{
}
- (void)SDKlogoutSDK
{
NSLog(@"切换账号");
}
- (void)handleOpenurl:(NSURL *)url
{
}
- (void)receivePayMessage : (NSNotification *)notification;
{
NSString *order_id = [notification object];
NSLog(@"订单ID:%@", order_id);
}
//补单处理
- (void) handlerLeakOrder{
NSUserDefaults* userDefaults2 = [NSUserDefaults standardUserDefaults];
NSMutableArray* queryIdArray = [userDefaults2 objectForKey:@"queryIds"];
NSLog(@"orderDic%@",queryIdArray);
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableArray* failQueryIdArray = [[NSMutableArray alloc]initWithCapacity:10];
if(queryIdArray){
for (NSString* queryId in queryIdArray) {
NSString* receiptStr = [userDefaults valueForKey:queryId];
NSDictionary* receiptDic = [NSDictionary dictionaryWithObjectsAndKeys:receiptStr,@"receipt",queryId,@"query_id", nil];
NSString* lastYebodaLeakOrderUrl = [userDefaults objectForKey:@"lastYebodaLeakOrderUrl"];
NSString* result;
if (lastYebodaLeakOrderUrl!=nil) {
result = [[NetCenter getInstance] httpPostSyn:lastYebodaLeakOrderUrl :receiptDic];
}else{
result = [[NetCenter getInstance] httpPostSyn:[HaiBaoJuheUtils createGzyazfUrl] :receiptDic];
}
if([@"success" isEqualToString:result]){//成功
[userDefaults removeObjectForKey:queryId];
}else{//补单失败
[failQueryIdArray addObject:queryId];
}
}
if([failQueryIdArray count] > 0){//含有补单失败项
[userDefaults setObject:failQueryIdArray forKey:@"queryIds"];
}else{//全部补单成功
[userDefaults removeObjectForKey:@"queryIds"];
}
[userDefaults synchronize];
}
}
- (void)receiveCreateOrder:(NSNotification *)notification
{
NSLog(@"创建订单成功");
HaiBaoJuheGzyazfInfo *payInfo = [notification object];
NSNumber *amount = @([[payInfo postAmount] integerValue] * mExchange);
NSString *serverId = [payInfo serverId];
NSString *roleName = [payInfo playerName];
NSString *queryId = [payInfo queryId];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[self handlerLeakOrder];
});
NSString *other = [payInfo other];
if (other && [other length] > 0) {
[[YebodaAllManager YebodaInstance] YebodaQuery:serverId :roleName :amount :[payInfo queryId] :self.controller :[payInfo serverName]];
}else{
NSString* products = [payInfo products];
//保存订单号到本地
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:queryId forKey:@"lastqueryid"];
[userDefaults synchronize];
[[YebodaAllManager YebodaInstance] YebodaQueryOperation:self.controller YebodaHuoWuID:products YebodaJiaGe:[payInfo postAmount] YebodaHuoWuMing:[payInfo productName] YebodaDingDanHao:queryId];
}
}
-(void)paymentSuccess:(NSString *)accountId orderId:(NSString *)orderId currencyAmount:(double)amount currencyType:(NSString *)currencyType payType:(NSString *)payType custom:(NSArray *)customArray
{
[TrackingIO setPayment:orderId paymentType:payType currentType:currencyType currencyAmount:amount];
}
@end