UMIVERSE SDK
  • UMIVERSE SDK Doc
    • Overview
    • Configure Secret Key and API Domain
    • Sync Account
      • OAuth login
        • Preparations for OAuth
        • Use Authorization_Code to get UMI_UID
        • Decrypt Authorization Code
          • AES Decrypt
    • Dive Points
      • Increase DivePoint
        • API
      • Mission System
        • Request task panel view in H5 game
    • Game Recharge
      • Initiate Recharge Request
      • Handle Recharge Completion
  • Signature
    • Typescript
    • PHP
    • Java
    • C++
  • SDK DEMO
  • Legacy
    • API Key/Secret
    • SignUp & SignIn
    • Get UMI UID
    • Authentication
    • Umiverse Features
      • Mint
      • Send a server-generated item to Umi account
      • Get all items that the player can put up for sale
      • Send an item to a player
      • Deduct an item from a player
    • Redirect
  • Developer Console
    • Add Game Information
Powered by GitBook
On this page
  1. Signature

Java

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.TreeMap;

public class SignGenerator {
    public static String generateSign(Map<String, String> params, String secretKey) throws NoSuchAlgorithmException {
        long timestamp = System.currentTimeMillis() / 1000L;
        Map<String, String> sortedParams = new TreeMap<>(params);
        sortedParams.put("timestamp", Long.toString(timestamp));
        StringBuilder signStr = new StringBuilder();
        for (Map.Entry<String, String> entry : sortedParams.entrySet()) {
            signStr.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
        }
        signStr.append(secretKey);
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digest = md.digest(signStr.toString().getBytes());
        StringBuilder sign = new StringBuilder();
        for (byte b : digest) {
            sign.append(String.format("%02x", b & 0xff));
        }
        return sign.toString();
    }
}

In this implementation, the generateSign function takes a Map of parameters and a String secret key as input. It generates a timestamp using System.currentTimeMillis(), sorts the parameters using a TreeMap, and adds the timestamp to the sorted parameters. It then concatenates the sorted parameters and the secret key into a string, computes the MD5 hash of the resulting string, and returns the hash as a string.

PreviousPHPNextC++

Last updated 1 year ago