当前位置: 首页 > news >正文

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

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')){// cloudcloud.auth().requestVerifyCode({action:VerifyCodeAction.REGISTER_LOGIN,//注册登录lang:'zh_CN',sendInterval:60,//多少秒发一次verifyCodeType:{phoneNumber:'17610176666',countryCode:'86',//中国手机号前面+86kind:'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)


http://www.mrgr.cn/news/12261.html

相关文章:

  • 华裔二、三代长相变迁的多维度解析
  • 利用深度学习技术来实现街景图像的语义分割(街景图像语义分割)
  • 如何使用 Nginx 解决跨域问题 (CORS)
  • uni-app - - - - - 自定义tabbar
  • 使用 OpenCV 组合和缩放多张图像
  • DDPM/DDIM去噪扩散概率模型和GANs
  • 查看redis节点的连接数
  • 多态(c++)
  • pytorch深度学习基础 8(CIFRA-10基础篇1)
  • 常用的 Redis 配置命令
  • 述FunsorFunsor是一个类似张量的函数和分布库。概率规划的泛函张量获取系统描述 ppl,pyro的衍生项目,人工智能python编程 ,深度神经网络
  • MyBatis之注解使用
  • 九、枚举和注解
  • npm install报错,解决记录:11个步骤诊断和解决问题
  • PowerShell | git log 中文乱码问题解决
  • Python实现t-分布随机邻域嵌入(t-SNE)降维算法
  • 使用Oracle的PL/SQL编写自定义函数来实现split
  • Java线程池
  • 阿里云创建的SpringBoot项目打包时找不到主清单属性
  • 《重生到现代之从零开始的C语言生活》—— 指针6