收藏
回答

鸿蒙 app 打开小程序异常,打开了“演示”小程序,没有打开目标小程序

问题类型 操作系统 操作系统版本 手机型号 微信版本
Bug HarmonyOS HarmonyOS 6.0.0.130 SP25 nova 14 8.0.16

我使用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


回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员--许涛
    社区技术运营专员--许涛
    04-24

    你好,复现问题时麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点,bundleid、identifier、appid和opensdk的调用时间点(可以社区私信提供)和open帐号后台移动应用签名包名截图,私信后请在评论区回复

    04-24
    有用
    回复 6
    • 夕阳晨伤
      夕阳晨伤
      04-25
      信息都私信发给你了
      04-25
      回复
    • 社区技术运营专员--许涛
      社区技术运营专员--许涛
      04-27回复夕阳晨伤
      拉起小程序要用LaunchMiniProgramReq
      04-27
      回复
    • 夕阳晨伤
      夕阳晨伤
      04-28
      04-28
      回复
    • 夕阳晨伤
      夕阳晨伤
      04-28
      用的就是LaunchMiniProgramReq
      04-28
      回复
    • 夕阳晨伤
      夕阳晨伤
      04-29
      我补充了纯ArkTS项目的demo信息,已私信发了,麻烦帮忙看一下
      04-29
      回复
    查看更多(1)
  • 智能回答 智能回答 本次回答由AI生成
    04-23
    有用
    回复 1
    • 夕阳晨伤
      夕阳晨伤
      04-24
      请求参数(除了原始ID)我都提供了,鸿蒙系统调用栈日志我要怎么提供呢
      04-24
      回复
登录 后发表内容