增加client模式登录

This commit is contained in:
CounterFire2023 2023-08-17 16:01:15 +08:00
parent 7d1cea16dc
commit 23b2360610
3 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

@ -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) {