From 5dd7e9932b3132fd1d4a7ee2aabdf91215f98825 Mon Sep 17 00:00:00 2001 From: yeliulee Date: Sun, 20 Oct 2024 22:51:59 +0800 Subject: [PATCH 1/4] add auth impl for wechat on ohos Signed-off-by: yeliulee (cherry picked from commit bf1d638ef03e0ec90eff0769db32dee98b3111f2) --- example/ohos/.gitignore | 19 +++ example/ohos/AppScope/app.json5 | 10 ++ .../resources/base/element/string.json | 8 ++ .../resources/base/media/app_icon.png | Bin 0 -> 6790 bytes example/ohos/build-profile.json5 | 42 +++++++ example/ohos/entry/.gitignore | 7 ++ example/ohos/entry/build-profile.json5 | 29 +++++ example/ohos/entry/hvigorfile.ts | 17 +++ example/ohos/entry/oh-package.json5 | 26 ++++ .../main/ets/entryability/EntryAbility.ets | 24 ++++ .../ohos/entry/src/main/ets/pages/Index.ets | 38 ++++++ example/ohos/entry/src/main/module.json5 | 53 +++++++++ .../main/resources/base/element/color.json | 8 ++ .../main/resources/base/element/string.json | 16 +++ .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/main_pages.json | 5 + .../main/resources/en_US/element/string.json | 16 +++ .../main/resources/zh_CN/element/string.json | 16 +++ .../src/ohosTest/ets/test/Ability.test.ets | 50 ++++++++ .../entry/src/ohosTest/ets/test/List.test.ets | 20 ++++ .../ohosTest/ets/testability/TestAbility.ets | 63 ++++++++++ .../ohosTest/ets/testability/pages/Index.ets | 49 ++++++++ .../ets/testrunner/OpenHarmonyTestRunner.ts | 64 ++++++++++ example/ohos/entry/src/ohosTest/module.json5 | 51 ++++++++ .../resources/base/element/color.json | 8 ++ .../resources/base/element/string.json | 16 +++ .../ohosTest/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/test_pages.json | 5 + example/ohos/hvigor/hvigor-config.json5 | 20 ++++ example/ohos/hvigorfile.ts | 21 ++++ example/ohos/oh-package.json5 | 34 ++++++ ohos/.gitignore | 9 ++ ohos/build-profile.json5 | 10 ++ ohos/hvigorfile.ts | 2 + ohos/index.ets | 17 +++ ohos/local.properties | 1 + ohos/oh-package.json5 | 12 ++ .../ets/components/plugin/FluwxPlugin.ets | 111 ++++++++++++++++++ .../plugin/handlers/FluwxAuthHandler.ets | 88 ++++++++++++++ .../plugin/handlers/WXAPiHandler.ets | 49 ++++++++ ohos/src/main/module.json5 | 10 ++ pubspec.yaml | 2 + 42 files changed, 1046 insertions(+) create mode 100644 example/ohos/.gitignore create mode 100644 example/ohos/AppScope/app.json5 create mode 100644 example/ohos/AppScope/resources/base/element/string.json create mode 100644 example/ohos/AppScope/resources/base/media/app_icon.png create mode 100644 example/ohos/build-profile.json5 create mode 100644 example/ohos/entry/.gitignore create mode 100644 example/ohos/entry/build-profile.json5 create mode 100644 example/ohos/entry/hvigorfile.ts create mode 100644 example/ohos/entry/oh-package.json5 create mode 100644 example/ohos/entry/src/main/ets/entryability/EntryAbility.ets create mode 100644 example/ohos/entry/src/main/ets/pages/Index.ets create mode 100644 example/ohos/entry/src/main/module.json5 create mode 100644 example/ohos/entry/src/main/resources/base/element/color.json create mode 100644 example/ohos/entry/src/main/resources/base/element/string.json create mode 100644 example/ohos/entry/src/main/resources/base/media/icon.png create mode 100644 example/ohos/entry/src/main/resources/base/profile/main_pages.json create mode 100644 example/ohos/entry/src/main/resources/en_US/element/string.json create mode 100644 example/ohos/entry/src/main/resources/zh_CN/element/string.json create mode 100644 example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets create mode 100644 example/ohos/entry/src/ohosTest/ets/test/List.test.ets create mode 100644 example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets create mode 100644 example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets create mode 100644 example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts create mode 100644 example/ohos/entry/src/ohosTest/module.json5 create mode 100644 example/ohos/entry/src/ohosTest/resources/base/element/color.json create mode 100644 example/ohos/entry/src/ohosTest/resources/base/element/string.json create mode 100644 example/ohos/entry/src/ohosTest/resources/base/media/icon.png create mode 100644 example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json create mode 100644 example/ohos/hvigor/hvigor-config.json5 create mode 100644 example/ohos/hvigorfile.ts create mode 100644 example/ohos/oh-package.json5 create mode 100644 ohos/.gitignore create mode 100644 ohos/build-profile.json5 create mode 100644 ohos/hvigorfile.ts create mode 100644 ohos/index.ets create mode 100644 ohos/local.properties create mode 100644 ohos/oh-package.json5 create mode 100644 ohos/src/main/ets/components/plugin/FluwxPlugin.ets create mode 100644 ohos/src/main/ets/components/plugin/handlers/FluwxAuthHandler.ets create mode 100644 ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets create mode 100644 ohos/src/main/module.json5 diff --git a/example/ohos/.gitignore b/example/ohos/.gitignore new file mode 100644 index 00000000..6ca13b31 --- /dev/null +++ b/example/ohos/.gitignore @@ -0,0 +1,19 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +*.har +**/BuildProfile.ets +**/oh-package-lock.json5 + +**/src/main/resources/rawfile/flutter_assets/ +**/libs/arm64-v8a/libapp.so +**/libs/arm64-v8a/libflutter.so +**/libs/arm64-v8a/libvmservice_snapshot.so diff --git a/example/ohos/AppScope/app.json5 b/example/ohos/AppScope/app.json5 new file mode 100644 index 00000000..a6a34f29 --- /dev/null +++ b/example/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.jarvan.fluwx_example", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/example/ohos/AppScope/resources/base/element/string.json b/example/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 00000000..41723660 --- /dev/null +++ b/example/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "fluwx_example" + } + ] +} diff --git a/example/ohos/AppScope/resources/base/media/app_icon.png b/example/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)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ntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 00000000..cef0447c --- /dev/null +++ b/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 00000000..1def08f2 --- /dev/null +++ b/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/example/ohos/entry/src/ohosTest/module.json5 b/example/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 00000000..fab77ce2 --- /dev/null +++ b/example/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/example/ohos/entry/src/ohosTest/resources/base/element/color.json b/example/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 00000000..3c712962 --- /dev/null +++ b/example/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/example/ohos/entry/src/ohosTest/resources/base/element/string.json b/example/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 00000000..65d8fa5a --- /dev/null +++ b/example/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/example/ohos/entry/src/ohosTest/resources/base/media/icon.png b/example/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DW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u_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y { + } + onResp = (resp: wechatOpenSDK.BaseResp): void => { + if (resp instanceof wechatOpenSDK.SendAuthResp) { + this.handleAuthResponse(resp); + return; + } + } + + // 微信回调 end + + + onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void { + WXAPiHandler.wxApi?.handleWant(want, this) + } + + onMethodCall(call: MethodCall, result: MethodResult): void { + switch (call.method) { + case "registerApp": + WXAPiHandler.registerApp(call, result); + break; + case "sendAuth": + this.authHandler?.sendAuth(call, result); + break; + case "authByQRCode": + this.authHandler?.authByQRCode(call, result); + break; + case "stopAuthByQRCode": + this.authHandler?.stopAuthByQRCode(result); + break; + case "isWeChatInstalled": + WXAPiHandler.checkWeChatInstallation(result); + break; + default: + result.notImplemented() + } + } + + handleAuthResponse(resp: wechatOpenSDK.SendAuthResp) { + const result: Map = new Map(); + result.set(KEY_ERR_CODE, resp.errCode); + result.set(KEY_ERR_STR, resp.errStr); + result.set("code", resp.code); + result.set("state", resp.state); + result.set("lang", resp.lang); + result.set("country", resp.country); + result.set(KEY_OPEN_ID, resp.openId); + result.set("url", resp.url); + result.set(KEY_TYPE, resp.type); + + this.channel?.invokeMethod("onAuthResponse", result); + } +} \ No newline at end of file diff --git a/ohos/src/main/ets/components/plugin/handlers/FluwxAuthHandler.ets b/ohos/src/main/ets/components/plugin/handlers/FluwxAuthHandler.ets new file mode 100644 index 00000000..64e56ea6 --- /dev/null +++ b/ohos/src/main/ets/components/plugin/handlers/FluwxAuthHandler.ets @@ -0,0 +1,88 @@ +import { MethodCall, MethodChannel, MethodResult } from "@ohos/flutter_ohos"; +import { DiffDevOAuthFactory, IDiffDevOAuth, OAuthCallback, OAuthErrCode, SendAuthReq } from "@tencent/wechat_open_sdk"; +import { WXAPiHandler } from "./WXAPiHandler"; +import { util } from "@kit.ArkTS"; + +export class FluwxAuthHandler implements OAuthCallback { + private channel: MethodChannel; + private diffDevOauth: IDiffDevOAuth | null = null; + + constructor(channel: MethodChannel) { + this.channel = channel; + } + + onGotQRCode = (base64JpegImageBuffer: string) => { + const base64Codec = new util.Base64Helper() + const bytes = base64Codec.decodeSync(base64JpegImageBuffer) + + this.channel.invokeMethod("onAuthGotQRCode", { + "errCode": 0, + "qrCode": bytes + }) + } + onQRCodeScanned = () => { + this.channel.invokeMethod("onQRCodeScanned", { + "errCode": 0 + }) + } + onAuthFinish = (authCode: string) => { + this.channel.invokeMethod("onAuthByQRCodeFinished", { + "authCode": authCode, + "errCode": 0 + }) + } + onAuthError = (errCode: OAuthErrCode, errMsg: string) => { + this.channel.invokeMethod("onAuthByQRCodeFinished", { + "errCode": errCode, + "errStr": errMsg + }) + } + + getDiffDevOauth(): IDiffDevOAuth { + if (this.diffDevOauth) { + this.diffDevOauth.stopOAuth(); + this.diffDevOauth = null; + } + this.diffDevOauth = DiffDevOAuthFactory.getDiffDevOAuth()!; + return this.diffDevOauth; + } + + sendAuth(call: MethodCall, result: MethodResult) { + const req = new SendAuthReq(); + req.isOption1 = false; + req.scope = call.argument("scope"); + req.state = call.argument("state"); + const openid: string | null = call.argument("openid"); + if (openid) { + req.openId = openid; + } + req.nonAutomatic = call.argument("nonAutomatic") ?? false; + result.success(WXAPiHandler.wxApi?.sendReq( + WXAPiHandler.uiContext, + req + )) + } + + authByQRCode(call: MethodCall, result: MethodResult) { + const appId: string = call.argument("appId") ?? ""; + const scope: string = call.argument("scope") ?? ""; + const nonceStr: string = call.argument("nonceStr") ?? ""; + const timeStamp: string = call.argument("timeStamp") ?? ""; + const signature: string = call.argument("signature") ?? ""; + + const qrCodeAuth = this.getDiffDevOauth(); + + result.success(qrCodeAuth.startOAuth( + appId, + scope, + nonceStr, + timeStamp, + signature, + this + )) + } + + stopAuthByQRCode(result: MethodResult) { + result.success(this.diffDevOauth?.stopOAuth()) + } +} \ No newline at end of file diff --git a/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets b/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets new file mode 100644 index 00000000..6126472c --- /dev/null +++ b/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets @@ -0,0 +1,49 @@ +import * as wechatOpenSDK from "@tencent/wechat_open_sdk" +import { MethodCall, MethodResult } from '@ohos/flutter_ohos' +import { bundle, bundleManager, common } from '@kit.AbilityKit' + +export class WXAPiHandler { + static wxApi: wechatOpenSDK.WXApi | null = null + private static registered: boolean = false + private static context: common.UIAbilityContext | null = null + + static get wxApiRegistered() { + return WXAPiHandler.registered + } + static get uiContext() { + return WXAPiHandler.context + } + + static coolBoot: boolean = false + + static setContext(context: common.UIAbilityContext) { + WXAPiHandler.context = context + } + + static registerApp(call: MethodCall, result: MethodResult) { + if (WXAPiHandler.wxApi != null) { + result.success(true) + return + } + const appId: string | null = call.argument("appId") + if (!appId) { + result.error("invalid app id", "are you sure your app id is correct ?", appId) + return + } + + WXAPiHandler.registerWxAPIInternal(appId) + + result.success(WXAPiHandler.registered) + } + + static checkWeChatInstallation(result: MethodResult) { + const isInstalled = bundleManager.canOpenLink("weixin://") + result.success(isInstalled) + } + + private static registerWxAPIInternal(appId: string) { + let api = wechatOpenSDK.WXAPIFactory.createWXAPI(appId) + WXAPiHandler.registered = true + WXAPiHandler.wxApi = api + } +} \ No newline at end of file diff --git a/ohos/src/main/module.json5 b/ohos/src/main/module.json5 new file mode 100644 index 00000000..d63604c0 --- /dev/null +++ b/ohos/src/main/module.json5 @@ -0,0 +1,10 @@ +{ + "module": { + "name": "fluwx", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/pubspec.yaml b/pubspec.yaml index e5997530..770c4d88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,6 +44,8 @@ flutter: web: pluginClass: FluwxWeb fileName: src/fluwx_web.dart + ohos: + pluginClass: FluwxPlugin # To add assets to your plugin package, add an assets section, like this: # assets: From ee981f7dc1bd4e6ebfc722c4c29b28dec2963972 Mon Sep 17 00:00:00 2001 From: yeliulee Date: Sat, 26 Oct 2024 01:49:15 +0800 Subject: [PATCH 2/4] add ohos config for IDE development Signed-off-by: yeliulee (cherry picked from commit 3071830cc8b2f761a44723d8bae2d573f63c68de) --- example/ohos/build-profile.json5 | 78 ++++++++++++++++------------- example/ohos/entry/oh-package.json5 | 1 + example/ohos/oh-package.json5 | 3 +- ohos/.gitignore | 1 + 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/example/ohos/build-profile.json5 b/example/ohos/build-profile.json5 index 0d8b167e..e18a4810 100644 --- a/example/ohos/build-profile.json5 +++ b/example/ohos/build-profile.json5 @@ -1,42 +1,50 @@ /* -* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ { - "app": { - "signingConfigs": [], - "products": [ + app: { + signingConfigs: [], + products: [ { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", - "runtimeOS": "HarmonyOS", - } - ] + name: "default", + signingConfig: "default", + compatibleSdkVersion: "5.0.0(12)", + runtimeOS: "HarmonyOS", + }, + ], }, - "modules": [ + modules: [ { - "name": "entry", - "srcPath": "./entry", - "targets": [ + name: "entry", + srcPath: "./entry", + targets: [ { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file + name: "default", + applyToProducts: ["default"], + }, + ], + }, + { + name: "fluwx", + srcPath: "../../ohos", + targets: [ + { + name: "default", + applyToProducts: ["default"], + }, + ], + }, + ], +} diff --git a/example/ohos/entry/oh-package.json5 b/example/ohos/entry/oh-package.json5 index dabaee13..567f3362 100644 --- a/example/ohos/entry/oh-package.json5 +++ b/example/ohos/entry/oh-package.json5 @@ -21,6 +21,7 @@ "author": "", "license": "", "dependencies": { + "fluwx": "../../../ohos" }, } diff --git a/example/ohos/oh-package.json5 b/example/ohos/oh-package.json5 index 85a603fa..2b718d3a 100644 --- a/example/ohos/oh-package.json5 +++ b/example/ohos/oh-package.json5 @@ -29,6 +29,7 @@ "@ohos/hypium": "1.0.6" }, "overrides": { - "@ohos/flutter_ohos": "file:./har/flutter.har" + "@ohos/flutter_ohos": "file:./har/flutter.har", + "fluwx": "../../ohos", } } diff --git a/ohos/.gitignore b/ohos/.gitignore index c0f9ca4c..09c15d8f 100644 --- a/ohos/.gitignore +++ b/ohos/.gitignore @@ -7,3 +7,4 @@ /.test /BuildProfile.ets /oh-package-lock.json5 +*.har \ No newline at end of file From 0ecc38106357ecc191b26da013889cb39377c216 Mon Sep 17 00:00:00 2001 From: yeliulee Date: Sat, 26 Oct 2024 01:51:12 +0800 Subject: [PATCH 3/4] add impl for payment & share for wechat on ohos Signed-off-by: yeliulee (cherry picked from commit 480e8f770167ca3905e9c0b7b09d94d25fb788c1) --- .../ets/components/plugin/FluwxPlugin.ets | 184 +++++++++++++++--- .../plugin/handlers/FluwxShareHandler.ets | 85 ++++++++ 2 files changed, 243 insertions(+), 26 deletions(-) create mode 100644 ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets diff --git a/ohos/src/main/ets/components/plugin/FluwxPlugin.ets b/ohos/src/main/ets/components/plugin/FluwxPlugin.ets index fd085529..d46d70f0 100644 --- a/ohos/src/main/ets/components/plugin/FluwxPlugin.ets +++ b/ohos/src/main/ets/components/plugin/FluwxPlugin.ets @@ -9,10 +9,11 @@ import { MethodResult, NewWantListener, } from '@ohos/flutter_ohos'; -import * as wechatOpenSDK from "@tencent/wechat_open_sdk" +import * as wechatSDK from "@tencent/wechat_open_sdk" import { FluwxAuthHandler } from './handlers/FluwxAuthHandler'; import { AbilityConstant, common, Want } from '@kit.AbilityKit'; import { WXAPiHandler } from './handlers/WXAPiHandler'; +import { FluwxShareHandler } from './handlers/FluwxShareHandler'; const MESSAGE_CHANNEL_NAME = "com.jarvanmo/fluwx" const KEY_ERR_STR = "errStr" @@ -21,11 +22,14 @@ const KEY_OPEN_ID = "openId" const KEY_TYPE = "type" /** FluwxPlugin **/ -export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware, NewWantListener, wechatOpenSDK.WXApiEventHandler { +export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware, NewWantListener, wechatSDK.WXApiEventHandler { private channel: MethodChannel | null = null; private appContext: common.Context | null = null; - private binding: AbilityPluginBinding | null = null; + private uiContext: common.UIAbilityContext | null = null; + private binding: AbilityPluginBinding | null = null private authHandler: FluwxAuthHandler | null = null; + private shareHandler: FluwxShareHandler | null = null; + private extMsg: string | null = null; getUniqueClassName(): string { return "FluwxPlugin" @@ -36,44 +40,39 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab this.channel.setMethodCallHandler(this) this.appContext = binding.getApplicationContext(); this.authHandler = new FluwxAuthHandler(this.channel); + this.shareHandler = new FluwxShareHandler(); } onDetachedFromEngine(binding: FlutterPluginBinding): void { this.channel = null; this.appContext = null; this.authHandler = null; + this.shareHandler = null; } onAttachedToAbility(binding: AbilityPluginBinding): void { - WXAPiHandler.setContext(binding.getAbility().context); - this.binding = binding; + this.binding = binding + this.uiContext = binding.getAbility().context; + WXAPiHandler.setContext(this.uiContext); binding.addOnNewWantListener(this) } onDetachedFromAbility(): void { - this.binding = null; + this.binding?.removeOnNewWantListener(this) + this.binding = null + this.uiContext = null; } - // 微信回调 start - - onReq = (req: wechatOpenSDK.BaseReq): void => { - } - onResp = (resp: wechatOpenSDK.BaseResp): void => { - if (resp instanceof wechatOpenSDK.SendAuthResp) { - this.handleAuthResponse(resp); + onMethodCall(call: MethodCall, result: MethodResult): void { + if (call.method.startsWith("share")) { + this.shareHandler?.share(call, result); return; } - } - // 微信回调 end - - - onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void { - WXAPiHandler.wxApi?.handleWant(want, this) - } - - onMethodCall(call: MethodCall, result: MethodResult): void { switch (call.method) { + case "isWeChatInstalled": + WXAPiHandler.checkWeChatInstallation(result); + break; case "registerApp": WXAPiHandler.registerApp(call, result); break; @@ -86,15 +85,100 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab case "stopAuthByQRCode": this.authHandler?.stopAuthByQRCode(result); break; - case "isWeChatInstalled": - WXAPiHandler.checkWeChatInstallation(result); + case "payWithFluwx": + this.handlePay(call, result); + break; + case "payWithHongKongWallet": + // TODO + result.notImplemented(); + break; + case "launchMiniProgram": + // TODO + result.notImplemented(); + break; + case "subscribeMsg": + // TODO + result.notImplemented(); + break; + case "autoDeduct": + // TODO + result.notImplemented(); + break; + case "autoDeductV2": + // TODO + result.notImplemented(); + break; + case "openWXApp": + result.success(WXAPiHandler.wxApi?.openWechat(this.uiContext)); + break; + case "getExtMsg": + result.success(this.extMsg); + this.extMsg = null; + break; + case "openWeChatCustomerServiceChat": + // TODO + result.notImplemented(); + break; + case "checkSupportOpenBusinessView": + // TODO + result.notImplemented(); + break; + case "openBusinessView": + // TODO + result.notImplemented(); + break; + case "openWeChatInvoice": + // TODO + result.notImplemented(); + break; + case "openUrl": + // TODO + result.notImplemented(); + break; + case "openRankList": + // TODO + result.notImplemented(); + break; + case "attemptToResumeMsgFromWx": + this.attemptToResumeMsgFromWx(result); + break; + case "selfCheck": + result.success(null) break; default: - result.notImplemented() + result.notImplemented(); } } - handleAuthResponse(resp: wechatOpenSDK.SendAuthResp) { + onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void { + WXAPiHandler.wxApi?.handleWant(want, this); + } + + // 微信回调 start + + onReq = (req: wechatSDK.BaseReq): void => { + // TODO + } + onResp = (resp: wechatSDK.BaseResp): void => { + if (resp instanceof wechatSDK.SendAuthResp) { + this.onAuthResponse(resp); + return; + } + + if (resp instanceof wechatSDK.SendMessageToWXResp) { + this.onSendMessageToWXResp(resp); + return; + } + + if (resp instanceof wechatSDK.PayResp) { + this.onPayResp(resp); + return; + } + } + + // 微信回调 end + + onAuthResponse(resp: wechatSDK.SendAuthResp) { const result: Map = new Map(); result.set(KEY_ERR_CODE, resp.errCode); result.set(KEY_ERR_STR, resp.errStr); @@ -108,4 +192,52 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab this.channel?.invokeMethod("onAuthResponse", result); } + + onSendMessageToWXResp(resp: wechatSDK.SendMessageToWXResp) { + const _result: Map = new Map(); + _result.set(KEY_ERR_CODE, resp.errCode); + _result.set(KEY_ERR_STR, resp.errStr); + _result.set(KEY_TYPE, resp.type); + _result.set(KEY_OPEN_ID, resp.openId); + + this.channel?.invokeMethod("onShareResponse", _result); + } + + onPayResp(resp: wechatSDK.PayResp) { + const _result: Map = new Map(); + _result.set(KEY_ERR_CODE, resp.errCode); + _result.set(KEY_ERR_STR, resp.errStr); + _result.set(KEY_TYPE, resp.type); + _result.set("prepayId", resp.prepayId); + _result.set("returnKey", resp.returnKey); + _result.set("extData", resp.extData); + + this.channel?.invokeMethod("onPayResponse", _result); + } + + async handlePay(call: MethodCall, result: MethodResult) { + if (!WXAPiHandler.wxApi) { + result.error("Unassigned WxApi", "please config wxapi first", null); + return; + } + + const request = new wechatSDK.PayReq(); + request.appId = call.argument("appId"); + request.partnerId = call.argument("partnerId"); + request.prepayId = call.argument("prepayId"); + request.packageValue = call.argument("packageValue"); + request.nonceStr = call.argument("nonceStr"); + request.timeStamp = call.argument("timeStamp").toString(); + request.sign = call.argument("sign"); + request.signType = call.argument("signType"); + request.extData = call.argument("extData"); + + const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request); + + result.success(done); + } + + attemptToResumeMsgFromWx(result: MethodResult) { + WXAPiHandler.wxApi?.handleWant(this.binding?.getAbility().launchWant, this) + } } \ No newline at end of file diff --git a/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets new file mode 100644 index 00000000..19862937 --- /dev/null +++ b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets @@ -0,0 +1,85 @@ +import { Any, MethodCall, MethodResult } from "@ohos/flutter_ohos" +import * as wechatSDK from "@tencent/wechat_open_sdk" +import { WXAPiHandler } from "./WXAPiHandler" +import { buffer } from "@kit.ArkTS" +import { fileUri } from "@kit.CoreFileKit" + +export class FluwxShareHandler { + share(call: MethodCall, result: MethodResult) { + if (!WXAPiHandler.wxApi) { + result.error("Unassigned WxApi", "please config wxapi first", null); + return; + } + + switch (call.method) { + case "shareText": + this.shareText(call, result); + break; + case "shareMiniProgram": + // TODO + result.notImplemented(); + break; + case "shareImage": + this.shareImage(call, result); + break; + case "shareMusic": + // TODO + result.notImplemented(); + break; + case "shareVideo": + // TODO + result.notImplemented(); + break; + case "shareWebPage": + // TODO + result.notImplemented(); + break; + case "shareFile": + // TODO + result.notImplemented(); + break; + default: + result.notImplemented(); + break; + } + } + + async shareText(call: MethodCall, result: MethodResult) { + const textObj = new wechatSDK.WXTextObject(); + textObj.text = call.argument("source"); + + const mediaMsg = new wechatSDK.WXMediaMessage(); + mediaMsg.mediaObject = textObj; + + const req = new wechatSDK.SendMessageToWXReq(); + req.message = mediaMsg; + + result.success(WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req)) + } + + async shareImage(call: MethodCall, result: MethodResult) { + const map: Map = call.argument("source") ?? new Map(); + // const imageHash: string | null = call.argument("imgDataHash"); + const bytes: Uint8Array | null = map.get("uint8List"); + + const imageObj = new wechatSDK.WXImageObject(); + + if (bytes) { + const buff: buffer.Buffer = buffer.from(bytes.buffer); + imageObj.imageData = buff.toString("base64", 0, buff.length); + } else { + const localImagePath: string | null = map.get("localImagePath"); + if (localImagePath) { + imageObj.uri = localImagePath.startsWith("file://") ? localImagePath : fileUri.getUriFromPath(localImagePath) + } + } + + const mediaMsg = new wechatSDK.WXMediaMessage(); + mediaMsg.mediaObject = imageObj; + + const req = new wechatSDK.SendMessageToWXReq(); + req.message = mediaMsg; + + result.success(WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req)); + } +} \ No newline at end of file From 7ad9e78e7ab47b657f70ef1337f205ff06fcd303 Mon Sep 17 00:00:00 2001 From: yeliulee Date: Sat, 26 Oct 2024 11:34:05 +0800 Subject: [PATCH 4/4] Add documentation for OpenHarmony Signed-off-by: yeliulee --- README.md | 41 +++++++++++++++++++++++++++++------------ README_CN.md | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 30c2574a..00a4ceb6 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,24 @@ # Fluwx -![pub package](https://img.shields.io/pub/v/fluwx.svg) + +[![pub package](https://img.shields.io/pub/v/fluwx.svg)](https://pub.dartlang.org/packages/fluwx) ![Build status](https://github.com/OpenFlutter/fluwx/actions/workflows/build_test.yml/badge.svg) -====== +[![GitHub stars](https://img.shields.io/github/stars/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/network) +[![GitHub license](https://img.shields.io/github/license/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/blob/master/LICENSE) +[![GitHub issues](https://img.shields.io/github/issues/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/issues) +OpenFlutter + +--- ![logo](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/fluwx_logo.png) [中文请移步此处](./README_CN.md) ## What's Fluwx + `Fluwx` is flutter plugin for [WeChatSDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html) which allows developers to call [WeChatSDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html) native APIs. - > Join QQ Group now: 1003811176 ![QQGroup](https://gitee.com/OpenFlutter/resoures-repository/raw/master/common/flutter.png) @@ -45,13 +52,13 @@ Add the following dependencies in your `pubspec.yaml` file: dependencies: fluwx: ^${latestVersion} ``` + ![pub package](https://img.shields.io/pub/v/fluwx.svg) `Fluwx` without pay: > Developers who need to exclude payment for iOS can enable `no_pay` in [pubspec.yaml](./example/pubspec.yaml#L86). - > NOTE: Never forget to replace ^${latestVersion} with actual version. ## Configurations @@ -68,8 +75,9 @@ for more details. - universal_link. Recommend for iOS. It'll be used to generate universal link on your projects. - scene_delegate. Optional. Use `AppDelegate` or `SceneDelegate`. See [official documents](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) for more details. -* For iOS +- For iOS If you are failing `cannot load such file -- plist` on iOS, please do the following steps: + ```shell # step.1 install missing dependencies sudo gem install plist @@ -78,6 +86,19 @@ cd example/ios/ # step.3 execute pod install ``` + +- On OpenHarmony, to check if WeChat is installed, add the following to the module.json5 in your project + +```json5 +{ + "module": { + "querySchemes": [ + "weixin" + ], + } +} +``` + ## Register WxAPI Register your app via `fluwx` if necessary. @@ -86,6 +107,7 @@ Register your app via `fluwx` if necessary. Fluwx fluwx = Fluwx(); fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.univerallink.com/link/"); ``` + The param `universalLink` only works with iOS. You can read [this document](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) to learn how to create universalLink. You can also learn how to add URL schema, how to add `LSApplicationQueriesSchemes` in your iOS project. This is essential. @@ -109,13 +131,14 @@ For more capabilities, you can read the public functions of `fluwx`. [These questions maybe help](./doc/QA_CN.md) ## Donate + Buy the writer a cup of coffee。 ## Subscribe Us On WeChat -![subscribe](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/wx_subscription.png) +![subscribe](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/wx_subscription.png) ## Star history @@ -123,7 +146,6 @@ Buy the writer a cup of coffee。 ## LICENSE - Copyright 2023 OpenFlutter Project Licensed to the Apache Software Foundation (ASF) under one or more contributor @@ -140,8 +162,3 @@ Buy the writer a cup of coffee。 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - - - - - diff --git a/README_CN.md b/README_CN.md index 34b002ee..6d937ff2 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,14 +1,21 @@ # Fluwx -![pub package](https://img.shields.io/pub/v/fluwx.svg) + +[![pub package](https://img.shields.io/pub/v/fluwx.svg)](https://pub.dartlang.org/packages/fluwx) ![Build status](https://github.com/OpenFlutter/fluwx/actions/workflows/build_test.yml/badge.svg) -====== +[![GitHub stars](https://img.shields.io/github/stars/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/network) +[![GitHub license](https://img.shields.io/github/license/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/blob/master/LICENSE) +[![GitHub issues](https://img.shields.io/github/issues/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/issues) +OpenFlutter + +--- ![logo](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/fluwx_logo.png) ## 什么是Fluwx -`Fluwx` 是一个[微信SDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html)插件,它允许开发者调用 -[微信原生SDK ](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html). +`Fluwx` 是一个[微信SDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html)插件,它允许开发者调用 +[微信原生SDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html). > 加入我们的QQ群: 1003811176 @@ -30,11 +37,9 @@ > 破坏性更新 :从4.5.0起,当分享图片到微信时,如果不支持FileProvider方式分享,Fluwx不再尝试申请WRITE_EXTERNAL_STORAGE权限,这意味着你需要自己处理权限问题。 - `Fluwx` 可以做很多工作但不是所有. 在集成之前,最好读一下[官方文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html). 然后你才知道怎么生成签名,怎么使用universal link以及怎么添加URL schema等. - ## 安装 在`pubspec.yaml` 文件中添加`fluwx`依赖: @@ -45,6 +50,7 @@ dependencies: fluwx: ^${latestVersion} ``` + ![pub package](https://img.shields.io/pub/v/fluwx.svg) 不带支付的`Fluwx`: @@ -67,8 +73,9 @@ dependencies: - universal_link. iOS 推荐. 它将用自动配置universal_link。 - scene_delegate. iOS 可选. 使用 `AppDelegate` 还是使用 `SceneDelegate`. 查阅[官方文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html)了解更多. -* For iOS +- For iOS 如果你在iOS上遇到了 `cannot load such file -- plist`, 请按照以下步骤进行操作: + ```shell # step.1 安装必要依赖 sudo gem install plist @@ -78,6 +85,18 @@ cd example/ios/ pod install ``` +- 在 OpenHarmony 上,要检查微信是否已安装,请在项目的 module.json5 中添加以下内容 + +```json5 +{ + "module": { + "querySchemes": [ + "weixin" + ], + } +} +``` + ## 注册 WxAPI 通过 `fluwx` 注册WxApi. @@ -109,11 +128,13 @@ fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.unive [这些问题可能对你有帮助](./doc/QA_CN.md) ## 捐助 + 开源不易,请作者喝杯咖啡。 ## 关注公众号 + ![subscribe](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/wx_subscription.png) ## 关注趋势 @@ -138,8 +159,3 @@ fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.unive WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - - - - -