User Penalties

一、 User penalty callback API

  • Callback URL:

Fill in the “Console - Service Configuration - User Penalties - Callback URL”.

  • HTTP request Header:
Header Value Required Descriptio
Content-Type application/json;charset=UTF-8 Required Request body type
Accept application/json;charset=UTF-8 Required Return type accepted
X-AppId Required The only identifier of the project or application.
X-TimeStamp Required The UTC timestamp of the request. Timestamps need to be formatted according to W3C standards, for example: 2010-01-31T23:59:59Z. (http://www.w3.org/TR/xmlschema-2/#dateTime).
Authorization Required Signature value
  • Request method:POST

  • Request body JSON object:

Parameter Required Type Description
appId Required String Project Number
userId Required String User ID
type Required String Method of punishment(mute:Mute,ban_account:Ban Account)
hours Required String Length of punishment(permanent:Permanent,{n}:{n} hours)
category Required String Reason for punishment(sensitive:Sensitive Words,advertising:Advertising Words)
  • Example of request body:
  {
    "appId": "80700001", //Project Number
    "userId": "usertest", //User ID
    "type": "mute", //Method of punishment
    "hours": "24", //Length of punishment (24 hours)
    "category": "advertising", //Reason for punishment
  }     
  • Request Header to send a signature via HTTP

Method: Add a header named Authorization in the request, whose value is the signature value. For example:

 Authorization: ****
  • Signature calculation method
  1. Canonicalized Query String:

Convert the request body JSON string to a hexadecimal string (not Base64) by doing sha256 encoding with UTF-8 character encoding.

CanonicalizedQueryString = hex(sha256(jsonBody))

  1. Constructs the signed string StringToSign ("\n" stands for ASCII newline character):
  StringToSign = HTTPMethod + "\n" +
                  CallbackUrl + "\n" +
                  CanonicalizedQueryString <get from previous> + "\n" +
                  "X-AppId:" + SAME_APPID_IN_HEADER + "\n" +
                  "X-TimeStamp:" + SAME_TIMESTAMP_IN_HEADER

HTTPMethod: POST

CallbackUrl: This value in the < Console - Service Configuration - User Penalties - Callback URL >.

The hash-based message authentication code (HMAC) is created using the HMAC-SHA256 protocol and the signature is calculated.

  1. StringToSign as the signature string, secretKey as the secret key and SHA256 as the hash algorithm.

    For more information about HMAC, see: https://tools.ietf.org/html/rfc2104.
    
  2. Converting the results of the previous step to a BASE64 string

  3. Put the BASE64 string into the Authorization of HTTP request Header