📗
EN
  • GPU Container Cloud Rental Manual
  • Computing Services Provided by EMC Hub
  • GPU Virtual Host Rental Steps
  • GPU Container Cloud Service Rental Steps
  • API Call Example Code
Powered by GitBook
On this page

API Call Example Code

Below is a Java example code to call the deployed txt2img API:

import java.security.MessageDigest;

/**
 * @description: GenSignDemo
 * @time: 2022-09-23 15:47
 */
public class GenSignDemo {

    public static void main(String[] args) {
        String appid = "YOURAPPID";
        String nonce = "1226202735";
        String action = "walletCreate";
        String requestBody = "{\"phone\":\"18155925293\",\"wallet_type\":0}";
        String first = "appid=" + appid + "&nonce=" + nonce + "&action=" + action 
            + "&requestBody=" + requestBody;
        String secret = "ef149163-276e-11ed-8589-b8599f24f354";
        String tempSignStr = first + "&secret=" + secret;
        String encodeSign = MDEncode(tempSignStr, "UTF-8", "SHA1");
        System.out.println(encodeSign);
    }

    public static String MDEncode(String origin, String charsetname, String mdname) {
        String resultString = null;
        try {
            resultString = new String(origin);
            MessageDigest md = MessageDigest.getInstance(mdname);
            if (charsetname == null || "".equals(charsetname))
                resultString = byteArrayToHexString(md.digest(resultString
                    .getBytes()));
            else
                resultString = byteArrayToHexString(md.digest(resultString
                    .getBytes(charsetname)));
        } catch (Exception exception) {
        }
        return resultString;
    }

    private static String byteArrayToHexString(byte[] b) {
        StringBuffer resultSb = new StringBuffer();
        for (int i = 0; i < b.length; i++)
            resultSb.append(byteToHexString(b[i]));
        return resultSb.toString();
    }

    private static String byteToHexString(byte b) {
        int n = b;
        if (n < 0)
            n += 256;
        int d1 = n / 16;
        int d2 = n % 16;
        return hexDigits[d1] + hexDigits[d2];
    }

    private static final String[] hexDigits = { "0", "1", "2", "3", "4", "5", 
        "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
}
PreviousGPU Container Cloud Service Rental Steps

Last updated 10 months ago