鸿蒙 HarmonyOS NEXT端云一体化开发-认证服务篇

一、开通认证服务

地址:AppGallery Connect (huawei.com)

步骤:
1 进入到项目设置页面中,并点击左侧菜单中的认证服务
2 选择需要开通的服务并开通

image.png

二、端侧项目环境配置

添加依赖
entry目录下的oh-package.json5
// 添加:主要前2个依赖
"dependencies": {
    "@hw-agconnect/cloud": "^1.0.0",
    "@hw-agconnect/hmcore": "^1.0.0",
    "@hw-agconnect/auth-component": "^1.0.0", // 可选
    "long": "5.2.1"
  }

开通网络权限
// 文件名:module.json5
// 路径:src/main/module.json5
  "requestPermissions": [
      {
        "name": "ohos.permission.INTERNET" // 网络权限
      },
    ]

更新agconnect-services.json文件
// AGC网站提示:下载最新的配置文件(如果您修改了项目、应用信息或者更改了某个开发服务设置,可能需要更新该文件)
为了确保项目不会出错,建立更新下该配置文件

三 认证组件界面示例

  1. 新建Login.ets页面,并设置成为应用首页

image.png

  1. Login.ets调用认证组件
import { AuthMode, Login } from '@hw-agconnect/auth-component';
import router from '@ohos.router';


@Entry
@Component
struct MyLogin {
  @State message: string = 'Hello World';

  build() {
   Column(){
     Text("test")
     // auth-component 中的组件Login
     Login({
       modes:[AuthMode.PHONE_VERIFY_CODE] // 手机验证码登录
       ,
       onSuccess:()=>{
         //登录成功后的回调
         router.pushUrl({url:'pages/Index'})
       }

     }){
       Button("登录").height(60).width("100%")
     }


   }.width("100%").height("100%")
  }
}

image.png
image.png

四、自定义登录组件

// 参考链接:https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/agc-auth-harmonyos-arkts-login-phone-0000001631566338

import cloud from '@hw-agconnect/cloud';
import { Auth, VerifyCodeAction } from '@hw-agconnect/cloud';

@Entry
@Component
struct PageTest {
  @State verificationBtnStr:string= "验证码"
  phone:string = ""
  @State verifcationBtnStatus:boolean = true
  @State timer :number = 0
  @State countDown:number = 60
  // 云端获取
  getCloudQrCode(){
    cloud.auth().requestVerifyCode({
      action: VerifyCodeAction.REGISTER_LOGIN,
      lang: 'zh_CN',
      sendInterval: 60,
      verifyCodeType: {
        phoneNumber: this.phone,
        countryCode: '86',
        kind: "phone"
      }
    }).then(verifyCodeResult => {
      //验证码申请成功
      console.log(JSON.stringify(verifyCodeResult))
      AlertDialog.show({
        title: "提示",
        message: "获取验证码成功",
      })
    }).catch((error: Promise<Result>) => {
      AlertDialog.show({
        title: "提示",
        message: "获取验证码失败",
      })
      //验证码申请失败
    });

  }
  // 初始化参数:
  initData(){
    clearInterval(this.timer)
    this.verifcationBtnStatus = true
    this.verificationBtnStr  = "验证码"
    this.countDown  = 60
  }
  // 发送验证码
  getCode(){
    if(this.phone==''){
      AlertDialog.show({
        title: "提示",
        message: "请输入手机号码",

      })
      return;
    }
    this.verifcationBtnStatus = false

    this.getCloudQrCode()


    this.timer  = setInterval(()=>{
      this.verificationBtnStr = `${this.countDown}s`
      if(this.countDown===0){
        this.initData()
        return;
      }

      this.countDown --

    },1000)
  }
  build() {
    Column({space:20}){
      TextInput({placeholder:'请输入手机号:'}).width("100%").height(60).margin({top:20})
        .onChange((value)=>{
          this.phone = value
        })
      Row(){
        TextInput({placeholder:"请输入验证码"}).layoutWeight(1).margin({right:20})
        Button(this.verificationBtnStr).width(120).onClick(()=>{
          this.getCode()

        }).enabled(this.verifcationBtnStatus)

      }.width("100%").height(60)
      Button("登录").width("100%").height(40).padding({
        left:50,right:50
      }).backgroundColor("#ff08be4b")
    }.width("100%").height("100%").padding({left:10,right:10})
  }
}
  1. 效果:

image.png

五、邮箱登录验证

import cloud from '@hw-agconnect/cloud';
import { Auth, VerifyCodeAction } from '@hw-agconnect/cloud';
import router from '@ohos.router';

