当前位置:编程学习 > C/C++ >>

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++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,