我使用fluwx组件在鸿蒙手机上跳转微信小程序,未打开目标小程序,打开了“演示”小程序。在使用微信SDK跳转微信小程序之前,SDK已经初始化并注册appid。
fluwx组件版本:
fluwx:
dependency: "direct main"
description:
name: fluwx
sha256: "7e92d2000ee49c5262a88c51ea2d22b91a753d5b29df27cc264bb0a115d65373"
url: "https://pub.dev"
source: hosted
version: "5.7.5"
鸿蒙原生端使用的微信SDK版本:
"overrides": {
"@tencent/wechat_open_sdk": "^1.0.16"
}
fluwx源码:
// 注册APPID
case "registerApp":
hilog.info(DOMAIN, TAG, `[registerApp] - appId: ${call.argument("appId")};iOS: ${call.argument("iOS")};android: ${call.argument("android")};universalLink: ${call.argument("universalLink")};`)
WXAPiHandler.registerApp(call, result);
hilog.info(DOMAIN, TAG, `[registerApp] - register app finished, registered is ${WXAPiHandler.wxApiRegistered}`)
break;
// WXAPiHandler代码
import * as wechatOpenSDK from "@tencent/wechat_open_sdk"
import { MethodCall, MethodResult } from '@ohos/flutter_ohos'
import { bundleManager, common } from '@kit.AbilityKit'
import { hilog } from "@kit.PerformanceAnalysisKit"
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://") || WXAPiHandler.wxApi?.isWXAppInstalled() === true;
result.success(isInstalled);
}
static checkSupportOpenBusinessView(result: MethodResult) {
if (!WXAPiHandler.wxApi) {
result.error("Unassigned WxApi", "please config wxapi first", null);
return;
}
const isInstalled = bundleManager.canOpenLink("weixin://") || WXAPiHandler.wxApi?.isWXAppInstalled() === true;
if (!isInstalled) {
result.error("WeChat Not Installed", "Please install the WeChat first", null);
return;
}
result.success(true);
}
private static registerWxAPIInternal(appId: string) {
let api = wechatOpenSDK.WXAPIFactory.createWXAPI(appId)
WXAPiHandler.registered = true
WXAPiHandler.wxApi = api
}
}
async shareMiniProgram(call: MethodCall, result: MethodResult) {
const miniProgramObject = new wxopensdk.WXMiniProgramObject()
miniProgramObject.userName = call.argument("userName")
miniProgramObject.path = call.argument("path")
let miniProgramType = wxopensdk.WXMiniProgramType.RELEASE
let miniProgramTypeInt: number = call.argument("miniProgramType")
if (miniProgramTypeInt === 1) {
miniProgramType = wxopensdk.WXMiniProgramType.TEST
} else if (miniProgramTypeInt === 2) {
miniProgramType = wxopensdk.WXMiniProgramType.PREVIEW
}
miniProgramObject.miniprogramType = miniProgramType
const mediaMessage = new wxopensdk.WXMediaMessage()
mediaMessage.mediaObject = miniProgramObject
mediaMessage.title = call.argument("title")
mediaMessage.description = call.argument("description")
const thumbData: Uint8Array | null = call.argument("thumbData");
if (thumbData) {
mediaMessage.thumbData = thumbData;
}
// 调用微信SDK的API进行跳转
const req = new wxopensdk.SendMessageToWXReq()
this.setCommonArgs(call, req, mediaMessage)
req.message = mediaMessage
hilog.info(DOMAIN, TAG, `userName: ${call.argument("userName")};path: ${call.argument("path")};miniProgramType: ${call.argument("miniProgramType") ?? 0}`)
const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req);
result.success(done)
}
日志:
04-23 16:38:29.990 27526-27526 A000FF/com....osapp/Flutter com.....ohosapp W FlutterEngineCxnRegistry --> Adding plugin: FluwxPlugin
04-23 16:38:31.534 27526-27526 A0FF00/com....p/FluwxPlugin com.....ohosapp I [registerApp] - appId: wx***4b;iOS: true;android: true;universalLink: https://m.***.com/;
04-23 16:38:31.535 27526-27526 A0FF00/com....p/FluwxPlugin com.....ohosapp I [registerApp] - register app finished, registered is true
04-23 16:39:19.110 27526-27526 A0FF00/com....p/FluwxPlugin com.....ohosapp I userName: {小程序原始ID};path: /pagesPresell/activity/index;miniProgramType: 0

你好,复现问题时麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点,bundleid、identifier、appid和opensdk的调用时间点(可以社区私信提供)和open帐号后台移动应用签名包名截图,私信后请在评论区回复
async launchMiniProgram(call: MethodCall, result: MethodResult) {// ---------->> 这里用的就是 LaunchMiniProgramReqconst request = new wechatSDK.LaunchMiniProgramReq();// <<request.userName = call.argument("userName");request.path = call.argument("path");// sdk 内当前没 type 常量, 直接使用传入的参数request.miniprogramType = call.argument("miniProgramType") ?? 0;hilog.info(DOMAIN, TAG, `userName: ${call.argument("userName")};path: ${call.argument("path")};miniProgramType: ${call.argument("miniProgramType") ?? 0}`)const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);result.success(done);}