395 lines
14 KiB
Plaintext
395 lines
14 KiB
Plaintext
#import "SDK.h"
|
||
#import <QPJHLightSDK/QPJHLightSDK.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){
|
||
[[SDK Instance] Relation:[NSString stringWithUTF8String: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(){
|
||
|
||
}
|
||
|
||
void m_SDK_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{
|
||
|
||
[self callUnityFuncParam:@"InitCallback" param:@"1"];
|
||
|
||
//设置代理,监听用户退出事件
|
||
// [JySDKManager defaultManager].acountDelegate = self;
|
||
// 实现代理方法,监听用户退出和注册账号事件:
|
||
// #pragma mark -- KAcountDelegate
|
||
// - (void)userLogout:(NSDictionary *)resultDic
|
||
// {
|
||
// NSLog(@"用户从个人中心手动登出。\n%@",resultDic);
|
||
// [self login:nil];
|
||
// }
|
||
// - (void)userRegister:(NSString *)uid
|
||
// {
|
||
// NSLog(@"注册账号:%@",uid);
|
||
// };
|
||
|
||
|
||
DLOG(@"Init");
|
||
}
|
||
|
||
#pragma mark - JHLCoreEntityDelegate
|
||
//登录回调
|
||
- (void)qpjh_LightGetChannelLoginCallBack:(NSDictionary *)result {
|
||
|
||
|
||
NSString *token = [NSString stringWithFormat:@"%@",result[@"token"]];
|
||
NSString *userid = [NSString stringWithFormat:@"%@",result[@"super_user_id"]];
|
||
NSLog(@"登录成功:\n用户ID:%@,验证码:%@",userid,token);
|
||
NSString* rel = [NSString stringWithFormat:@"%@#%@#%@#%@",@"1",userid,@"",token];
|
||
[self callUnityFuncParam:@"LoginCallback" param:rel];
|
||
|
||
// self.super_user_id = [NSString stringWithFormat:@"%@",result[@"super_user_id"]];
|
||
// self.serviceToken = [NSString stringWithFormat:@"%@",result[@"token"]];
|
||
//
|
||
// NSLog(@"super_user_id == %@, serviceToken = %@ ",self.super_user_id,self.serviceToken );
|
||
//#warning - 用户效验接口 请在服务器做校验验证用户信息❗️❗️❗️
|
||
// NSURL *nsurl = [NSURL URLWithString:[NSString stringWithFormat:@"%@",@"https://supersdk.7pa.com/login/checkuserinfo"]];
|
||
//
|
||
// NSMutableURLRequest *mutableRequest=[NSMutableURLRequest requestWithURL:nsurl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:2];
|
||
//
|
||
// mutableRequest.HTTPMethod = @"POST";
|
||
//
|
||
// NSString *postStr = [NSString stringWithFormat:@"token=%@&super_user_id=%@",self.serviceToken, self.super_user_id];
|
||
//
|
||
// mutableRequest.HTTPBody = [postStr dataUsingEncoding:NSUTF8StringEncoding];
|
||
//
|
||
// NSURLSession *session = [NSURLSession sharedSession];
|
||
// NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:mutableRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||
// if (error) { //请求失败
|
||
// NSLog(@"qpjh onLoginFailed:login fail");
|
||
// } else { //请求成功
|
||
// NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
|
||
// NSString *surpercode = [NSString stringWithFormat:@"%@",dic[@"code"]];
|
||
// if ([surpercode isEqualToString:@"200"]) {
|
||
// NSLog(@"qpjh onLoginSuccess:%@", dic);
|
||
// } else {
|
||
// NSLog(@"qpjh onLoginFailed:login fail");
|
||
// }
|
||
// }
|
||
// }];
|
||
// [dataTask resume];
|
||
}
|
||
|
||
//上报角色回调
|
||
- (void)getUpdateRoleCallBack:(NSDictionary *)result {
|
||
NSLog(@"上报角色回调:%@",result);
|
||
}
|
||
|
||
//选择区服【停止新增用户】回调 当result为1可进入该区服,当result为其他值时,SDK里有错误提示.研发不做任何处理
|
||
- (void)canEnterListenCallBack:(NSString *)result {
|
||
NSLog(@"是否可以新增回调:%@",result);
|
||
if ([result isEqualToString:@"1"]) {
|
||
//TODO:可以进入该大区
|
||
} else {
|
||
//当前选择的大区已满或已关闭,SDK里有错误提示.研发不做任何处理
|
||
}
|
||
}
|
||
|
||
//支付成功回调
|
||
- (void)getPaySuccessCallBack:(NSDictionary *)result {
|
||
NSLog(@"支付成功回调:%@",result);
|
||
}
|
||
|
||
//支付失败回调
|
||
- (void)getPayFailCallBack:(NSDictionary *)result {
|
||
NSLog(@"支付失败回调:%@",result);
|
||
}
|
||
|
||
//注销, 切换账号回调
|
||
- (void)logOutCallBack:(NSString *)result {
|
||
|
||
NSLog(@"注销, 切换账号回调:%@",result);
|
||
|
||
#warning - 在游戏中主动退出SDK, 或在悬浮窗中切换账号 都会自动来到此回调, 请在此方法中做游戏退出的操作 (请勿在此回调中调用我方 [[JHLCoreEntity sharedInstance] qpjh_logout]; 否则会造成死循环❗️❗️❗️)
|
||
//TODO: 游戏退出, 回到游戏的登录选服页面
|
||
[self callUnityFuncParam:@"LogoutCallback" param:@"1"];
|
||
}
|
||
|
||
-(void)Login{
|
||
[[JHLCoreEntity sharedInstance] qpjh_setStartLoginListener:self];
|
||
[[JHLCoreEntity sharedInstance] qpjh_lightLoginStart];
|
||
DLOG(@"Login");
|
||
}
|
||
|
||
-(void)SwitchLogin{
|
||
DLOG(@"SwitchLogin");
|
||
}
|
||
|
||
-(void)Logout{
|
||
[[JHLCoreEntity sharedInstance] qpjh_logout];
|
||
DLOG(@"Logout");
|
||
}
|
||
|
||
-(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{
|
||
|
||
// NSLog(@"当前用户UID=%@,年龄=%@", JySDKManager.userId, age);
|
||
|
||
NSString* type = @"";
|
||
if(dataType == 2){
|
||
type = @"createrole";
|
||
}else if(dataType == 3){
|
||
type = @"enterserver";
|
||
}else if(dataType == 4){
|
||
type = @"levelup";
|
||
}else{
|
||
return;
|
||
}
|
||
|
||
NSDictionary *dic1 = @{
|
||
@"role_type": type, //角色上报类型: createrole 创建角色; enterserver 进入服务器调用; levelup 升级角色;
|
||
@"service_id": [NSString stringWithFormat:@"%d",serverId], //区服ID
|
||
@"service_name": serverName, //区服名字
|
||
@"role_id": roleID, //角色ID
|
||
@"role_name": roleName, //角色名称
|
||
@"role_level": Vip, //角色等级
|
||
@"power_value": @"1", //战力值 (必填,没有填1)
|
||
//@"describe": @"1", //角色描述 (选填)
|
||
//@"money": @"1", //角色余额 (选填,玩家的背包元宝或金币或钻石数量)
|
||
@"experience": @"1" //角色经验 (选填,默认为1,可以填写等级)
|
||
};
|
||
NSError* error1;
|
||
NSData* jsonData1 = [NSJSONSerialization dataWithJSONObject:dic1 options:NSJSONWritingPrettyPrinted error:&error1];
|
||
NSString* roleData1 = [[NSString alloc] initWithData:jsonData1 encoding: NSUTF8StringEncoding];
|
||
[[JHLCoreEntity sharedInstance] qpjh_superRoleUpdate:roleData1];
|
||
|
||
DLOG(@"SubmitExtraData");
|
||
}
|
||
|
||
-(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{
|
||
|
||
NSDictionary *dic1 = @{
|
||
@"good_id":rechargeId, //商品ID (必填,不能为0)
|
||
@"good_name":productName, //商品名
|
||
@"game_order_sn":orderID, //订单号
|
||
@"money":price, //订单金额 (单位:元)
|
||
@"remark":extension //扩展参数 (选填)
|
||
};
|
||
NSError* error1;
|
||
NSData* jsonData1 = [NSJSONSerialization dataWithJSONObject:dic1 options:NSJSONWritingPrettyPrinted error:&error1];
|
||
NSString* roleData1 = [[NSString alloc] initWithData:jsonData1 encoding: NSUTF8StringEncoding];
|
||
[[JHLCoreEntity sharedInstance] qpjh_superOrder:roleData1];
|
||
DLOG(@"Pay");
|
||
}
|
||
|
||
-(void)Bind{
|
||
DLOG(@"Bind");
|
||
}
|
||
|
||
-(void)Community{
|
||
DLOG(@"Community");
|
||
}
|
||
|
||
-(void)CustomerService{
|
||
[[JHLCoreEntity sharedInstance] qpjh_openGmShop];
|
||
DLOG(@"CustomerService");
|
||
}
|
||
|
||
-(void)Relation:(NSString *) type{
|
||
if([type isEqualToString: @"1"]){
|
||
[[JHLCoreEntity sharedInstance] qpjh_openResourceStore];
|
||
}else if ([type isEqualToString: @"2"]){
|
||
[[JHLCoreEntity sharedInstance] qpjh_openSuperDiscount];
|
||
}
|
||
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");
|
||
}
|
||
|
||
-(void)LoginPanel_Btn2{
|
||
DLOG(@"LoginPanel_Btn2");
|
||
}
|
||
|
||
-(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
|