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

C++

#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <ctime>
#include <sstream>
#include <openssl/md5.h>

std::string generateSign(std::map<std::string, std::string> params, std::string secretKey) {
  std::time_t timestamp = std::time(nullptr);
  params["timestamp"] = std::to_string(timestamp);
  std::stringstream ss;
  for (auto const& [key, val] : params) {
    ss << key << "=" << val << "&";
  }
  ss << secretKey;
  std::string signStr = ss.str();
  unsigned char md5Result[MD5_DIGEST_LENGTH];
  MD5((unsigned char*)signStr.c_str(), signStr.length(), md5Result);
  std::stringstream signSs;
  for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
    signSs << std::hex << std::setw(2) << std::setfill('0') << (int)md5Result[i];
  }
  return signSs.str();
}++

In this implementation, the generateSign function takes two parameters: the object parameter params and the secret key secretKey. The function first generates a timestamp and adds it to the sorted object parameter. It then concatenates the name-value pairs with the secret key and generates the md5 hash of the resulting string. The function returns the md5 hash as the sign.

PreviousJavaNextSDK DEMO

Last updated 1 year ago