351 lines
12 KiB
Plaintext
351 lines
12 KiB
Plaintext
#import "SDK.h"
|
|
#import <superSDK/superSDK.h>
|
|
#import <superSDK/superSDK-Swift.h>
|
|
|
|
extern UIViewController *UnityGetGLViewController();
|
|
|
|
//NSString转char*
|
|
#define MakeStringCopy( _x_ ) ( _x_ != NULL && [_x_ isKindOfClass:[NSString class]] ) ? strdup( [_x_ UTF8String] ) : NULL
|
|
//日志打印
|
|
#define DLOG(...) NSLog(__VA_ARGS__);
|
|
|
|
extern "C"{
|
|
void m_SDK_Init(){
|
|
[[SDK Instance] Init];
|
|
}
|
|
|
|
void m_SDK_Login(){
|
|
[[SDK Instance] Login];
|
|
}
|
|
|
|
void m_SDK_Logout(){
|
|
[[SDK Instance] Logout];
|
|
}
|
|
|
|
bool m_SDK_IsSupportExit(){
|
|
return [[SDK Instance] IsSupportExit];
|
|
}
|
|
|
|
void m_SDK_Exit(){
|
|
[[SDK Instance] ExitGame];
|
|
}
|
|
|
|
void m_SDK_SubmitExtraData(int dataType,int serverId,char* serverName, char* zoneID, char* zoneName, char* roleID, char* roleName, char* roleLevel, char* guildlD, char* Vip, int moneyNum, char* roleCreateTime, char* roleLevelUpTime){
|
|
[[SDK Instance] SubmitExtraData:dataType
|
|
serverId:serverId
|
|
serverName:[NSString stringWithUTF8String:serverName]
|
|
zoneID:[NSString stringWithUTF8String:zoneID]
|
|
zoneName:[NSString stringWithUTF8String:zoneName]
|
|
roleID:[NSString stringWithUTF8String:roleID]
|
|
roleName:[NSString stringWithUTF8String:roleName]
|
|
roleLevel:[NSString stringWithUTF8String:roleLevel]
|
|
guildlD:[NSString stringWithUTF8String:guildlD]
|
|
Vip:[NSString stringWithUTF8String:Vip]
|
|
moneyNum:moneyNum
|
|
roleCreateTime:[NSString stringWithUTF8String:roleCreateTime]
|
|
roleLevelUpTime:[NSString stringWithUTF8String:roleLevelUpTime]];
|
|
}
|
|
|
|
void m_SDK_Pay(char* rechargeId,int showType, int productId, char* productName, char* productDesc,char* price,char* currencyType,int ratio,int buyNum,int coinNum, char* zoneId, char* serverID, char* serverName, char* accounted, char* roleID, char* roleName,int roleLevel, char* Vip, char* guildlD, char* payNotifyUrl, char* extension, char* orderID){
|
|
[[SDK Instance] Pay:[NSString stringWithUTF8String:rechargeId]
|
|
showType:showType
|
|
productId:productId
|
|
productName:[NSString stringWithUTF8String:productName]
|
|
productDesc:[NSString stringWithUTF8String:productDesc]
|
|
price:[NSString stringWithUTF8String:price]
|
|
currencyType:[NSString stringWithUTF8String:currencyType]
|
|
ratio:ratio
|
|
buyNum:buyNum
|
|
coinNum:coinNum
|
|
zoneId:[NSString stringWithUTF8String:zoneId]
|
|
serverID:[NSString stringWithUTF8String:serverID]
|
|
serverName:[NSString stringWithUTF8String:serverName]
|
|
accounted:[NSString stringWithUTF8String:accounted]
|
|
roleID:[NSString stringWithUTF8String:roleID]
|
|
roleName:[NSString stringWithUTF8String:roleName]
|
|
roleLevel:roleLevel
|
|
Vip:[NSString stringWithUTF8String:Vip]
|
|
guildlD:[NSString stringWithUTF8String:guildlD]
|
|
payNotifyUrl:[NSString stringWithUTF8String:payNotifyUrl]
|
|
extension:[NSString stringWithUTF8String:extension]
|
|
orderID:[NSString stringWithUTF8String:orderID]];
|
|
}
|
|
|
|
void m_SDK_Bind(){
|
|
[[SDK Instance] Bind];
|
|
}
|
|
|
|
void m_SDK_Community(){
|
|
[[SDK Instance] Community];
|
|
}
|
|
|
|
void m_SDK_CustomerService(){
|
|
[[SDK Instance] CustomerService];
|
|
}
|
|
|
|
void m_SDK_Relation(char* type){
|
|
|
|
}
|
|
|
|
void m_SDK_Cancellation(){
|
|
|
|
}
|
|
|
|
bool m_SDK_IsCDKey(){
|
|
return false;
|
|
}
|
|
|
|
void m_SDK_CDKey(char* cdkey, char* serverID, char* roleID){
|
|
|
|
}
|
|
|
|
void m_SDK_LoginPanel_Btn1(){
|
|
[[SDK Instance] LoginPanel_Btn1];
|
|
}
|
|
|
|
void m_SDK_LoginPanel_Btn2(){
|
|
[[SDK Instance] LoginPanel_Btn2];
|
|
}
|
|
|
|
void m_SDK_CustomEvent(int type, char* param){
|
|
[[SDK Instance] CustomEvent:type param:[NSString stringWithUTF8String:param]];
|
|
}
|
|
}
|
|
|
|
@implementation SDK
|
|
|
|
NSString* callUnityTargetGameObjectName = @"SDK.SDKManager";
|
|
|
|
static SDK * instance = nil;
|
|
+(SDK*)Instance {
|
|
if(instance == nil){
|
|
instance =[[SDK alloc] init];
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
-(void)Init{
|
|
DLOG(@"Init");
|
|
[[superSDKManager shareInstance] showLog:NO];
|
|
[self callUnityFuncParam:@"InitCallback" param:@"1"];
|
|
}
|
|
|
|
-(void)Login{
|
|
DLOG(@"Login");
|
|
[[superSDKManager shareInstance] startLogin:UnityGetGLViewController() onSuccess:^(NSMutableDictionary *info) {
|
|
NSLog(@"info: %@",info);
|
|
NSString* rel = [NSString stringWithFormat:@"%@#%@#%@#%@",@"1",@"",@"",info[@"session"]];
|
|
[self callUnityFuncParam:@"LoginCallback" param:rel];
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"errorInfo: %@",errorInfo);
|
|
}];
|
|
}
|
|
|
|
-(void)SwitchLogin{
|
|
DLOG(@"SwitchLogin");
|
|
}
|
|
|
|
-(void)Logout{
|
|
DLOG(@"Logout");
|
|
[[superSDKManager shareInstance] logout:^{
|
|
NSLog(@"登出成功");
|
|
[self callUnityFuncParam:@"LogoutCallback" param:@"1"];
|
|
}];
|
|
}
|
|
|
|
-(bool)IsSupportExit{
|
|
DLOG(@"IsSupportExit");
|
|
return false;
|
|
}
|
|
|
|
-(void)ExitGame{
|
|
DLOG(@"ExitGame");
|
|
}
|
|
|
|
-(void)SubmitExtraData:(int) dataType
|
|
serverId :(int) serverId
|
|
serverName :(NSString *) serverName
|
|
zoneID :(NSString *) zoneID
|
|
zoneName :(NSString *) zoneName
|
|
roleID :(NSString *) roleID
|
|
roleName :(NSString *) roleName
|
|
roleLevel :(NSString *) roleLevel
|
|
guildlD :(NSString *) guildlD
|
|
Vip :(NSString *) Vip
|
|
moneyNum :(int) moneyNum
|
|
roleCreateTime :(NSString *) roleCreateTime
|
|
roleLevelUpTime :(NSString *) roleLevelUpTime{
|
|
DLOG(@"SubmitExtraData");
|
|
if (dataType == 2)
|
|
{
|
|
NSString *eventName = @"ican_create";
|
|
NSDictionary *infoDic = @{@"ican_create":roleID, @"server":[NSString stringWithFormat:@"%d",serverId]};
|
|
|
|
[[superSDKManager shareInstance] logEvent:eventName infoDic:infoDic];
|
|
}
|
|
else if (dataType == 3)
|
|
{
|
|
NSString *sid = [NSString stringWithFormat:@"%dY%@",serverId,zoneID];
|
|
|
|
[[superSDKManager shareInstance] sendSidToServer:zoneName sid:sid onSuccess:^(NSMutableDictionary *info) {
|
|
NSLog(@"info: %@",info);
|
|
[[superSDKManager shareInstance] accountVerification:^(NSMutableDictionary *info) {
|
|
NSLog(@"Get account validation status success : %@", info);
|
|
NSString *msg = [NSString stringWithFormat:@"%@%@",@"1&",info[@"mobileValidation"]];
|
|
[self callUnityFuncParam:@"MessageCallback" param:msg];
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"Get account validation status fail : %@", errorInfo);
|
|
}];
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"errorInfo: %@",errorInfo);
|
|
}];
|
|
|
|
}
|
|
else if(dataType == 4)
|
|
{
|
|
if([roleLevel intValue] == 4)
|
|
{
|
|
NSString *eventName = @"ican_tutorial";
|
|
NSDictionary *infoDic = @{@"ican_tutorial":roleLevel, @"server":[NSString stringWithFormat:@"%d",serverId]};
|
|
[[superSDKManager shareInstance] logEvent:eventName infoDic:infoDic];
|
|
}
|
|
NSString *eventName = @"ican_level";
|
|
NSDictionary *infoDic = @{@"ican_level":roleLevel, @"server":[NSString stringWithFormat:@"%d",serverId]};
|
|
[[superSDKManager shareInstance] logEvent:eventName infoDic:infoDic];
|
|
}
|
|
}
|
|
|
|
-(void)Pay:(NSString *) rechargeId
|
|
showType :(int)showType
|
|
productId :(int) productId
|
|
productName :(NSString *) productName
|
|
productDesc :(NSString *) productDesc
|
|
price :(NSString *) price
|
|
currencyType :(NSString *) currencyType
|
|
ratio :(int) ratio
|
|
buyNum :(int) buyNum
|
|
coinNum :(int) coinNum
|
|
zoneId :(NSString *) zoneId
|
|
serverID :(NSString *) serverID
|
|
serverName :(NSString *) serverName
|
|
accounted :(NSString *) accounted
|
|
roleID :(NSString *) roleID
|
|
roleName :(NSString *) roleName
|
|
roleLevel :(int) roleLevel
|
|
Vip :(NSString *) Vip
|
|
guildlD :(NSString *) guildlD
|
|
payNotifyUrl :(NSString *) payNotifyUrl
|
|
extension :(NSString *) extension
|
|
orderID :(NSString *) orderID{
|
|
DLOG(@"Pay");
|
|
IAPModel *iapModel = [[IAPModel alloc] init];
|
|
iapModel.productID = rechargeId;
|
|
NSString *extra = [extension substringFromIndex:14];
|
|
extra = [extra substringToIndex:(extra.length-2)];
|
|
iapModel.extra = extra;
|
|
iapModel.standalone = @"0";
|
|
|
|
[[superSDKManager shareInstance] startPurchase:UnityGetGLViewController() iapModel:iapModel onSuccess:^(NSMutableDictionary *info) {
|
|
NSLog(@"info: %@",info);
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"errorInfo: %@",errorInfo);
|
|
}];
|
|
}
|
|
|
|
-(void)Bind{
|
|
DLOG(@"Bind");
|
|
[[superSDKManager shareInstance] showGuestBinding:UnityGetGLViewController() onSuccess:^(NSMutableDictionary *info) {
|
|
NSLog(@"info: %@",info);
|
|
[[superSDKManager shareInstance] logout:^{
|
|
NSLog(@"登出成功");
|
|
[self callUnityFuncParam:@"LogoutCallback" param:@"1"];
|
|
}];
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"errorInfo: %@",errorInfo);
|
|
[self callUnityFuncParam:@"MessageCallback" param:errorInfo[@"errorMsg"]];
|
|
}];
|
|
}
|
|
|
|
-(void)Community{
|
|
DLOG(@"Community");
|
|
}
|
|
|
|
-(void)CustomerService{
|
|
DLOG(@"CustomerService");
|
|
[[superSDKManager shareInstance] showMemberCentre:UnityGetGLViewController() onSuccess:^(NSMutableDictionary *info) {
|
|
NSString *callbackType = info[@"CallbackType"];
|
|
|
|
if ([callbackType isEqualToString: @"logout"]) {
|
|
// 會員登出
|
|
[[superSDKManager shareInstance] logout:^{
|
|
NSLog(@"登出成功");
|
|
[self callUnityFuncParam:@"LogoutCallback" param:@"1"];
|
|
}];
|
|
} else if ([callbackType isEqualToString: @"MobileVerified"]) {
|
|
// 會員手機驗證
|
|
[self callUnityFuncParam:@"MessageCallback" param:@"1&1"];
|
|
}
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"errorInfo: %@",errorInfo);
|
|
[self Bind];
|
|
// [self callUnityFuncParam:@"MessageCallback" param:errorInfo[@"errorMsg"]];
|
|
}];
|
|
}
|
|
|
|
-(void)Relation:(NSString *) type{
|
|
DLOG(@"Relation");
|
|
}
|
|
|
|
-(void)Cancellation{
|
|
DLOG(@"Cancellation");
|
|
}
|
|
|
|
-(bool)IsCDKey{
|
|
DLOG(@"IsCDKey");
|
|
return false;
|
|
}
|
|
|
|
-(void)CDKey:(NSString *) cdkey
|
|
serverID :(NSString *)serverID
|
|
roleID :(NSString *)roleID{
|
|
DLOG(@"CDKey");
|
|
}
|
|
|
|
-(void)LoginPanel_Btn1{
|
|
DLOG(@"LoginPanel_Btn1");
|
|
[[superSDKManager shareInstance] facebookShareLink:UnityGetGLViewController() url:@"https://www.icantw.com" onSuccess:^(NSMutableDictionary *info) {
|
|
NSLog(@"分享成功");
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"分享失敗");
|
|
[self callUnityFuncParam:@"MessageCallback" param:errorInfo[@"errorMsg"]];
|
|
}];
|
|
}
|
|
|
|
-(void)LoginPanel_Btn2{
|
|
DLOG(@"LoginPanel_Btn2");
|
|
[[superSDKManager shareInstance] showQuestionnaire:UnityGetGLViewController() cid:nil onSuccess:^(NSMutableDictionary *info) {
|
|
NSLog(@"問卷完成");
|
|
} onFail:^(NSMutableDictionary *errorInfo) {
|
|
NSLog(@"問卷開啟失敗");
|
|
[self callUnityFuncParam:@"MessageCallback" param:errorInfo[@"errorMsg"]];
|
|
}];
|
|
}
|
|
|
|
-(void)CustomEvent:(int) type
|
|
param :(NSString *) param{
|
|
DLOG(@"CustomEvent");
|
|
}
|
|
|
|
|
|
//调用Unity方法
|
|
-(void)callUnityFunc:(NSString*)funcName{
|
|
UnitySendMessage(MakeStringCopy(callUnityTargetGameObjectName), MakeStringCopy(funcName), "");
|
|
}
|
|
|
|
//调用Unity方法
|
|
-(void)callUnityFuncParam:(NSString*)funcName param:(NSString*)param{
|
|
UnitySendMessage(MakeStringCopy(callUnityTargetGameObjectName), MakeStringCopy(funcName), MakeStringCopy(param));
|
|
}
|
|
|
|
@end
|