diff --git a/Classes_cocos/JcWallet.mm b/Classes_cocos/JcWallet.mm index 66768d2..080f769 100644 --- a/Classes_cocos/JcWallet.mm +++ b/Classes_cocos/JcWallet.mm @@ -643,6 +643,28 @@ static bool JSB_authGetStoragePass(se::State& s) } SE_BIND_FUNC(JSB_authGetStoragePass) +static bool JSB_getClientId(se::State &s) +{ + const auto &args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc > 0) + { + std::string funid; + ok = seval_to_std_string(args[0], &funid); + SE_PRECONDITION2(ok, false, "Error processing funid"); + NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding: NSUTF8StringEncoding]; + dispatch_async(dispatch_get_main_queue(), ^{ + UIWindow* window = [[[UIApplication sharedApplication] delegate] window]; + [window.rootViewController clientLogin:nfunid ]; + }); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(JSB_getClientId) bool jsb_register_walletevent_modules(se::Object* global) { getOrCreatePlainObject_r("jsb", global, &__jsbObj); @@ -662,6 +684,7 @@ bool jsb_register_walletevent_modules(se::Object* global) { __jsbObj->defineFunction("beginBuy", _SE(JSB_beginBuy)); __jsbObj->defineFunction("authGetStoragePass", _SE(JSB_authGetStoragePass)); __jsbObj->defineFunction("storagePass", _SE(JSB_storagePass)); + __jsbObj->defineFunction("getClientId", _SE(JSB_getClientId)); __jsbObj->defineFunction("passStorageState", _SE(JSB_passStorageState)); // JSB_signWithEmail // JSB_beginBuyJNI diff --git a/Classes_cocos/UIViewController+Wallet.h b/Classes_cocos/UIViewController+Wallet.h index 9b74c33..7d8c697 100644 --- a/Classes_cocos/UIViewController+Wallet.h +++ b/Classes_cocos/UIViewController+Wallet.h @@ -18,6 +18,7 @@ - (void)signWithFacebook:(NSString *)funid; - (void)signWithTwitter:(NSString *)funid; - (void)signOutGoogle:(NSString *)funid; +- (void)clientLogin:(NSString *)funid; - (void)saveKey:(NSString *)account key:(NSString *)key; - (NSString *)loadKey:(NSString *)account; - (void)showPage:(NSString *)url; diff --git a/Classes_cocos/UIViewController+Wallet.mm b/Classes_cocos/UIViewController+Wallet.mm index b880c43..76cfe3b 100644 --- a/Classes_cocos/UIViewController+Wallet.mm +++ b/Classes_cocos/UIViewController+Wallet.mm @@ -61,6 +61,23 @@ static WebPageViewController *webpageVC = nil; }]; } +-(void)clientLogin:(NSString *) funid { + NSString *clientKey = @"game_client_id"; + NSString *clientID = [self loadKey:clientKey]; + // if clientID is empty, then generate a new one with uuid + if ([NSString isStringEmpty:clientID]) { + NSString *pre_id = [[NSUUID UUID] UUIDString]; + // cast pre_id to lower case + std::string uuid = [[pre_id lowercaseString] UTF8String]; + std::string clientIdStr = generate_clientid(uuid); + clientID = [NSString stringWithUTF8String:clientIdStr.c_str()]; + NSLog(@"new clientID: %@", clientID); + [self saveKey:clientKey key:clientID]; + } + NSLog(@"clientID: %@", clientID); + [self nativeCb:funid hasErr:NO dataStr: clientID]; +} + -(void) refreshTokenID:(GIDGoogleUser *)user funid:(NSString*) funid{ [user.authentication doWithFreshTokens:^(GIDAuthentication * _Nullable authentication, NSError * _Nullable error) {