您的位置:首页 > 文旅 > 旅游 > 鸿蒙验证码,鸿蒙认证服务验证码,鸿蒙云存储上传图片

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

2024/10/6 14:34:02 来源:https://blog.csdn.net/jian11058/article/details/141501908  浏览:    关键词:鸿蒙验证码,鸿蒙认证服务验证码,鸿蒙云存储上传图片

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)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com