Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to "@tencent/wechat_open_sdk" v1.0.3 and add impl for plugin.launchMiniProgram #671

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ohos/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
34 changes: 32 additions & 2 deletions ohos/src/main/ets/components/plugin/FluwxPlugin.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -215,6 +219,20 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab
this.channel?.invokeMethod("onPayResponse", _result);
}

onLaunchMiniProgramResp(resp: wechatSDK.LaunchMiniProgramResp) {
const _result: Map<string, ESObject> = 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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading