Authentication API

The Authentication API is used to handle player authentication and session management. This includes generating signatures to authenticate the legitimacy of requests. Below are examples of how to generate signatures using different programming languages:

Java Code

StringBuilder siginStrbuild = new StringBuilder();
siginStrbuild.append(appId);
siginStrbuild.append("|");
siginStrbuild.append(nonce);
siginStrbuild.append("|");
siginStrbuild.append(timestamp);
siginStrbuild.append("|");
siginStrbuild.append(signType);
HMac mac = new HMac(HmacAlgorithm.HmacMD5, slat.getBytes());

Node.js Code

const crypto = require('crypto');

function generateSignature(appId, nonce, timestamp, signType, salt) {
    const signStr = `${appId}|${nonce}|${timestamp}|${signType}`;
    return crypto.createHmac('md5', salt).update(signStr).digest('hex');
}

Python Code

import hmac
import hashlib

def generate_signature(appId, nonce, timestamp, signType, salt):
    sign_str = f"{appId}|{nonce}|{timestamp}|{signType}"
    return hmac.new(salt.encode(), sign_str.encode(), hashlib.md5).hexdigest()

new(salt.encode(), sign_str.encode(), hashlib.md5).hexdigest()

These functions combine appId, nonce, timestamp, and signType with HMAC-MD5 encryption using the specified key (salt) to generate a signature for the request.

Last updated