更新记录
1.0.0(2026-05-20) 下载此版本
实现华为AGC云函数调用,示例项目结合华为登录的unionid实现云函数查询云数据库
平台兼容性
uni-app(5.01)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | 14 |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(5.01)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | - | - | - | - |
ysk-login
简介
ysk-login 是一款专为 HarmonyOS Next (鸿蒙纯血版) 生态系统打造的轻量级、高性能统一登录解决方案。它基于 UTS (UniType Script) 语言开发,旨在解决鸿蒙原生应用开发中多平台账号体系接入复杂、原生能力调用门槛高的问题
功能特性
- ✅ 原生性能:基于 ArkTS 开发,直接调用鸿蒙系统 API。
- ✅ 类型安全:内置完善的 TypeScript/UTS 类型定义。
- ✅ 灵活传参:支持传入
Object对象或JSON字符串作为云函数参数。 - ✅ 异常捕获:统一的错误处理机制,方便前端调试。
使用方式
设备登录华为账号 import { authentication } from "@kit.AccountKit"; import { util } from "@kit.ArkTS"; import { hilog } from "@kit.PerformanceAnalysisKit"; import { BusinessError } from '@kit.BasicServicesKit'; import { promptAction } from "@kit.ArkUI"; import { common } from "@kit.AbilityKit";
interface fanh{
suc:(data:Object)=>void
fail:(data:Object)=>void
}
export function login(data:fanh){
// 创建登录请求,并设置参数
const loginRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();
// 获取头像昵称需要传如下scope
loginRequest.scopes = ['profile'];
// 若开发者需要进行服务端开发以获取头像昵称,则需传如下permission获取authorizationCode
loginRequest.permissions = ['serviceauthcode'];
// 用户是否需要登录授权,该值为true且用户未登录或未授权时,会拉起用户登录或授权页面
loginRequest.forceAuthorization = true;
// 用于防跨站点请求伪造
loginRequest.state = util.generateRandomUUID();
const context = getContext() as common.UIAbilityContext;
// 此示例为代码片段,实际需在自定义组件实例中使用,以获取UIContext对象作为函数入参
const controller = new authentication.AuthenticationController(context);
controller.executeRequest(loginRequest).then((response: authentication.LoginWithHuaweiIDResponse) => {
const loginWithHuaweiIDResponse = response as authentication.AuthorizationWithHuaweiIDResponse;
const state = loginWithHuaweiIDResponse.state;
if (state && loginRequest.state !== state) {
hilog.error(0x0000, 'testTag', Failed to login. The state is different, response state: ${state});
return;
}
const loginWithHuaweiIDCredential = loginWithHuaweiIDResponse?.data;
console.log(`loginWithHuaweiIDCredential: ${JSON.stringify(loginWithHuaweiIDCredential)}`);
if(loginWithHuaweiIDCredential)
return data.suc(loginWithHuaweiIDCredential)
})
.catch((error: BusinessError) => {
hilog.error(0x0000, 'testTag', Failed to login. Error code:+ error.message)
return data.fail(error)
})
}

收藏人数:
下载插件并导入HBuilderX
赞赏(0)
下载 0
赞赏 0
下载 11985453
赞赏 1915
赞赏
京公网安备:11010802035340号