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

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)
相关推荐
黑臂麒麟1 小时前
HarmonyOS鸿蒙实战应用7:随手账本——数据导出与分享
华为·app·arkts·鸿蒙
贾伟康3 小时前
【天体运行模拟|11】HarmonyOS ArkTS 收藏与笔记实战:同步知识页和个人学习记录
harmonyos·arkts·preferences·多设备适配·arkdata
2501_919749034 小时前
华为鸿蒙录音可视化APP—小羊声觉
华为·harmonyos·鸿蒙
大雷神4 小时前
HarmonyOS AR Engine深度估计实战——把毫米距离画成实时热力图
华为·ar·harmonyos
GKxx4 小时前
在 HarmonyOS 上给 QEMU 搭一个最小 aarch64 Linux guest(内核 + busybox initramfs)
linux·华为·qemu·harmonyos·鸿蒙·鸿蒙pc
黑臂麒麟5 小时前
屏幕信息全解析:HarmonyOS的分辨率、刷新率、折叠状态一个API搞定
华为·arkts·鸿蒙
黑臂麒麟5 小时前
HarmonyOS 网络连接诊断实战:检测网络状态、WiFi 切换、弱网监测一网打尽
网络·华为·arkts·鸿蒙
贾伟康5 小时前
【天体运行模拟|08】HarmonyOS ArkTS 单位换算实战:处理天文尺度、科学计数与精度
harmonyos·arkts·arkui·数值精度·单位换算
lilian2335 小时前
HarmonyOS 7 新特性(十三)|3DGS 模型加载、交互与性能回退
3d·交互·harmonyos
2501_919749036 小时前
华为鸿蒙免费反诈APP—小羊反诈
华为·harmonyos·鸿蒙