From cefd5352dc56296679b0477fb7a3af804d901ac8 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Sun, 9 Jul 2023 18:55:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0google=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/platform/android/jni/JniImp.cpp | 14 ++++ cocos/platform/android/jni/JniImp.h | 3 + .../js-bindings/manual/jsb_global.cpp | 71 +++++++++++++++++-- 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/cocos/platform/android/jni/JniImp.cpp b/cocos/platform/android/jni/JniImp.cpp index b228c43..a4e2b75 100644 --- a/cocos/platform/android/jni/JniImp.cpp +++ b/cocos/platform/android/jni/JniImp.cpp @@ -712,6 +712,20 @@ void toWalletJNI(const std::string& url) JniHelper::callStaticVoidMethod(JCSDK, "toWallet", url); } +void beginBuyJNI(const std::string& funid, const std::string& productid, const std::string& orderid) +{ + JniHelper::callStaticVoidMethod(JCSDK, "buyProduct", funid, productid, orderid); +} +void queryProductsJNI(const std::string& funid, const std::string& content) +{ + JniHelper::callStaticVoidMethod(JCSDK, "queryProducts", funid, content); +} + +void queryPurchaseJNI(const std::string& funid) +{ + JniHelper::callStaticVoidMethod(JCSDK, "queryPurchase", funid); +} + void setPreferredFramesPerSecondJNI(int fps) { JniHelper::callStaticVoidMethod(JCLS_RENDERER, "setPreferredFramesPerSecond", fps); diff --git a/cocos/platform/android/jni/JniImp.h b/cocos/platform/android/jni/JniImp.h index 2807f5f..3c20c7c 100644 --- a/cocos/platform/android/jni/JniImp.h +++ b/cocos/platform/android/jni/JniImp.h @@ -47,6 +47,9 @@ void signWithTwitterJNI(const std::string& funid); void signWithEmailJNI(const std::string& funid); void callJcVoidMethodJNI(const std::string& funid, const std::string& method_name); void toWalletJNI(const std::string& url); +void beginBuyJNI(const std::string& funid, const std::string& productid, const std::string& orderid); +void queryProductsJNI(const std::string& funid, const std::string& content); +void queryPurchaseJNI(const std::string& funid); 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/scripting/js-bindings/manual/jsb_global.cpp b/cocos/scripting/js-bindings/manual/jsb_global.cpp index 55d24c4..9cfc064 100644 --- a/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -997,7 +997,7 @@ static bool JSB_showQRCode(se::State& s) } SE_BIND_FUNC(JSB_showQRCode) -bool jsb_showWebPage(se::State& s) { +bool JSB_showWebPage(se::State& s) { const auto& args = s.args(); size_t argc = args.size(); if (argc >= 2) { @@ -1013,7 +1013,68 @@ bool jsb_showWebPage(se::State& s) { } return false; } -SE_BIND_FUNC(jsb_showWebPage) +SE_BIND_FUNC(JSB_showWebPage) + +static bool JSB_queryProductsJNI(se::State& s) +{ + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc > 1) { + std::string funid; + ok = seval_to_std_string(args[0], &funid); + SE_PRECONDITION2(ok, false, "funid is invalid!"); + std::string param0; + ok = seval_to_std_string(args[1], ¶m0); + SE_PRECONDITION2(ok, false, "param0 is invalid!"); + queryProductsJNI(funid, param0); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); + return false; +} +SE_BIND_FUNC(JSB_queryProductsJNI) + +static bool JSB_queryPurchaseJNI(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!"); + queryPurchaseJNI(funid); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(JSB_queryPurchaseJNI) + + +static bool JSB_beginBuyJNI(se::State& s) +{ + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc > 2) { + std::string funid; + ok = seval_to_std_string(args[0], &funid); + SE_PRECONDITION2(ok, false, "funid is invalid!"); + std::string param0; + ok = seval_to_std_string(args[1], ¶m0); + SE_PRECONDITION2(ok, false, "param0 is invalid!"); + std::string param1; + ok = seval_to_std_string(args[2], ¶m1); + SE_PRECONDITION2(ok, false, "param0 is invalid!"); + beginBuyJNI(funid, param0, param1); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3); + return false; +} +SE_BIND_FUNC(JSB_beginBuyJNI) #endif static bool JSB_toWallet(se::State& s) @@ -1350,8 +1411,10 @@ bool jsb_register_global_variables(se::Object* global) __jsbObj->defineFunction("callJcVoidMethodJNI", _SE(JSB_callJcVoidMethodJNI)); __jsbObj->defineFunction("signOutGoogle", _SE(JSB_signOutGoogle)); __jsbObj->defineFunction("showQRCode", _SE(JSB_showQRCode)); - __jsbObj->defineFunction("showWebPage", _SE(jsb_showWebPage)); - + __jsbObj->defineFunction("showWebPage", _SE(JSB_showWebPage)); + __jsbObj->defineFunction("queryProducts", _SE(JSB_queryProductsJNI)); + __jsbObj->defineFunction("queryPurchase", _SE(JSB_queryPurchaseJNI)); + __jsbObj->defineFunction("beginBuy", _SE(JSB_beginBuyJNI)); #endif __jsbObj->defineFunction("toWallet", _SE(JSB_toWallet));