Exchange access key
You can obtain an Access Key by using your secretId and SecretKey. The Access Key expires after 7 days. If the Access Key expires, please retrieve it again. Otherwise, all API calls will return a 401 error. If you are unsure how to obtain your secretId and SecretKey, please log in to the Thinla Affiliate Website.
Take care
Do not disclose your SecretKey to unauthorized individuals, as it may lead to unintended losses.
/api/affiliate/auth/access/key
Method: POST
Post data
{
"secretId": "string",
"signature": "string",
"timestamp": 0
}
- secretId The field is coming from Thinla Affiliate Website
- timestamp The field is the current Unix Timestamp, consisting of a 13-digit number.
Take care
The timestamp should not deviate from the current timestamp on the Thinla Affiliate API server by more than one hour. Otherwise, an error message stating "timestamp is not the current timestamp" will be thrown.
- signature The signature field is generated by signing the timestamp with the secretKey and then encoding it in Base64. The secretKey is the private key generated by RSA. Below is an example of the code:
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
private PrivateKey getPrivateKeyFromString(String keyString) throws NoSuchAlgorithmException, InvalidKeySpecException {
// Remove the BEGIN and END lines, and any line breaks or whitespace
String privateKeyPEM = keyString
.replace("-----BEGIN PRIVATE KEY-----", "")
.replace("-----END PRIVATE KEY-----", "")
.replaceAll("\\s+", "");
// Base64 decode the data
byte[] encoded = Base64.getDecoder().decode(privateKeyPEM);
// Generate the private key object from the decoded data
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
return keyFactory.generatePrivate(keySpec);
}
public String sign(String privateKeyString, String dataToSign) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, InvalidKeySpecException {
// Create a private key object from the private key string
PrivateKey privateKey = getPrivateKeyFromString(privateKeyString);
// Create a signature object for signing data using SHA256 with RSA
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initSign(privateKey);
// Update the data to be signed
signature.update(dataToSign.getBytes());
// Generate the signature
byte[] signedData = signature.sign();
// Convert the signature to base64 for easy printing
String base64Signature = Base64.getEncoder().encodeToString(signedData);
System.out.println("Signature: " + base64Signature);
return base64Signature;
}
Long currentTimestamp = Calendar.getInstance().getTimeInMillis();
String signature = sign(secretKey, currentTimestamp.toString())
Response
{
"data": "string",
"message": "string",
"params": [
{}
],
"requestId": "string",
"status": 0
}