//
// SDKInterface.h
// Unity-iPhone
//
// Created by 刘叹 on 17/3/24.
//
//
#import
@interfaceSDKInterface : NSObject
+(instancetype) sharedInstance;
@end
//
// SDKInterface.m
// Unity-iPhone
//
// Created by 刘叹 on 17/3/24.
//
//
#import "SDKInterface.h"
#import // CC_MD5
#import "SMPCQuickSDK.framework/Headers/SMPCQuickSDK.h"
#import "SMPCQuickSDK.framework/Headers/SMPCQuickSDKGameRoleInfo.h"
#import "SMPCQuickSDK.framework/Headers/SMPCQuickSDKPayOrderInfo.h"
#if defined( __cplusplus )
extern "C" {
#endif
voidinit(){
//添加对QuickSDK通知的监听
//登录
[[NSNotificationCenter defaultCenter] addObserver:[SDKInterface sharedInstance] selector:@selector(smpcQpLoginResult:) name:kSmpcQuickSDKNotiLogin object:nil];
//注销
[[NSNotificationCenter defaultCenter] addObserver:[SDKInterface sharedInstance] selector:@selector(smpcQpLogoutResult:) name:kSmpcQuickSDKNotiLogout object:nil];
//充值结果
[[NSNotificationCenter defaultCenter] addObserver:[SDKInterface sharedInstance] selector:@selector(smpcQpRechargeResult:) name:kSmpcQuickSDKNotiRecharge object:nil];
//暂停结束 这个回调可以不用添加
[[NSNotificationCenter defaultCenter] addObserver:[SDKInterface sharedInstance] selector:@selector(smpcQpPauseOver:) name:kSmpcQuickSDKNotiPauseOver object:nil];
}
voidlogin(){
[[SMPCQuickSDK defaultInstance] login];
}
voidfacebookLogin(){
NSLog(@"%@", @"facebook login pressed");
}
voidloginOut(){
[[SMPCQuickSDK defaultInstance] logout];
}
voidpursePay(intprice,constchar* productID,intindex,constchar* callbackInfo,constchar* callbackUrl,constchar* serverid,constchar* playerID,constchar* myServerName,constchar* myrolename,intmyvip,intmylevel){
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef guid = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
NSString *uuidString = [((__bridgeNSString *)guid) stringByReplacingOccurrencesOfString:@"-"withString:@""];
CFRelease(guid);
//myServerName,myrolename,myvip,mylevel
SMPCQuickSDKGameRoleInfo *role = [[SMPCQuickSDKGameRoleInfo alloc] init];
SMPCQuickSDKPayOrderInfo *order = [[SMPCQuickSDKPayOrderInfo alloc] init];
role.serverName = [NSString stringWithUTF8String:myServerName];//必填
role.gameRoleName = [NSString stringWithUTF8String:myrolename];//@""
role.serverId = [NSString stringWithUTF8String:serverid];//需要是数字字符串
role.gameRoleID = [NSString stringWithUTF8String:playerID];//
role.gameUserBalance =@"0";//
role.vipLevel = [NSString stringWithFormat:@"%d",myvip];
role.gameUserLevel = [NSString stringWithFormat:@"%d",mylevel];
role.partyName =@"ios";//
order.goodsID = [NSString stringWithUTF8String:productID];
order.productName =@"钻石";//必填
order.productDesc =@"";
order.quantifier =@"个";
order.cpOrderID = [uuidString lowercaseString];
order.price =0.1;//单价,比如1个元宝的价格
order.count = price /10;
order.amount = price/100;//总价
order.callbackUrl = [NSString stringWithUTF8String:callbackUrl];
order.extrasParams = [NSString stringWithUTF8String:callbackInfo];
interror = [[SMPCQuickSDK defaultInstance] payOrderInfo:order
roleInfo:role];
if(error!=0)
NSLog(@"%d", error);
}
voidsetRoleData(constchar* sType,constchar* roleid,
constchar* rolename,intlevel,
intserverid,constchar* servername,
intbalance,intvip,constchar* guild){
//[[IAPManager Instance] VerifyUncompletedTransaction];
SMPCQuickSDKGameRoleInfo *roleInfo = [[SMPCQuickSDKGameRoleInfo alloc] init];
roleInfo.serverName = [NSString stringWithUTF8String:servername];
roleInfo.gameRoleName = [NSString stringWithUTF8String:rolename];
roleInfo.serverId = [NSString stringWithFormat:@"%d",serverid];//需要是数字字符串
roleInfo.gameRoleID = [NSString stringWithUTF8String:roleid];
roleInfo.gameUserBalance =@"0";
roleInfo.vipLevel =[NSString stringWithFormat:@"%d",vip];
roleInfo.gameUserLevel = [NSString stringWithFormat:@"%d",level];
roleInfo.partyName =@"0";
[[SMPCQuickSDK defaultInstance] updateRoleInfoWith:roleInfo];
}
#if defined( __cplusplus)
}
#endif
@implementation SDKInterface
staticSDKInterface * instatnce =nil;
+(instancetype) sharedInstance {
staticdispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instatnce = [[selfalloc] init];
});
returninstatnce;
}
- (instancetype)init
{
self= [superinit];
if(self) {
}
return self;
}
- (void)smpcQpLoginResult:(NSNotification *)notify {
NSLog(@"登录成功通知%@",notify);
interror = [[[notify userInfo] objectForKey:kSmpcQuickSDKKeyError] intValue];
NSDictionary *userInfo = [notify userInfo];
if(error ==0) {
NSString *uid = [[SMPCQuickSDK defaultInstance] userId];
NSString *user_name = [[SMPCQuickSDK defaultInstance] userNick];
NSString *user_token = userInfo[kSmpcQuickSDKKeyUserToken];
//NSString *user_token = [[SMPCQuickSDK defaultInstance] userToken];
NSString *product_code =@"81610864807405610715641689786124";
intchannelCode = [[SMPCQuickSDK defaultInstance] channelType];
NSString *sendInfo = [NSString stringWithFormat:@"{\"product_code\":\"%@\",\"user_id\":\"%@\",\"token\":\"%@\"}",
product_code,uid, user_token];
// String sResult = "{\"channel\":\"quicksdk\", "
// + "\"token\": \"" + userInfo.getToken()+ "\","
// + "\"userId\":\"" +userInfo.getUID()+"\","
// + "\"product_code\":\"" +"89945144719855725991053481214433"+"\","
// + "\"channel_code\":\"" +Extend.getInstance().getChannelType()+"\"}";
NSLog(@"sendInfo====%@",sendInfo);
UnitySendMessage("Platform","OnLoginSuccessedCallBack", sendInfo.UTF8String);
// 更新角色信息
}
}
- (void)smpcQpLogoutResult:(NSNotification *)notify {
NSLog(@"%s",__func__);
NSDictionary *userInfo = notify.userInfo;
interrorCode = [userInfo[kSmpcQuickSDKKeyError] intValue];
switch(errorCode) {
caseSMPC_QUICK_SDK_ERROR_NONE:
{
NSLog(@"注销成功");
//注销成功
UnitySendMessage("Platform","OnLogoutSuccessedCallBack",@" ".UTF8String);
}
break;
caseSMPC_QUICK_SDK_ERROR_LOGOUT_FAIL:
default:
{
//注销失败
NSLog(@"注销失败");
}
break;
}
if(errorCode == SMPC_QUICK_SDK_ERROR_NONE) {
}
}
- (void)smpcQpRechargeResult:(NSNotification *)notify{
NSLog(@"充值结果%@",notify);
NSDictionary *userInfo = notify.userInfo;
interror = [[userInfo objectForKey:kSmpcQuickSDKKeyError] intValue];
switch(error) {
caseSMPC_QUICK_SDK_ERROR_NONE:
{
//充值成功
//QuickSDK订单号,cp下单时传入的订单号,渠道sdk的订单号,cp下单时传入的扩展参数
NSString *orderID = userInfo[kSmpcQuickSDKKeyOrderId];
NSString *cpOrderID = userInfo[kSmpcQuickSDKKeyCpOrderId];
NSString *sdkOrderID = userInfo[kSmpcQuickSDKKeySdkOrderId];
NSString *extraParams = userInfo[kSmpcQuickSDKKeyExtraParams];
NSLog(@"充值成功数据:%@,%@,%@,%@",orderID,cpOrderID,sdkOrderID,extraParams);
}
break;
caseSMPC_QUICK_SDK_ERROR_RECHARGE_CANCELLED:
caseSMPC_QUICK_SDK_ERROR_RECHARGE_FAILED:
{
//充值失败
NSString *orderID = userInfo[kSmpcQuickSDKKeyOrderId];
NSString *cpOrderID = userInfo[kSmpcQuickSDKKeyCpOrderId];
NSString *sdkOrderID = userInfo[kSmpcQuickSDKKeySdkOrderId];
NSString *extraParams = userInfo[kSmpcQuickSDKKeyExtraParams];
NSLog(@"充值失败数据%@,%@,%@,%@",orderID,cpOrderID,sdkOrderID,extraParams);
}
break;
default:
break;
}
}
- (void)smpcQpPauseOver:(NSNotification *)notify{
NSLog(@"收到QuickSDK暂停结束通知");
}
- (void)smpcQpInitResult:(NSNotification *)notify {
NSLog(@"init result:%@",notify);
}
@end
网友评论