checkDeviceToken返回的错误码有以下几种:
错误码 | 描述 |
|---|---|
OK | 请求处理成功。 |
InvalidDeviceToken | deviceToken缺失或不合法。 |
DeviceTokenExpired | deviceToken过期。 |
InvalidTimeStamp | timeStamp缺失或不合法。 |
InternalServerError | 服务器内部错误。 |
InvalidBundleName | bundleName缺失或不合法。 |
针对deviceToken缺失或者不合法问题,要从deviceToken生成和请求发送过程进行分析。
import { deviceCertificate } from '@kit.DeviceSecurityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG = "DeviceCertificateJsTest"; @Entry @Component struct Index { private message: string = '获取设备Token'; build() { RelativeContainer() { Text(this.message) .id('getDeviceToken') .fontSize($r('app.float.page_text_font_size')) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }) .onClick(() => { this.getDeviceToken(); }) } .height('100%') .width('100%') } /** * 获取设备的token * @returns */ getDeviceToken(): string { let res = ""; try { deviceCertificate.getDeviceToken().then((token) => { hilog.info(0x0000, TAG, 'Succeeded in executing getDeviceToken'); console.info('token:' + token); }).catch((err: BusinessError) => { hilog.error(0x0000, TAG, 'getDeviceToken failed! %{public}d %{public}s', err.code, err.message); }); } catch (err) { let error: BusinessError = err as BusinessError; hilog.error(0x0000, TAG, 'getDeviceToken failed! %{public}d %{public}s', error.code, error.message); } return res; } }