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

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)
相关推荐
Georgewu2 小时前
【HarmonyOS 5】鸿蒙分布式协同应用开发详解
harmonyos
君莫笑111117 小时前
从零到一教你在鸿蒙中上架应用--全流程保姆级
harmonyos
二流小码农7 小时前
鸿蒙开发:资讯项目实战之项目初始化搭建
android·ios·harmonyos
HarmonyOS_SDK8 小时前
如何在应用中实现地图关键字搜索和标记聚合功能?
harmonyos
别说我什么都不会10 小时前
【OpenHarmony】图形图像加载:LargeImage
harmonyos
Aisanyi12 小时前
【鸿蒙开发】PC实现开局沉浸式全屏
前端·华为·harmonyos
我睡醒再说15 小时前
以下是对华为 HarmonyOS NETX 5属性动画(ArkTS)文档的结构化整理,通过层级标题、表格和代码块提升可读性:
harmonyos
我睡醒再说15 小时前
ArkUI-X跨平台开发能力解析:优势与限制场景
harmonyos
我睡醒再说15 小时前
纯血Harmony NETX 5小游戏实践:趣味三消游戏(附源文件)
harmonyos
我睡醒再说15 小时前
HarmonyOS NETX 5ArkUI-X打造数字猜谜游戏:(附源文件)
harmonyos