# Harmony_pay **Repository Path**: erictor_admin/Harmony_pay ## Basic Information - **Project Name**: Harmony_pay - **Description**: 文强支付案例 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-02-02 - **Last Updated**: 2024-03-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 个人理财项目案例 ## 1. 开通服务认证 AGC地址: [AppGallery Connect (huawei.com)](https://developer.huawei.com/consumer/cn/service/josp/agc/index.html#/) [HarmonyOS使用入门(ArkTS API9及以上)-HarmonyOS-使用入门 | 华为开发者联盟 (huawei.com)](https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/agc-get-started-harmony-arkts-0000001683915520) ![image-20240202105546426](./img/image-20240202105546426.png) ![image-20240202105732444](./img/image-20240202105732444.png) ![image-20240202105824285](./img/image-20240202105824285.png) ![image-20240202105933707](./img/image-20240202105933707.png) 下载文件放到下面路径 ![image-20240202110109403](./img/image-20240202110109403.png) 检查依赖 ![image-20240202110241131](./img/image-20240202110241131.png) ## 2. 邮箱认证 [邮箱-登录认证-ArkTS(API 9及以上)-HarmonyOS-认证服务 | 华为开发者联盟 (huawei.com)](https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/agc-auth-harmonyos-arkts-login-email-0000001679886157) ### 2.1 初始化,修改EntryAbility的onCreate以下内容 [集成SDK-ArkTS(API 9及以上)-HarmonyOS-认证服务 | 华为开发者联盟 (huawei.com)](https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/agc-auth-harmonyos-arkts-integration-0000001679766293) ``` import { initialize } from '@hw-agconnect/hmcore'; import util from '@ohos.util'; async onCreate(want, launchParam) { //初始化agconnect let input = await this.context.resourceManager.getRawFileContent('agconnect-services.json') let jsonString = util.TextDecoder.create('utf-8', { ignoreBOM: true }).decodeWithStream(input, { stream: false }); ``` ### 2.2.添加发送邮件方法 [邮箱-登录认证-ArkTS(API 9及以上)-HarmonyOS-认证服务 | 华为开发者联盟 (huawei.com)](https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/agc-auth-harmonyos-arkts-login-email-0000001679886157) ``` /* * 验证码部分 * */ import { Auth, VerifyCodeAction } from '@hw-agconnect/cloud'; import cloud from '@hw-agconnect/cloud'; @Component export default struct InputAuth { @State countDown: number = 60 @State email:string = 'gouwqiang@163.com' timer?: number //发送验证码 sendCode() { this.startCountDown() console.log('发送验证码。。。') //发送邮箱验证吗 cloud.auth().requestVerifyCode({ action: VerifyCodeAction.REGISTER_LOGIN, lang: 'zh_CN', sendInterval: 60, verifyCodeType: { email: this.email, kind: "email", } }).then(verifyCodeResult => { //验证码申请成功 console.log(JSON.stringify(verifyCodeResult),'成功了') }).catch(error => { //验证码申请失败 console.log(JSON.stringify(error),'错误') }); } //倒计时 startCountDown() { this.timer = setInterval(() => { this.countDown -= 1 if (this.countDown === 0) { this.countDown = 60 clearInterval(this.timer) } }, 1000) } build() { Column({ space: 10 }) { Text('验证码') .width('100%') .textAlign(TextAlign.Start) .fontSize(16) .fontWeight(500) .fontColor($r('app.color.font_color')) .margin({ bottom: 14 }) Row() { TextInput({ placeholder: '请输入验证码' }).width(170) Button(this.countDown == 60 ? '发送验证码' : `${this.countDown}s`) .onClick(() => { if (this.countDown === 60) { //倒计数过程不能点击 this.sendCode() } }) }.width('100%') .justifyContent(FlexAlign.SpaceBetween) }.margin({ top: 20 }) } } ``` ### 2.3 触发后去邮箱查看 ![image-20240204113544354](D:\code\Harmony\MyApp2\img\image-20240204113544354.png)