@Entry
@Component
struct PageTest {
  @State verificationBtnStr:string= "验证码"
  @State phone:string = ""
  @State verifcationBtnStatus:boolean = true
  @State timer :number = 0
  @State countDown:number = 60
  @State data:string = ""
  @State verifCode:string = ""
  // 注销
  loginOut(){
    cloud.auth().signOut().then(() => {
      //登出成功
      AlertDialog.show({
        title: "提示",
        message: "注销用户成功",


      })
    }).catch(() => {
      //登出失败
    });
  }
  //登录
   login(){
   
    // 注册
     this.data = this.verifCode

     cloud.auth().signIn({
       credentialInfo: {
         kind: 'email',
         email: this.phone,
         verifyCode: this.verifCode
       }
     }).then(user => {
       //登录成功
       router.replaceUrl({url:'pages/Index'})
     }).catch((error:Promise<Result>) => {
       //登录失败
       this.data= JSON.stringify(error)
       AlertDialog.show({
         title: "提示",
         message: JSON.stringify(error),

       })
     });

  }
  // 云端获取
  getCloudQrCode(){
    cloud.auth().requestVerifyCode({
      action: VerifyCodeAction.REGISTER_LOGIN,
      lang: 'zh_CN',
      sendInterval: 60,
      verifyCodeType: {
        email: this.phone,
        kind: "email",
      }
    }).then(verifyCodeResult => {
      //验证码申请成功
      console.log(JSON.stringify(verifyCodeResult))
      this.data = JSON.stringify(verifyCodeResult)
      AlertDialog.show({
        title: "提示",
        message: "获取验证码成功",
      })
    }).catch((error: Promise<Result>) => {
      AlertDialog.show({
        title: "提示",
        message: "获取验证码失败",
      })
      //验证码申请失败
    });

  }
  // 初始化参数:
  initData(){
    clearInterval(this.timer)
    this.verifcationBtnStatus = true
    this.verificationBtnStr  = "验证码"
    this.countDown  = 60
  }
  // 发送验证码
  getCode(){
    if(this.phone==''){
      AlertDialog.show({
        title: "提示",
        message: "请输入用户邮箱",

      })
      return;
    }
    this.verifcationBtnStatus = false

    this.getCloudQrCode()


    this.timer  = setInterval(()=>{
      this.verificationBtnStr = `${this.countDown}s`
      if(this.countDown===0){
        this.initData()
        return;
      }

      this.countDown --

    },1000)
  }
  build() {
    Column({space:20}){
      TextInput({placeholder:'请输入手机号:'}).width("100%").height(60).margin({top:20})
        .onChange((value)=>{
          this.phone = value
        })
      Row(){
        TextInput({placeholder:"请输入验证码"}).layoutWeight(1).margin({right:20})
          .onChange((value)=>{
            this.verifCode =value
          })
        Button(this.verificationBtnStr).width(120).onClick(()=>{
          this.getCode()

        }).enabled(this.verifcationBtnStatus)

      }.width("100%").height(60)
      Button("登录").onClick( ()=>{
        this.data = "1aaaaaa"
        this.login()

      }).width("100%").height(40).padding({
        left:50,right:50
      }).backgroundColor("#ff08be4b")

      Button("注销").onClick( ()=>{
        this.data = "1aaaaaa"
        this.loginOut()

      }).width("100%").height(40).padding({
        left:50,right:50
      }).backgroundColor("#ff08be4b")


      Text(this.data).width("100%").height(200).backgroundColor(Color.Pink)
    }.width("100%").height("100%").padding({left:10,right:10})
  }
}
  • 获取验证码

image.png
image.png

  • 登录

image.png

// 提示用户已经登录过了,需要登出后才能重新登录
// 重而需要调用注销按钮中的登出方法
   cloud.auth().signOut()

image.png

  • 点击注销按钮

image.png

  • 点击登录后,跳转到Index页面中

image.png

<think>好的,我现在需要解决用户在鸿蒙系统2.0中查找/system/bin/目录下被移除或改名命令的新位置的问题。首先,我应该回忆一下鸿蒙系统的基本架构,尤其是文件系统的结构。鸿蒙系统基于微内核设计,可能对传统的Linux目录结构有所调整。用户提到的是/system/bin/目录,这在传统的Android系统中确实存在,但鸿蒙可能进行了优化或重组。 接下来,我需要考虑鸿蒙系统中可能替代传统命令的位置。通常,系统命令可能被移动到其他标准目录,比如/bin或/usr/bin,或者整合到其他子系统中。另外,鸿蒙可能引入了新的工具或命令来替代旧有的功能,比如使用hdc(HarmonyOS Device Connector)替代adb。 然后,我应该查阅官方文档或可靠的资料,确认鸿蒙2.0的具体变化。例如,华为开发者文档可能提到目录结构的调整,或者命令的迁移情况。此外,用户提到的rmdir命令在引用中出现过,但这里需要关注的是/system/bin下的其他命令是否被移动。 还需要考虑用户如何在实际设备上查找这些命令。建议使用命令行工具连接设备,通过find或which命令搜索特定的命令名称,或者检查环境变量PATH中的目录。另外,鸿蒙系统的权限管理可能更严格,某些命令可能只有特定权限才能访问,或者被封装在系统应用中。 最后,生成相关问题时要围绕鸿蒙系统目录结构、命令变更、替代工具以及调试方法等方面,帮助用户进一步理解系统的调整和如何进行问题排查。</think>针对鸿蒙系统2.0中/system/bin目录命令变更的说明: 1. **目录结构调整** 鸿蒙2.0对系统目录进行了优化重组,部分传统Linux命令已迁移到新位置: - `/system/bin` 中部分基础命令移至 `/bin` 或 `/usr/bin` - 专用工具整合到 `/system/hdc`(鸿蒙设备连接工具)和 `/system/hmcore`(系统核心组件) 2. **典型命令变更示例** | 原命令路径 | 新路径/替代方案 | 功能变化 | |--------------------|-----------------------------|----------------------------| | /system/bin/adb | /system/hdc | 强化设备调试功能[^1] | | /system/bin/rmdir | /bin/rmdir (保留但功能受限) | 需配合`hmfs -d`实现深度删除 | | /system/bin/ifconfig | /system/netcfg | 新增网络状态可视化功能 | 3. **查询方法** (1) 通过hdc连接设备后执行: ```shell hdc shell find / -name [命令名] ``` (2) 检查新版环境变量: ```shell echo $PATH ``` 输出示例:`/bin:/sbin:/system/bin:/system/hdc:/vendor/bin` 4. **特殊注意事项** - 部分命令如`telnetd`已移除,需通过`hdc tmode`进入开发者模式 - 文件操作命令改用`hmfs`工具集: ```shell hmfs copy /old/path /new/path ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

VarYa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值