Uc sdk integration package _ objctive-c ++

Source: Internet
Author: User

# 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 (); encrypt (const cppChargeManager_uc &); cppChargeManager_uc & operator = (const Encrypt &); public: static cppChargeManager_uc * getInstance (void ); // register ID and Key void init (void * addr); // log on to void login (charge_cb suc, charge_cb fail, charge_cb cancel = NULL ); // purchase void buy (product_t * info, charge_cb suc, charge_cb fail, charge_cb cancel = NULL); // set the link callback function void setCon NectFunc (charge_cb sd, charge_cb rec); // obtain the user name and password 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; // variable needed for game account logon 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); // wake up the blocked thread break ;}} return NULL ;}@ interface UCViewController: UIViewController <UCGameSdkProtocol >{}// load-(void) viewDidLoad;-(void) viewDidUnload; // the login part-(void) onSdkInitFin: (NSNotification *) notification;-(void) onLoginFin: (NSNotification *) notification;-(void) onUnloginExit; // payment Department Minute-(void) onPayFin: (NSNotification *) notification;-(void) payExit: (NSNotification *) notification;-(void) buy :( product_t *) info; @ end @ implementation UCViewController-(void) viewDidUnload {}-(void) viewDidLoad {} // login part // UC-technical contact-Chen zihao: 17:00:04 // For the production environment gameid of the ancient world, use 105174 // sdk. cpId = 593; // sdk. gameId = 64710; // 105174 // sdk. serverId = 1375; // sdk. isDebug = NO;-(id) init {self = [super init]; if (N ULL! = Self) {[[NSNotificationCenter defacenter center] removeObserver: self]; [nsicationicationcenter defaultCenter] addObserver: self selector: @ selector (onSdkInitFin :) name: Your 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/"; [userDefa Ult setValue: hostUrl forKey: @ "UCG_SDK_URL_HOST_DEBUG"]; [userDefault setValue: siUrl forKey: @ "UCG_SDK_URL_SI_DEBUG"]; UCGameSdk * sdk = [UCGameSdk ultultsdk]; 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 = @ "Elder world \ n Customer Service Tel: 021-50183061"; // self. feedbackCPTxtTextView. text; sdk. exInfo = exInfo; [sdk initSDK];} return self;}-(void) onUnloginExit // Login Failed {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; [[nsicationicationcenter defacenter center] removeObserver: self name: UCG_SDK_MSG_LOGIN_FIN object: nil]; [nsnotifcent cent Er defaultCenter] removeObserver: self name: jsonobject: nil]; [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (onLoginFin :) name: UCG_SDK_MSG_LOGIN_FIN object: nil]; [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (onUnloginExit) name: jsonobject: nil]; [UCGameSdk defaultSDK] loginWithDelegate: self]; }-(Void) onLoginFin: (NSNotification *) notification // log on to the UC account {NSDictionary * res = notification. userInfo; NSNumber * code = (NSNumber *) [res objectForKey: @ "code"]; if (code. intValue = 0) {if (NULL! = Call_backs [Login_success]) {call_backs [Login_success] (NULL); call_backs [Login_success] = NULL ;}} else {if (NULL! = Call_backs [Login_fail]) {call_backs [Login_fail] (NULL); call_backs [Login_fail] = NULL ;}}- (NSDictionary *) verifyGameUser :( NSString *) gameUser gamePassword :( NSString *) gamePassword {NSString * sid; int resultCode = 0; NSMutableDictionary * resultDict = [[[NSMutableDictionary alloc] init] autorelease]; // open a thread, and the current line is blocked. Hold pthread_cond_init (& thread_cond, NULL); pthread_mutex_init (& thread_lock, NULL );/ /Send the username and password to our server pthread_mutex_lock (& thread_lock); game_user = gameUser. UTF8String; game_passwd = gamePassword. UTF8String; if (NULL! = Call_backs [Connect_send]) {call_backs [Connect_send] (NULL); call_backs [Connect_send] = NULL;} // func pthread_create (& connect_to_our_server, NULL, callback, NULL ); pthread_cond_wait (& thread_cond, & thread_lock); pthread_mutex_unlock (& thread_lock); // run the following command to recycle pthread_join (connect_to_our_server, NULL) Waiting threads and other variables ); pthread_mutex_destroy (& thread_lock); pthread_cond_destroy (& thread_cond); Sid = [NSString stringwithuf8string: ucsid. c_str ()]; [resultDict setValue: sid forKey: @ "sid"]; [resultDict setValue: [NSNumber numberWithInt: resultdcode] forKey: @ "resultCode"]; [resultDict setValue: @ "OK" forKey: @ "resultMsg"]; return resultDict;}-(void) buy :( product_t *) info {[[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (onPayFin :) name: UCG_SDK_MSG_PAY_FIN object: nil]; [[Nsicationicationcenter defacenter center] addObserver: self selector: @ selector (payExit :) name: UCG_SDK_MSG_PAY_EXIT object: nil]; char order [200]; sprintf (order, "serverip = sgmx # channel = % d # user = % s", info-> _ id, info-> _ name); NSString * customInfo = [NSString stringwithuf8string: order]; NSString * roleId = [NSString stringWithFormat: @ "% d", info-> _ roleid]; NSString * roleName = [NSString stringwithuf8string: in Fo-> _ rolename]; NSDictionary * dict = [NSDictionary Syntax: [NSNumber numberWithBool: YES], @ "allowContinuousPay", customInfo, @ "customInfo", roleId, @ "roleId", roleName, @ "roleName", nil]; [[UCGameSdk defaultSDK] payWithPaymentInfo: dict];}-(void) onPayFin: (NSNotification *) notification {NSDictionary * res = notification. userInfo; NSNumber * code = (NSNumber *) [res objectForKey: @ "Code"]; if (code. intValue = 0) {if (NULL! = Call_backs [Buy_success]) call_backs [Buy_success] (NULL);} else {if (NULL! = Call_backs [Buy_fail]) call_backs [Buy_fail] (NULL) ;}}- (void) payExit: (NSNotification *) notification {}@ end void * cppChargeManager_uc :: _ rootView = NULL; static UCViewController * uc_view = NULL; cppChargeManager_uc: cppChargeManager_uc () {uc_view = [[UCViewController alloc] init];} cppChargeManager_uc ::~ Revoke () {[uc_view dealloc]; uc_view = NULL;} cppChargeManager_uc * handle: getInstance (void) {static cppChargeManager_uc _ only; return & _ only;} void response :: init (void * addr) {_ rootView = (UCViewController *) addr;} void failed: login (charge_cb suc, charge_cb fail, charge_cb cancel) {call_backs [Login_success] = suc; call_backs [Login_fail] = fail; cal Rochelle backs [Login_cancel] = cancel; UIViewController * root = (UIViewController *) _ rootView; [root addSubview: uc_view.view];} void metadata: buy (product_t * info, charge_cb suc, charge_cb fail, charge_cb cancel) {call_backs [callback] = suc; call_backs [callback] = fail; call_backs [Buy_cancel] = cancel; [uc_view buy: info];} void resume :: setConnectFunc (charge_cb sd, charge_cb rec) {Call_backs [Connect_send] = sd; call_backs [Connect_receive] = rec;} const char * handle: getUserName (void) {return game_user;} const char * cppChargeManager_uc :: getUserPasswd (void) {return game_passwd;} const char * cppChargeManager_uc: getSid () {return [[[UCGameSdk ultultsdk] sid] UTF8String];} some people may not be familiar with the previous proxy, or they may have to spend some time researching it. In this case, I may just give it out, UseStaticLibraryUc. isrance (). setConnectFunc (new M OnoBindingUc. XMUtilityCallback (this. onUcLoginResult), new MonoBindingUc. XMUtilityCallback (this. onUcLoginResult), new MonoBindingUc. XMUtilityCallback (this. onUcLoginResult); public string onUcLoginResult (int type) {www.2cto. comNSString str = null; return str;} These are also available on official instances.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.