In order to use our API, you need to get your x-auth-key and x-client-id first.
How to get x-client-id and x-auth-key
You can access API Keys to copy x-client-id and x-auth-key.
Do not show your x-auth-key to anyone else. If someone gains the access ot your x-auth-key, they can use your account as if they had your password. You can click on the Reset button to get a new one and invalidate the old one for security reasons.
Authentication
Generate a signature based on HMAC-SHA256 algorithm through the x-auth-key and x-client-id to ensure the integrity and security of the request. The request body and a timestamp can be signed to prevent replay attacks.
importcom.alibaba.fastjson2.JSONObject;importcom.alibaba.fastjson2.JSON;importcom.alibaba.fastjson2.TypeReference;importjava.util.Map;importjava.util.SortedMap;importjava.util.TreeMap;publicclassJsonSorterUtils { /** * Converts the object into a sorted, compact JSON string。 * * @param obj The object to be converted * @return A compact sorted JSON string */publicstaticStringobjectToJsonSorted(Object obj) { Map<String, Object> map = JSON.parseObject(JSON.toJSONString(obj), new TypeReference<Map<String, Object>>() {});
returnJSON.toJSONString(sortMap(map)); } /** * Sort the Map and recursively sort the Jsonobjects in it * * @param map Map that needs to be sorted * @return The sorted Map */privatestaticMap<String,Object> sortMap(Map<String,Object> map) {if (map ==null) returnnull;// Sort the external fields using TreeMapSortedMap<String,Object> sortedMap =newTreeMap<>(map);// Iterate through the Map and sort each JSONObject recursivelyfor (Map.Entry<String,Object> entry :sortedMap.entrySet()) {if (entry.getValue() instanceof JSONObject) {// If it is JSONObject, it is converted to Map before sortingMap<String,Object> nestedMap =JSON.parseObject(entry.getValue().toString(),newTypeReference<Map<String,Object>>() {});entry.setValue(sortMap(nestedMap)); } elseif (entry.getValue() instanceof Map) {// If it is a Map, it is sorted recursivelyentry.setValue(sortMap((Map<String, Object>) entry.getValue())); } }return sortedMap; }}