更新记录

1.0.0(2026-03-20) 下载此版本

实现iOS和鸿蒙两端微信登录。


平台兼容性

uni-app x(5.01)

Chrome Safari Android iOS 鸿蒙 微信小程序
× × × 12 5.0 ×

ul-wechat-login

轻量级微信授权登录 UTS 插件,支持 iOS 和鸿蒙 Next。

使用方式

import { isWechatInstalled, wechatLogin } from '@/uni_modules/ul-wechat-login';

// 无需手动注册,插件在 App 启动时自动从 config.uts 读取配置并注册

// 检查微信是否安装
const installed = isWechatInstalled();

// 发起登录
wechatLogin({
  success: (res) => {
    console.log('授权 code:', res.code);
    // 将 code 发送到后端换取 token
  },
  fail: (err) => {
    console.error('登录失败:', err.errCode, err.errMsg);
  }
});

接入方配置

1. 填写微信配置(必需,所有平台通用)

打开 uni_modules/ul-wechat-login/utssdk/config.uts,填入你的微信 AppID 和 Universal Link:

export const WX_APP_ID = "你的微信AppId"
export const WX_UNIVERSAL_LINK = "你的UniversalLink"

2. iOS 额外配置

打开 uni_modules/ul-wechat-login/utssdk/app-ios/Info.plist,将 CFBundleURLSchemes 中的字符串替换为你的微信 AppID。

manifest.json 中配置 Associated Domains:

"entitlements": {
  "com.apple.developer.associated-domains": ["applinks:你的域名"]
}

3. 鸿蒙额外配置

由于 harmony-configs/entry/src/main/module.json5 会完全替换默认配置,需要提供完整的配置文件。

在项目的 harmony-configs/entry/src/main/module.json5 文件中使用以下完整配置:

{
  "module": {
    "name": "entry",
    "type": "entry",
    "description": "$string:module_desc",
    "mainElement": "EntryAbility",
    "deviceTypes": ["phone", "tablet", "2in1"],
    "deliveryWithInstall": true,
    "installationFree": false,
    "pages": "$profile:main_pages",
    "querySchemes": ["weixin", "wxopensdk"],
    "abilities": [{
      "name": "EntryAbility",
      "srcEntry": "./ets/entryability/EntryAbility.ets",
      "description": "$string:EntryAbility_desc",
      "icon": "$media:layered_image",
      "label": "$string:EntryAbility_label",
      "startWindowIcon": "$media:startIcon",
      "startWindowBackground": "$color:start_window_background",
      "exported": true,
      "skills": [{
        "entities": ["entity.system.home"],
        "actions": ["action.system.home", "wxentity.action.open"]
      }]
    }],
    "requestPermissions": [{ "name": "ohos.permission.INTERNET" }]
  }
}

自定义基座

原生插件必须使用自定义基座运行。在 HBuilderX 中:运行 -> 运行到手机 -> 制作自定义调试基座。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

ohos.permission.INTERNET

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不收集任何用户数据,微信授权 code 由调用方自行处理

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。