HarmonyOS

Integration Requirements

Environment Requirements

Description
Compatible VersionAPI 12 and above
Supported Architecturesarm64-v8a, x86_64

Integration Steps

Installation Configuration

Installation Instructions

ohpm install @trustdecision/apisign

Integrate the SDK

Set the third-party package dependency in the project's oh-package.json5 file. A configuration example is as follows:

 "dependencies": {
   "@trustdecision/apisign": "1.0.1"
  }

API Signature

Method Definition

public static sign(path: string): TDAPISignResult;

Structure Definition

export class TDAPISignResult {
  // Signature result
  signature: string
  // Signature status code
  code: number
  // Exception information
  message: string

  constructor(sign: string, code: number, msg: string) {
    this.signature = sign
    this.code = code
    this.message = msg
  }
}

Best Practices

An API to be protected is in the form: <https://sg.apitd.net/de/v1?name=jacky&age=12>

import { TDAPISign } from "@trustdecision/apisign"

const signResult = TDAPISign.sign('de/v1')
if (signResult.code === 0) {
  // Obtain the signature and use it
  const signature: string = signResult.signature
} else {
  // Obtain error information and status code
  const message: string = signResult.message
  const code: number = signResult.code
  // Continue with business logic; the signature can be replaced with an empty string here
}

Status Check

The signature is successful if the status code obtained from the returned structure is 0.

TDAPISignResult.code === 0

Status Codes

Error CodeError MessageHandling Method
0Success/
2000path is emptyPlease set the path parameter
22xxInternal errorPlease contact TD technical support
5001Failed to call the so file; the so file dependent on the SDK may be missingPlease check if the architecture of the current device is configured in the project