uc sdk 对接封装_objctive-c++
#ifndef __Charge_uc_h__#define __Charge_uc_h__
typedef void* (*charge_cb)(void*);
struct product_t{
int _id;
const char* _name;
int _roleid;
const char* _rolename;
};
class cppChargeManager_uc{
static void* _rootView;
cppChargeManager_uc();
~cppChargeManager_uc();
cppChargeManager_uc(const cppChargeManager_uc&);
cppChargeManager_uc& operator=(const cppChargeManager_uc&);
public:
static cppChargeManager_uc* getInstance(void);
//注册ID和Key
void init(void* addr);
//登录
void login(charge_cb suc, charge_cb fail, charge_cb cancel =NULL);
//购买
void buy(product_t* info, charge_cb suc, charge_cb fail, charge_cb cancel =NULL);
//设置链接回调函数
void setConnectFunc(charge_cb sd, charge_cb rec);
//获得用户姓名和密码
const char* getUserName(void);
const char* getUserPasswd(void);
const char* getSid(void);
};
#endif
#import "Charge_uc.h"
#import <UIKit/UIKit.h>
#import <pthread.h>
#import <Foundation/Foundation.h>
#import "UCGameSdk/UCGameSdk.h"
#import "UCGameSdk/UCGameSdkConst.h"
#import "ChargeManager.h"
#include <iostream>
using namespace std;
static charge_cb call_backs[10] = {NULL};
static const char* game_user =NULL;
static const char* game_passwd = NULL;
//游戏帐号登录需要用到的变量
static pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t thread_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_t connect_to_our_server =0;
static string ucsid;
void* wait_for_cour_server_replay(void*){
ucsid.clear();
while (true){
void* value = NULL;
if(NULL != call_backs[Connect_receive])
{
value = call_backs[Connect_receive](NULL);
call_backs[Connect_receive] = NULL;
}
if(NULL != value){
const char* text =static_cast<constchar*>(value);
ucsid = text;
pthread_cond_signal(&thread_cond); //唤醒阻塞的线程
break;
}
}
return NULL;
}
@inte易做图ce UCViewController : UIViewController<UCGameSdkProtocol>{
}
//加载
- (void)viewDidLoad;
- (void)viewDidUnload;
//登陆部分
- (void) onSdkInitFin: (NSNotification *) notification;
- (void) onLoginFin: (NSNotification *) notification;
- (void)onUnloginExit;
//支付部分
- (void)onPayFin: (NSNotification *) notification;
- (void)payExit: (NSNotification *) notification;
- (void)buy:(product_t*)info;
@end
@implementation UCViewController
- (void)viewDidUnload{
}
-(void)viewDidLoad{
}
//登陆部分
// UC-技术接口人-陈子浩: 17:00:04
// 上古世界的生产环境gameid请用105174
// sdk.cpId = 593;
// sdk.gameId = 64710; //105174
// sdk.serverId = 1375;
// sdk.isDebug = NO;
-(id)init{
self = [super init];
if(NULL != self){
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSdkInitFin:) name:UCG_SDK_MSG_SDK_INIT_FIN object:nil];
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSString* hostUrl = @"http://sdk.test4.g.uc.cn/cs/data/host/";
NSString* siUrl = @"http://sdk.test4.g.uc.cn/cs/data/si/";
[userDefault setValue:hostUrl forKey:@"UCG_SDK_URL_HOST_DEBUG"];
[userDefault setValue:siUrl forKey:@"UCG_SDK_URL_SI_DEBUG"];
UCGameSdk *sdk = [UCGameSdk defaultSDK];
sdk.cpId = 4;
sdk.gameId = 4;
sdk.serverId = 11;
sdk.isDebug = YES;
sdk.logLevel = UCLOG_LEVEL_DEBUG;
sdk.allowGameUserLogin = YES;
sdk.gameUserName = @"上古世界官方帐号";
ExInfo *exInfo = [[[ExInfo alloc] init] autorelease];
exInfo.cpServiceContact = @"上古世界\n客服电话:021-50183061";//self.feedbackCPTxtTextView.text;
sdk.exInfo = exInfo;
[sdk initSDK];
}
return self;
}
- (void)onUnloginExit //登陆失败
{
if(NULL != call_backs[Login_fail] )
{
call_backs[Login_fail](NULL);
call_backs[Login_fail] = NULL;
}
}
- (void) onSdkInitFin: (NSNotification *) notification
{
NSDictionary *res = notification.userInfo;
NSNumber *code = (NSNumber *)[res objectForKey:@"code"];
if ([code intValue] == 1)
return;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UCG_SDK_MSG_LOGIN_FIN object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UCG_SDK_MSG_EXIT_WITHOUT_LOGIN object:nil];
[[NSNotif
补充:软件开发 , C++ ,
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