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

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)
相关推荐
MarkHD8 小时前
第十八天 WebView深度优化指南
华为·harmonyos
塞尔维亚大汉9 小时前
OpenHarmony(鸿蒙南向)——平台驱动开发【MIPI CSI】
harmonyos·领域驱动设计
别说我什么都不会9 小时前
鸿蒙轻内核M核源码分析系列十五 CPU使用率CPUP
操作系统·harmonyos
塞尔维亚大汉11 小时前
OpenHarmony(鸿蒙南向)——平台驱动开发【I3C】
harmonyos·领域驱动设计
今阳13 小时前
鸿蒙开发笔记-6-装饰器之@Require装饰器,@Reusable装饰器
android·app·harmonyos
余多多_zZ13 小时前
鸿蒙初学者学习手册(HarmonyOSNext_API14)_组件截图(@ohos.arkui.componentSnapshot (组件截图) )
学习·华为·harmonyos·鸿蒙·鸿蒙系统
一个处女座的程序猿O(∩_∩)O15 小时前
鸿蒙开发技术指南:从入门到精通
华为·harmonyos
陈无左耳、17 小时前
HarmonyOS学习第4天: DevEco Studio初体验
学习·华为·harmonyos
月未央19 小时前
HarmonyOS Next 开发系列:Local 状态管理实践
harmonyos
openinstall全渠道统计1 天前
免填邀请码工具:赋能六大核心场景,重构App增长新模型
android·ios·harmonyos