From 0a782e88cf46ac0899f65143f43583897165314e Mon Sep 17 00:00:00 2001 From: cebgcontract <99630598+cebgcontract@users.noreply.github.com> Date: Thu, 22 Sep 2022 10:28:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0jsb=E8=B0=83=E7=94=A8google?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=92=8C=E7=99=BB=E5=87=BA=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/platform/CCApplication.h | 4 +++ .../android/CCApplication-android.cpp | 8 +++++ cocos/platform/android/jni/JniImp.cpp | 10 ++++++ cocos/platform/android/jni/JniImp.h | 2 ++ cocos/platform/ios/CCApplication-ios.mm | 8 +++++ .../js-bindings/manual/jsb_global.cpp | 36 +++++++++++++++++++ 6 files changed, 68 insertions(+) diff --git a/cocos/platform/CCApplication.h b/cocos/platform/CCApplication.h index 9e4adf1..9ca27d3 100644 --- a/cocos/platform/CCApplication.h +++ b/cocos/platform/CCApplication.h @@ -186,6 +186,10 @@ public: void scanQRCode(const std::string &funid, const std::string &title); + void signWithGoogle(const std::string &funid); + + void signOutGoogle(const std::string &funid); + void toWallet(const std::string &url); std::string getSystemVersion(); diff --git a/cocos/platform/android/CCApplication-android.cpp b/cocos/platform/android/CCApplication-android.cpp index 2dc8d03..0144701 100644 --- a/cocos/platform/android/CCApplication-android.cpp +++ b/cocos/platform/android/CCApplication-android.cpp @@ -295,6 +295,14 @@ void Application::scanQRCode(const std::string &funid, const std::string &title) scanQRCodeJNI(funid, title); } +void Application::signWithGoogle(const std::string &funid) { + signWithGoogleJNI(funid); +} + +void Application::signOutGoogle(const std::string &funid) { + signOutGoogleJNI(funid); +} + void Application::toWallet(const std::string &url) { toWalletJNI(url); } diff --git a/cocos/platform/android/jni/JniImp.cpp b/cocos/platform/android/jni/JniImp.cpp index a754de2..f4c8b16 100644 --- a/cocos/platform/android/jni/JniImp.cpp +++ b/cocos/platform/android/jni/JniImp.cpp @@ -658,6 +658,16 @@ void scanQRCodeJNI(const std::string& funid, const std::string& title) JniHelper::callStaticVoidMethod(JCSDK, "scanQRCode", funid, title); } +void signWithGoogleJNI(const std::string& funid) +{ + JniHelper::callStaticVoidMethod(JCSDK, "signWithGoogle", funid); +} + +void signOutGoogleJNI(const std::string& funid) +{ + JniHelper::callStaticVoidMethod(JCSDK, "signOutGoogle", funid); +} + void toWalletJNI(const std::string& url) { JniHelper::callStaticVoidMethod(JCSDK, "toWallet", url); diff --git a/cocos/platform/android/jni/JniImp.h b/cocos/platform/android/jni/JniImp.h index ed64628..45259d2 100644 --- a/cocos/platform/android/jni/JniImp.h +++ b/cocos/platform/android/jni/JniImp.h @@ -36,6 +36,8 @@ extern void exitApplication(); extern std::string getApkPathJNI(); extern std::string getPackageNameJNI(); void scanQRCodeJNI(const std::string& funid, const std::string& title); +void signWithGoogleJNI(const std::string& funid); +void signOutGoogleJNI(const std::string& funid); void toWalletJNI(const std::string& url); extern int getObbAssetFileDescriptorJNI(const std::string& path, long* startOffset, long* size); extern void convertEncodingJNI(const std::string& src, int byteSize, const std::string& fromCharset, std::string& dst, const std::string& newCharset); diff --git a/cocos/platform/ios/CCApplication-ios.mm b/cocos/platform/ios/CCApplication-ios.mm index a1f4903..1db01d6 100644 --- a/cocos/platform/ios/CCApplication-ios.mm +++ b/cocos/platform/ios/CCApplication-ios.mm @@ -335,6 +335,14 @@ void Application::scanQRCode(const std::string &funid, const std::string &title) } +void Application::signWithGoogle(const std::string &funid) { + +} + +void Application::signOutGoogle(const std::string &funid) { + +} + void Application::toWallet(const std::string &url) { UIApplication *app = [UIApplication sharedApplication]; NSString *uri = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding]; diff --git a/cocos/scripting/js-bindings/manual/jsb_global.cpp b/cocos/scripting/js-bindings/manual/jsb_global.cpp index 9619db7..0cd0c9d 100644 --- a/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -817,6 +817,40 @@ static bool JSB_scanQRCode(se::State& s) return false; } SE_BIND_FUNC(JSB_scanQRCode) + +static bool JSB_signWithGoogle(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, "funid is invalid!"); + Application::getInstance()->signWithGoogle(funid); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(JSB_signWithGoogle) + +static bool JSB_signOutGoogle(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, "funid is invalid!"); + Application::getInstance()->signOutGoogle(funid); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(JSB_signOutGoogle) #endif static bool JSB_toWallet(se::State& s) @@ -860,6 +894,8 @@ bool jsb_register_global_variables(se::Object* global) __jsbObj->defineFunction("copyTextToClipboard", _SE(JSB_copyTextToClipboard)); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) __jsbObj->defineFunction("scanQRCode", _SE(JSB_scanQRCode)); + __jsbObj->defineFunction("signWithGoogle", _SE(JSB_signWithGoogle)); + __jsbObj->defineFunction("signOutGoogle", _SE(JSB_signOutGoogle)); #endif __jsbObj->defineFunction("toWallet", _SE(JSB_toWallet));