diff --git a/ohos/oh-package.json5 b/ohos/oh-package.json5 index bf2f2db3..3d1dd098 100644 --- a/ohos/oh-package.json5 +++ b/ohos/oh-package.json5 @@ -7,6 +7,6 @@ "license": "Apache-2.0", "dependencies": { "@ohos/flutter_ohos": "file:./har/flutter.har", - "@tencent/wechat_open_sdk": "^1.0.0" + "@tencent/wechat_open_sdk": "1.0.3" } } diff --git a/ohos/src/main/ets/components/plugin/FluwxPlugin.ets b/ohos/src/main/ets/components/plugin/FluwxPlugin.ets index d46d70f0..701d8c4a 100644 --- a/ohos/src/main/ets/components/plugin/FluwxPlugin.ets +++ b/ohos/src/main/ets/components/plugin/FluwxPlugin.ets @@ -93,8 +93,7 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab result.notImplemented(); break; case "launchMiniProgram": - // TODO - result.notImplemented(); + this.launchMiniProgram(call, result); break; case "subscribeMsg": // TODO @@ -174,6 +173,11 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab this.onPayResp(resp); return; } + + if (resp instanceof wechatSDK.LaunchMiniProgramResp) { + this.onLaunchMiniProgramResp(resp); + return; + } } // 微信回调 end @@ -215,6 +219,20 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab this.channel?.invokeMethod("onPayResponse", _result); } + onLaunchMiniProgramResp(resp: wechatSDK.LaunchMiniProgramResp) { + 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); + + if (resp.extMsg) { + _result.set("extMsg", resp.extMsg); + } + + this.channel?.invokeMethod("onLaunchMiniProgramResponse", _result); + } + async handlePay(call: MethodCall, result: MethodResult) { if (!WXAPiHandler.wxApi) { result.error("Unassigned WxApi", "please config wxapi first", null); @@ -240,4 +258,16 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab attemptToResumeMsgFromWx(result: MethodResult) { WXAPiHandler.wxApi?.handleWant(this.binding?.getAbility().launchWant, this) } + + async launchMiniProgram(call: MethodCall, result: MethodResult) { + const request = new wechatSDK.LaunchMiniProgramReq(); + request.userName = call.argument("userName"); + request.path = call.argument("path"); + // sdk 内当前没 type 常量, 直接使用传入的参数 + request.miniprogramType = call.argument("miniprogramType") ?? 0; + + const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request); + + result.success(done); + } } \ 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 index 64e56ea6..64eb4b20 100644 --- a/ohos/src/main/ets/components/plugin/handlers/FluwxAuthHandler.ets +++ b/ohos/src/main/ets/components/plugin/handlers/FluwxAuthHandler.ets @@ -47,7 +47,7 @@ export class FluwxAuthHandler implements OAuthCallback { return this.diffDevOauth; } - sendAuth(call: MethodCall, result: MethodResult) { + async sendAuth(call: MethodCall, result: MethodResult) { const req = new SendAuthReq(); req.isOption1 = false; req.scope = call.argument("scope"); @@ -57,10 +57,10 @@ export class FluwxAuthHandler implements OAuthCallback { req.openId = openid; } req.nonAutomatic = call.argument("nonAutomatic") ?? false; - result.success(WXAPiHandler.wxApi?.sendReq( - WXAPiHandler.uiContext, - req - )) + + const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req); + + result.success(done); } authByQRCode(call: MethodCall, result: MethodResult) { diff --git a/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets index 19862937..2c0c05df 100644 --- a/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets +++ b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets @@ -54,7 +54,9 @@ export class FluwxShareHandler { const req = new wechatSDK.SendMessageToWXReq(); req.message = mediaMsg; - result.success(WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req)) + const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req); + + result.success(done) } async shareImage(call: MethodCall, result: MethodResult) { @@ -80,6 +82,7 @@ export class FluwxShareHandler { const req = new wechatSDK.SendMessageToWXReq(); req.message = mediaMsg; - result.success(WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req)); + const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req); + result.success(done); } } \ 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 index 6126472c..5cb8f5fd 100644 --- a/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets +++ b/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets @@ -1,6 +1,6 @@ import * as wechatOpenSDK from "@tencent/wechat_open_sdk" import { MethodCall, MethodResult } from '@ohos/flutter_ohos' -import { bundle, bundleManager, common } from '@kit.AbilityKit' +import { bundleManager, common } from '@kit.AbilityKit' export class WXAPiHandler { static wxApi: wechatOpenSDK.WXApi | null = null