Installation Instructions
ohpm install @trustdecision/apisignIntegrate 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"
}public static sign(path: string): TDAPISignResult;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
}
}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
}The signature is successful if the status code obtained from the returned structure is 0.
TDAPISignResult.code === 0