鸿蒙验证码,鸿蒙认证服务验证码,鸿蒙云存储上传图片

1、在entry / oh-package.json5目录下,增加依赖:

复制代码
 "dependencies": {
    '@hw-agconnect/cloud': "^1.0.0",
    '@hw-agconnect/hmcore':  "^1.0.0",
    '@hw-agconnect/auth-component':  "^1.0.0",
    'long': '^5.2.1'
  }

整体效果

复制代码
{
  "license": "",
  "devDependencies": {},
  "author": "",
  "name": "entry",
  "description": "Please describe the basic information.",
  "main": "",
  "version": "1.0.0",
  "dependencies": {
    '@hw-agconnect/cloud': "^1.0.0",
    '@hw-agconnect/hmcore':  "^1.0.0",
    '@hw-agconnect/auth-component':  "^1.0.0",
    'long': '^5.2.1'
  }
}

​​​​​​​2、初始化、在应用初始化阶段使用context初始化SDK,推荐在EntryAbility的onCreate中进行。

复制代码
  async initSDK(){
    let input = await this.context.resourceManager.getRawFileContent('agconnect-services.json')
    
    let jsonString  = util.TextDecoder.create('utf-8', {
      ignoreBOM: true
    }).decodeWithStream(input, {
      stream: false
    });

    initialize(this.context, JSON.parse(jsonString));
  }

3、在界面中首先导入一个包:

复制代码
import {VerifyCodeAction} from '@hw-agconnect/cloud'

4.1、认证服务,在使用时调用:

复制代码
  sendCode(){
    if (this.checkPhone('17610176666')){
      // cloud
      cloud.auth().requestVerifyCode({
        action:VerifyCodeAction.REGISTER_LOGIN,//注册登录
        lang:'zh_CN',

        sendInterval:60,//多少秒发一次
        verifyCodeType:{
          phoneNumber:'17610176666',
          countryCode:'86',//中国手机号前面+86
          kind:'phone'
        }
      })

    }
  }



  checkPhone(number:string){
    return !!(number&&new RegExp('^1[3-9]\\d{9}$').test(number))
  }

4.2、端云存储上传照片

复制代码
    let file=util.generateRandomUUID()+'.jpg'
    await cloud.storage().upload({
      localPath:'',//本地地址
      cloudPath:file
    })
    // 下载后的地址
    let imgUrl=await cloud.storage().getDownloadURL(file)
相关推荐
李游Leo2 小时前
HarmonyOS 7 文搜图实战 04:图片增删、索引重建与异常恢复完善 SnapSeek 可维护性【鸿蒙心迹】
harmonyos
三掌柜6666 小时前
# ArkWeb 手记 03|把 JSBridge 做成协议
harmonyos
轻口味6 小时前
HarmonyOS 7 新特性5:平行视界——轻视界文集的两栏阅读与窗口状态边界矩阵真机实测
华为·矩阵·harmonyos·鸿蒙·平行视界
动物园猫7 小时前
Compose Multiplatform 三方库 compose-icons(Octicons)的 OpenHarmony 鸿蒙化适配实战
华为·ar·harmonyos
旺仔Sec8 小时前
2026年江西省职业院校技能大赛鸿蒙应用开发赛项竞赛任务书(高职组)样题
华为·harmonyos
曲鸟8 小时前
体验完鸿蒙AI后的几点感受
人工智能·华为·harmonyos
HwJack208 小时前
【HarmonyOS开发小实践】Node-API 的SO 命名规则、多线程限制与调试
华为·harmonyos
LucianaiB8 小时前
用 HarmonyOS 做一张会写诗的月夜明信片:追月的完整开发复盘
华为·ai·harmonyos·skill
蒸鱼Yuzheng9 小时前
HarmonyOS HAP 与调试工件治理:包结构、版本身份与自动化证据链
自动化·性能测试·数据治理·harmonyos·hap
轻口味10 小时前
HarmonyOS 7 新特性3:TiledGSNode——轻带看让 71MB 庭院按视口按需加载:真机实测与零请求降级
华为·harmonyos·鸿蒙·tiledgsnode