当前位置: 首页> 游戏> 攻略 > 独立建站平台_2022年免费网站软件下载_东莞网站建设优化排名_网站seo在线诊断

独立建站平台_2022年免费网站软件下载_东莞网站建设优化排名_网站seo在线诊断

时间:2025/7/15 4:21:01来源:https://blog.csdn.net/jingbin_/article/details/143205266 浏览次数:0次
独立建站平台_2022年免费网站软件下载_东莞网站建设优化排名_网站seo在线诊断

这三个月一直在进行鸿蒙原生开发,已经在应用市场发了App和元服务,期间陆续整理了一些笔记,现发布出来,也可以留言探讨。

下载三方包

下载三方包,需要配置 ohpm。前提是安装nodejs,去nodejs官网下载后配置PATH。然后再下载ohpm工具包,进行初始化后,再进行配置。

不过最新的编辑器好像直接自带了nodejs

users/michelle 资料库(Library)里有Huawei onpm。 /Users/michelle/Library/Huawei/ohpm

就是说要下载2个包:nodejs和ohpm,然后初始化./init后,再配置到环境变量里。文档:ohpm使用指导

interface 回调使用

interface写法变了

export interface OnCallBack<T = object> {// 这里不一样,不是这样:onSuccess(bean: T): void;onSuccess: (bean: T) => void;onError: (error: AxiosError) => void;
}

使用:

public static searchPageData(o: string, callBack: OnCallBack<BaseResultBean<SearchBean>>) {HttpUtil.getInstance().post<null, AxiosResponse<BaseResultBean<SearchBean>>, HomeBean>("/xx/xx", {o: o}).then((res: AxiosResponse<BaseResultBean<SearchBean>>) => {callBack?.onSuccess(res.data)console.error("1222------" + res.data.result!!.searchGoods)// if (res.data.result != null) {// }}).catch((error: AxiosError) => {callBack?.onError(error)console.log(JSON.stringify(error))})}
}

引用:

 HttpUtil.searchPageData("harmonyos", {onSuccess: (bean: BaseResultBean<SearchBean>): void => {if (bean.result != null) {this.message = bean.result}},onError: (error: AxiosError): void => {console.log('error:' + error.message);}})

华为登录

最新的next版本,不能获取到手机号。
不能获取手机号

  • 需要用真机;
  • 签名不用自动签名;Failed to login. Code: 1001500001, message: Failed to check the fingerprint of the app bundle.Fingerprint verification error.

Authorization Code。临时凭据,有效时间5分钟,并且只能使用一次

module.json5里加:

"metadata": [{"name": "client_id","value": "775544333"  // 配置为获取的Client ID}
]

配置证书指纹(指纹配置成功后大约10分钟左右生效,请您耐心等待):

1.在module.json5 配置metadata --> client_id
2.AppGallery Connect平台 找到对应的项目,在里面配置“SHA256证书/公钥指纹”

需要注意包名要和开发的包名对应,client_id也是在这个应用取的

https://developer.huawei.com/consumer/cn/blog/topic/03147440682731014 获取公钥指纹步骤

(期间使用:hdc shell bm dump -n 包名 | findstr appIdfindstr错误,可以将findstr改为grep,即:hdc shell bm dump -n 包名 | grep appId

(hdc 需要配置环境变量,且只有在当前的命令窗口里有效)

最后登录:

huaweiLogin() {LogBevolUtil.error("---------start login")this.isShowLoading = true// 创建登录请求,并设置参数let loginRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest();// loginRequest.scopes = ['phone']; // 元服务不支持profile,需传其他支持的scope。配置openid的scope可以在响应中获取到openID、unionID// loginRequest.scopes = ['quickLoginAnonymousPhone','openid']; // 元服务不支持profile,需传其他支持的scope。配置openid的scope可以在响应中获取到openID、unionIDloginRequest.scopes = ['openid', "profile"]; // 元服务不支持profile,需传其他支持的scope。配置openid的scope可以在响应中获取到openID、unionID// loginRequest.scopes = ["openid"]; // 元服务不支持profile,需传其他支持的scope。配置openid的scope可以在响应中获取到openID、unionID// loginRequest.permissions = ['serviceauthcode'];// loginRequest.permissions = ['quickLoginAnonymousPhone'];loginRequest.forceAuthorization = true;// false表示当用户未登录华为账号时,不会拉起华为账号登录界面;直接返回1001502001错误码。// loginRequest.forceLogin = false;// authRequest.state = util.generateRandomUUID(); // 应用建议使用generateRandomUUID生成stateloginRequest.state = 'xxx'; // 元服务自定义生成loginRequest.idTokenSignAlgorithm = authentication.IdTokenSignAlgorithm.PS256;// 执行登录请求,并处理结果try {let controller = new authentication.AuthenticationController(getContext(this));controller.executeRequest(loginRequest, (error: BusinessError<Object>, data) => {if (error) {this.dealAllError(error);return;}let loginWithHuaweiIDResponse = data as authentication.AuthorizationWithHuaweiIDResponse;let state = loginWithHuaweiIDResponse.state;if (state != undefined && loginRequest.state != state) {this.handleLoginFail()hilog.error(0x0000, 'testTag', `Failed to login. The state is different, response state: ${state}`);return;}hilog.info(0x0000, 'testTag', 'Succeeded in login. %{public}s', JSON.stringify(loginWithHuaweiIDResponse));let loginWithHuaweiIDCredential = loginWithHuaweiIDResponse.data!;let code = loginWithHuaweiIDCredential.authorizationCode;// 得到code请求接口登录let idToken = loginWithHuaweiIDCredential.idToken;let openID = loginWithHuaweiIDCredential.openID;let unionID = loginWithHuaweiIDCredential.unionID;// loginWithHuaweiIDResponse.data.let anonymousPhone = loginWithHuaweiIDCredential.extraInfo?.quickLoginAnonymousPhone;LogBevolUtil.error("----anonymousPhone:" + anonymousPhone)LogBevolUtil.error("----openID:" + openID)LogBevolUtil.error("----unionID:" + unionID)// if (anonymousPhone) {//   hilog.info(0x0000, 'testTag', 'Succeeded in authentication');//   // 将匿名手机号传给第3步使用//   return;// }// 开发者处理code, idToken, openID, unionID// Authorization Code。临时凭据,有效时间5分钟,并且只能使用一次。证书不能使用自动获取形式。// Logger.error("----code:" + code)if (!isEmpty(unionID) && !isEmpty(openID)) {this.login(unionID, openID, code)} else {this.handleLoginFail()}});} catch (error) {this.dealAllError(error);}}

延迟执行

// 延迟显示
setTimeout(() => {this.isShowFooterView = true
}, 200)

元服务发布后域名访问不通

将域名添加到后台

关键字:独立建站平台_2022年免费网站软件下载_东莞网站建设优化排名_网站seo在线诊断

版权声明:

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

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

责任编辑: