Description

Feitian Integrity Intelligent IoT Platform provides HTTPSRest interface to the outside, and all requests adopt POST method. The encoding method is UTF-8, and the message body parameters and return results are in JSON format .

Note: You need to obtain Appkey and Appsecret before using the API. Appkey is used to identify the accessed application, and AppSecret is used to sign the transmission message when transmitting data.

Message signature description:

tep 1: The non-empty parameters in each interface are sorted according to the ascii code of the parameter name from small to large, and the URL key-value pair format is used to concatenate the string to be signed, namely

key1=value1&key2=value2&key3=value3

Spliced into strings.

Suppose the parameters sent are:

{ appkey : 9A0A8659F005D6984697E2CA0A9CF3B7, timestamp :20181221162001, nonce : dpRxkhjbauiclpKoqt }

Data to be signed appkey=9A0A8659F005D6984697E2CA0A9CF3B7&nonce=dpRxkhjbauiclpKoqt×tamp=20181221162001

Step 2: Use apisecret as the signature key to sign A and get the signature result B

B=HmacSHA256(A, appsecret);

Step 3: Add B to the parameter list, and get the final data sent as:

{ appkey : 9A0A8659F005D6984697E2CA0A9CF3B7, timestamp :20181221162001, nonce : dpRxkhjbauiclpKoqt, sign:Base64(B) }

Signature example:

														  
												
												import java.io.BufferedReader;
												import java.io.InputStream;
												import java.io.InputStreamReader;
												import java.io.OutputStream;
												import java.net.HttpURLConnection;
												import java.net.URL;
												import java.security.MessageDigest;
												import java.security.SecureRandom;
												import java.text.SimpleDateFormat;
												import java.util.Arrays;
												import java.util.Base64;
												import java.util.Date;
												import java.util.HashMap;
												import java.util.Map;
												import java.util.Random;
												import java.util.Set;
												import javax.crypto.Mac;
												import javax.crypto.spec.SecretKeySpec;


												import com.alibaba.fastjson.JSON;
													
													
													
															                                                      
												public static void main(String[] args) {
													try{
														String appsecert = "<Your appsecret>";          							//Application appsecret
														Map<String,Object> data = new HashMap<String,Object>();					//The data to be signed, please refer to the signature generation process to generate
														String sign = generateSignature(data, appsecert, "HMAC-SHA256");        //Generate data signature
														}catch(Exception e){
															e.printStackTrace();
														}
												   }
												 
												 
												public static String generateSignature(final Map<String,Object> data, String appsecret, String signType) // Generate data signature
													throws Exception {
													Set keySet = data.keySet();
													String[] keyArray = (String[]) keySet.toArray(new String[keySet.size()]);
													Arrays.sort(keyArray);
													StringBuilder sb = new StringBuilder();
													for (String k : keyArray) {
														if (k.equals("sign")) {
															continue;
														}

														if (data.get(k) == null || "null".equals(data.get(k))) { 				// If the parameter value is empty, it will not participate in the signature
															data.remove(k);
															continue;
														}

														Object value = data.get(k);
														if (value instanceof Integer) {
															value = sb.append(k).append("=").append(value).append("&");
														} else {
															if (String.valueOf(value).trim().length() > 0) {
																sb.append(k).append("=").append(String.valueOf(value).trim()).append("&");
															}
														}
													}
													String sbr = sb.substring(0, sb.length() - 1);
													if ("MD5".equals(signType)) {
														java.security.MessageDigest md = MessageDigest.getInstance("MD5");
														byte[] array = md.digest(sbr.getBytes("UTF-8"));
														return Base64.getUrlEncoder().encodeToString(array);					// Hexadecimal base64 form
													} else if ("HMAC-SHA256".equals(signType)) {
														Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
														SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes("UTF-8"), "HmacSHA256");
														sha256_HMAC.init(secret_key);
														byte[] array = sha256_HMAC.doFinal(sbr.getBytes("UTF-8"));
														return Base64.getUrlEncoder().encodeToString(array); 					// Hexadecimal base64 form
													}
													return null;
												}
														  
														

Manual

Step 1: Create my application

In order to run the development environment normally, you need to create an application and obtain the corresponding [application ID], [App security key] and [Message service address], the specific steps are as follows:

1.Click to enter Feitian Intelligent IOT platform login page, log in to Feitian Intelligent IOT platform.

2.In the list on the left side of the management platform, click [Add Application] to jump to the add application interface to add an application.

3.Enter [application name], application Descp (optional), click the [Save] button, the page jumps to the application list to view the newly added application’s [application ID] [App security key] [Message service address] and other key information , These parameters are needed during API initialization.

Step 2: Integrate the interfaces you need

After the application is added, you can integrate the interface according to your business needs, please refer to the detailed introduction of RESTful interface.

Device binding

Request address:https://serverurl/v1/audio/

Interface function: bind the terminal device and the merchant's QR code plate. Upload the device number and QR code plate identification to the message service platform. After the verification is passed, bind the device and code plate.

parameter name Parameter Description Is the value required
appkey Application appkey Yes
method Requested interface name,bindDevice Yes
devicesn device ID Yes
paycode Code plate number (the content of the QR code of the receipt code) Yes
timestamp Timestamp, format yyyyMMddHHmmss Yes
nonce Random string generated on the client side. No more than 32 bits in length Yes
sign The signature of the request parameter Base64(HmacSHA256(parameter to be signed, appsecret)) The method of generating the character string to be signed is detailed in "Message Signature Instructions" Yes
parameter name Parameter Description
code Return response code
msg Result description
nonce The nonce when requested, bring it back as it is
sign Signature of response data Base64 (HmacSHA256 (parameter to be signed, appsecret)) The generation rules of the parameters to be signed are the same as the generation rules of the request signature
														  
															
														import java.io.BufferedReader;
														import java.io.InputStream;
														import java.io.InputStreamReader;
														import java.io.OutputStream;
														import java.net.HttpURLConnection;
														import java.net.URL;
														import java.security.MessageDigest;
														import java.security.SecureRandom;
														import java.text.SimpleDateFormat;
														import java.util.Arrays;
														import java.util.Base64;
														import java.util.Date;
														import java.util.HashMap;
														import java.util.Map;
														import java.util.Random;
														import java.util.Set;
														import javax.crypto.Mac;
														import javax.crypto.spec.SecretKeySpec;
														
														
														import com.alibaba.fastjson.JSON;
																
																
																
															                                                   
														public static void main(String[] args) {
															try {
																String serverUrl = "<Your serverUrl>";
																String appkey = "<Your appkey>";
																String appsecret = "<Your appsecret>";
																String method = "<Requested interface name>";
																String devicesn = "<Your device number>";
																String paycode = "<Your payment code>";
																SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
																String timestamp = dateFormat.format(new Date());						// Timestamp
																char[] nonceChars = new char[32];
																final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
																final Random RANDOM = new SecureRandom();
																for (int index = 0; index > nonceChars.length; ++index) {
																	nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
																}
																String none = new String(nonceChars); 									// Get random string
																Map<String,Object> param = new HashMap<String,Object>();
																param.put("appkey", appkey); 											// Setting parameters
																.....;
																String sign = generateSignature(param, appsecret, "HMAC-SHA256");		// Please refer to the signature sample generation
																param.put("sign", sign);
																String response = httpRequest(serverUrl, "POST", JSON.toJSONString(param));
																System.out.println(response);											// Return result
															} catch (Exception e) {
																e.printStackTrace();
															}
														}
														  
														 public static String generateSignature(final Map<String,Object> data, String appsecret, String signType) // Generate data signature
															throws Exception {
																Set keySet = data.keySet();
																String[] keyArray = (String[]) keySet.toArray(new String[keySet.size()]);
																Arrays.sort(keyArray);
																StringBuilder sb = new StringBuilder();
																for (String k : keyArray) {
																	if (k.equals("sign")) {
																		continue;
																	}
															 
																	if (data.get(k) == null || "null".equals(data.get(k))) { 				// If the parameter value is empty, it will not participate in the signature
																		data.remove(k);
																		continue;
																	}
															 
																	Object value = data.get(k);
																	if (value instanceof Integer) {
																		value = sb.append(k).append("=").append(value).append("&");
																	} else {
																		if (String.valueOf(value).trim().length() > 0) {
																			sb.append(k).append("=").append(String.valueOf(value).trim()).append("&");
																		}
																	}
																}
																String sbr = sb.substring(0, sb.length() - 1);
																if ("MD5".equals(signType)) {
																	java.security.MessageDigest md = MessageDigest.getInstance("MD5");
																	byte[] array = md.digest(sbr.getBytes("UTF-8"));
																	return Base64.getUrlEncoder().encodeToString(array);					// Hexadecimal base64 form
																} else if ("HMAC-SHA256".equals(signType)) {
																	Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
																	SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes("UTF-8"), "HmacSHA256");
																	sha256_HMAC.init(secret_key);
																	byte[] array = sha256_HMAC.doFinal(sbr.getBytes("UTF-8"));
																	return Base64.getUrlEncoder().encodeToString(array); 					// Hexadecimal base64 form
																}
																return null;
														 }
																											 
														public static String httpRequest(String requestUrl, String requestMethod, String outputStr) // Send request method
															throws Exception {
																StringBuffer buffer = new StringBuffer();
																HttpURLConnection httpUrlConn = null;
																try {
																	URL url = new URL(requestUrl);
																	httpUrlConn = (HttpURLConnection) url.openConnection();

																	httpUrlConn.setDoOutput(true);
																	httpUrlConn.setDoInput(true);
																	httpUrlConn.setUseCaches(false);
																	httpUrlConn.setConnectTimeout(30000);
																	httpUrlConn.setReadTimeout(60000);
																	httpUrlConn.setRequestProperty("Content-type", "application/json");

																	httpUrlConn.setRequestMethod(requestMethod);								// Set the request method (GET/POST)

																	if ("GET".equalsIgnoreCase(requestMethod)) {
																		httpUrlConn.connect();
																	}

																	if (null != outputStr && outputStr.length() > 0) {							// When there is data to submit
																		OutputStream outputStream = null;
																		try {
																			outputStream = httpUrlConn.getOutputStream();
																			outputStream.write(outputStr.getBytes("UTF-8"));					// Pay attention to the encoding format to prevent Chinese garbled characters
																		} finally {
																			if (outputStream != null) {
																				outputStream.close();
																				outputStream = null;
																			}
																		}
																	}

																	InputStream inputStream = null;
																	InputStreamReader inputStreamReader = null;
																	BufferedReader bufferedReader = null;
																	try {
																		inputStream = httpUrlConn.getInputStream();								// Convert the returned input stream into a string
																		inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
																		bufferedReader = new BufferedReader(inputStreamReader);

																		String str = null;
																		while ((str = bufferedReader.readLine()) != null) {
																			buffer.append(str);
																		}
																	} finally { 
																		if (bufferedReader != null) {
																			bufferedReader.close();
																			bufferedReader = null;
																		}
																		if (inputStreamReader != null) {
																			inputStreamReader.close();
																			inputStreamReader = null;
																		}
																		if (inputStream != null) {
																			inputStream.close();
																			inputStream = null;
																		}
																	}

																} finally {
																	if (httpUrlConn != null) {
																		httpUrlConn.disconnect();
																	}
																}
																return buffer.toString();
															}
														}
															  
														  
														

Message push (using device code)

Request address:https://serverurl/v1/audio/

Interface function: push voice messages to specified devices.

parameter name Parameter Description Is the value required
appkey Application appkey Yes
method Requested interface name,push Yes
devicesn Device number, you can specify the device number to push messages to the device Yes
message Broadcast amount, int type, unit: cent Yes
push_template Voice template (5 Alipay; 6 WeChat; 7 Scan (default); 8 UnionPay) Yes
timestamp Timestamp, format yyyyMMddHHmmss Yes
nonce Random string generated on the client side. No more than 32 bits in length Yes
sign The signature of the request parameter Base64(HmacSHA256(parameter to be signed, appsecret)) The method of generating the character string to be signed is detailed in "Message Signature Instructions" Yes
parameter name Parameter Description
code Return response code
msg Result description
nonce The nonce when requested, bring it back as it is
pushsn Message serial number
sign Signature of response data Base64 (HmacSHA256 (parameter to be signed, appsecret)) The generation rules of the parameters to be signed are the same as the generation rules of the request signature
																		
																			
																import java.io.BufferedReader;
																import java.io.InputStream;
																import java.io.InputStreamReader;
																import java.io.OutputStream;
																import java.net.HttpURLConnection;
																import java.net.URL;
																import java.security.MessageDigest;
																import java.security.SecureRandom;
																import java.text.SimpleDateFormat;
																import java.util.Arrays;
																import java.util.Base64;
																import java.util.Date;
																import java.util.HashMap;
																import java.util.Map;
																import java.util.Random;
																import java.util.Set;
																import javax.crypto.Mac;
																import javax.crypto.spec.SecretKeySpec;
																
																
																import com.alibaba.fastjson.JSON;
																		
																		
																		
																	                                                   
																public static void main(String[] args) {
																	try {
																		String serverUrl = "<Your serverUrl>";
																		String appkey = "<Your appkey>";
																		String appsecret = "<Your appsecret>";
																		String method = "<Requested interface name>";
																		String devicesn = "<Your device number>";
																		Integer message = "<Announced amount>";
																		Integer push_template = "<Your template number>";
																		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
																		String timestamp = dateFormat.format(new Date());						// Timestamp
																		char[] nonceChars = new char[32];
																		final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
																		final Random RANDOM = new SecureRandom();
																		for (int index = 0; index > nonceChars.length; ++index) {
																			nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
																		}
																		String none = new String(nonceChars); 									// Get random string
																		Map<String,Object> param = new HashMap<String,Object>();
																		param.put("appkey", appkey); 											// Setting parameters
																		.....;
																		String sign = generateSignature(param, appsecret, "HMAC-SHA256");		// Please refer to the signature sample generation
																		param.put("sign", sign);
																		String response = httpRequest(serverUrl, "POST", JSON.toJSONString(param));
																		System.out.println(response);											// Return result
																	} catch (Exception e) {
																		e.printStackTrace();
																	}
																}
																  
																 public static String generateSignature(final Map<String,Object> data, String appsecret, String signType) // Generate data signature
																	throws Exception {
																		Set keySet = data.keySet();
																		String[] keyArray = (String[]) keySet.toArray(new String[keySet.size()]);
																		Arrays.sort(keyArray);
																		StringBuilder sb = new StringBuilder();
																		for (String k : keyArray) {
																			if (k.equals("sign")) {
																				continue;
																			}
																	 
																			if (data.get(k) == null || "null".equals(data.get(k))) { 				// If the parameter value is empty, it will not participate in the signature
																				data.remove(k);
																				continue;
																			}
																	 
																			Object value = data.get(k);
																			if (value instanceof Integer) {
																				value = sb.append(k).append("=").append(value).append("&");
																			} else {
																				if (String.valueOf(value).trim().length() > 0) {
																					sb.append(k).append("=").append(String.valueOf(value).trim()).append("&");
																				}
																			}
																		}
																		String sbr = sb.substring(0, sb.length() - 1);
																		if ("MD5".equals(signType)) {
																			java.security.MessageDigest md = MessageDigest.getInstance("MD5");
																			byte[] array = md.digest(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array);					// Hexadecimal base64 form
																		} else if ("HMAC-SHA256".equals(signType)) {
																			Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
																			SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes("UTF-8"), "HmacSHA256");
																			sha256_HMAC.init(secret_key);
																			byte[] array = sha256_HMAC.doFinal(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array); 					// Hexadecimal base64 form
																		}
																		return null;
																 }
																													 
																public static String httpRequest(String requestUrl, String requestMethod, String outputStr) // Send request method
																	throws Exception {
																		StringBuffer buffer = new StringBuffer();
																		HttpURLConnection httpUrlConn = null;
																		try {
																			URL url = new URL(requestUrl);
																			httpUrlConn = (HttpURLConnection) url.openConnection();
																
																			httpUrlConn.setDoOutput(true);
																			httpUrlConn.setDoInput(true);
																			httpUrlConn.setUseCaches(false);
																			httpUrlConn.setConnectTimeout(30000);
																			httpUrlConn.setReadTimeout(60000);
																			httpUrlConn.setRequestProperty("Content-type", "application/json");
																
																			httpUrlConn.setRequestMethod(requestMethod);								// Set the request method (GET/POST)
																
																			if ("GET".equalsIgnoreCase(requestMethod)) {
																				httpUrlConn.connect();
																			}
																
																			if (null != outputStr && outputStr.length() > 0) {							// When there is data to submit
																				OutputStream outputStream = null;
																				try {
																					outputStream = httpUrlConn.getOutputStream();
																					outputStream.write(outputStr.getBytes("UTF-8"));					// Pay attention to the encoding format to prevent Chinese garbled characters
																				} finally {
																					if (outputStream != null) {
																						outputStream.close();
																						outputStream = null;
																					}
																				}
																			}
																
																			InputStream inputStream = null;
																			InputStreamReader inputStreamReader = null;
																			BufferedReader bufferedReader = null;
																			try {
																				inputStream = httpUrlConn.getInputStream();								// Convert the returned input stream into a string
																				inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
																				bufferedReader = new BufferedReader(inputStreamReader);
																
																				String str = null;
																				while ((str = bufferedReader.readLine()) != null) {
																					buffer.append(str);
																				}
																			} finally { 
																				if (bufferedReader != null) {
																					bufferedReader.close();
																					bufferedReader = null;
																				}
																				if (inputStreamReader != null) {
																					inputStreamReader.close();
																					inputStreamReader = null;
																				}
																				if (inputStream != null) {
																					inputStream.close();
																					inputStream = null;
																				}
																			}
																
																		} finally {
																			if (httpUrlConn != null) {
																				httpUrlConn.disconnect();
																			}
																		}
																		return buffer.toString();
																	}
																}
																	  
															  
															

Message push (using the code plate number)

Request address:https://serverurl/v1/audio/

Interface function: push voice messages to specified devices.

parameter name Parameter Description Is the value required
appkey Application appkey Yes
method Requested interface name,pushByPaycode Yes
paycode Collection code, specify the collection code, and push messages to the bound device Yes
message Broadcast amount, int type, unit: cent Yes
push_template Voice template (5 Alipay; 6 WeChat; 7 Scan (default); 8 UnionPay) Yes
timestamp Timestamp, format yyyyMMddHHmmss Yes
nonce Random string generated on the client side. No more than 32 bits in length Yes
sign The signature of the request parameter Base64(HmacSHA256(parameter to be signed, appsecret)) The method of generating the character string to be signed is detailed in "Message Signature Instructions" Yes
parameter name Parameter Description
code Return response code
msg Result description
pushsn Message serial number
nonce The nonce when requested, bring it back as it is
sign Signature of response data Base64 (HmacSHA256 (parameter to be signed, appsecret)) The generation rules of the parameters to be signed are the same as the generation rules of the request signature
															  
																
																import java.io.BufferedReader;
																import java.io.InputStream;
																import java.io.InputStreamReader;
																import java.io.OutputStream;
																import java.net.HttpURLConnection;
																import java.net.URL;
																import java.security.MessageDigest;
																import java.security.SecureRandom;
																import java.text.SimpleDateFormat;
																import java.util.Arrays;
																import java.util.Base64;
																import java.util.Date;
																import java.util.HashMap;
																import java.util.Map;
																import java.util.Random;
																import java.util.Set;
																import javax.crypto.Mac;
																import javax.crypto.spec.SecretKeySpec;
																
																
																import com.alibaba.fastjson.JSON;
																		
																		
																		
																	                                                   
																public static void main(String[] args) {
																	try {
																		String serverUrl = "<Your serverUrl>";
																		String appkey = "<Your appkey>";
																		String appsecret = "<Your appsecret>";
																		String method = "<Requested interface name>";
																		String paycode = "<Your payment code>";
																		Integer message = "<Announced amount>";
																		Integer push_template = "<Your template number>";
																		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
																		String timestamp = dateFormat.format(new Date());						// Timestamp
																		char[] nonceChars = new char[32];
																		final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
																		final Random RANDOM = new SecureRandom();
																		for (int index = 0; index > nonceChars.length; ++index) {
																			nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
																		}
																		String none = new String(nonceChars); 									// Get random string
																		Map<String,Object> param = new HashMap<String,Object>();
																		param.put("appkey", appkey); 											// Setting parameters
																		.....;
																		String sign = generateSignature(param, appsecret, "HMAC-SHA256");		// Please refer to the signature sample generation
																		param.put("sign", sign);
																		String response = httpRequest(serverUrl, "POST", JSON.toJSONString(param));
																		System.out.println(response);											// Return result
																	} catch (Exception e) {
																		e.printStackTrace();
																	}
																}
																  
																 public static String generateSignature(final Map<String,Object> data, String appsecret, String signType) // Generate data signature
																	throws Exception {
																		Set keySet = data.keySet();
																		String[] keyArray = (String[]) keySet.toArray(new String[keySet.size()]);
																		Arrays.sort(keyArray);
																		StringBuilder sb = new StringBuilder();
																		for (String k : keyArray) {
																			if (k.equals("sign")) {
																				continue;
																			}
																	 
																			if (data.get(k) == null || "null".equals(data.get(k))) { 				// If the parameter value is empty, it will not participate in the signature
																				data.remove(k);
																				continue;
																			}
																	 
																			Object value = data.get(k);
																			if (value instanceof Integer) {
																				value = sb.append(k).append("=").append(value).append("&");
																			} else {
																				if (String.valueOf(value).trim().length() > 0) {
																					sb.append(k).append("=").append(String.valueOf(value).trim()).append("&");
																				}
																			}
																		}
																		String sbr = sb.substring(0, sb.length() - 1);
																		if ("MD5".equals(signType)) {
																			java.security.MessageDigest md = MessageDigest.getInstance("MD5");
																			byte[] array = md.digest(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array);					// Hexadecimal base64 form
																		} else if ("HMAC-SHA256".equals(signType)) {
																			Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
																			SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes("UTF-8"), "HmacSHA256");
																			sha256_HMAC.init(secret_key);
																			byte[] array = sha256_HMAC.doFinal(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array); 					// Hexadecimal base64 form
																		}
																		return null;
																 }
																													 
																public static String httpRequest(String requestUrl, String requestMethod, String outputStr) // Send request method
																	throws Exception {
																		StringBuffer buffer = new StringBuffer();
																		HttpURLConnection httpUrlConn = null;
																		try {
																			URL url = new URL(requestUrl);
																			httpUrlConn = (HttpURLConnection) url.openConnection();
																
																			httpUrlConn.setDoOutput(true);
																			httpUrlConn.setDoInput(true);
																			httpUrlConn.setUseCaches(false);
																			httpUrlConn.setConnectTimeout(30000);
																			httpUrlConn.setReadTimeout(60000);
																			httpUrlConn.setRequestProperty("Content-type", "application/json");
																
																			httpUrlConn.setRequestMethod(requestMethod);								// Set the request method (GET/POST)
																
																			if ("GET".equalsIgnoreCase(requestMethod)) {
																				httpUrlConn.connect();
																			}
																
																			if (null != outputStr && outputStr.length() > 0) {							// When there is data to submit
																				OutputStream outputStream = null;
																				try {
																					outputStream = httpUrlConn.getOutputStream();
																					outputStream.write(outputStr.getBytes("UTF-8"));					// Pay attention to the encoding format to prevent Chinese garbled characters
																				} finally {
																					if (outputStream != null) {
																						outputStream.close();
																						outputStream = null;
																					}
																				}
																			}
																
																			InputStream inputStream = null;
																			InputStreamReader inputStreamReader = null;
																			BufferedReader bufferedReader = null;
																			try {
																				inputStream = httpUrlConn.getInputStream();								// Convert the returned input stream into a string
																				inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
																				bufferedReader = new BufferedReader(inputStreamReader);
																
																				String str = null;
																				while ((str = bufferedReader.readLine()) != null) {
																					buffer.append(str);
																				}
																			} finally { 
																				if (bufferedReader != null) {
																					bufferedReader.close();
																					bufferedReader = null;
																				}
																				if (inputStreamReader != null) {
																					inputStreamReader.close();
																					inputStreamReader = null;
																				}
																				if (inputStream != null) {
																					inputStream.close();
																					inputStream = null;
																				}
																			}
																
																		} finally {
																			if (httpUrlConn != null) {
																				httpUrlConn.disconnect();
																			}
																		}
																		return buffer.toString();
																	}
																}
																	  
															  
															

Get code plate binding device

Request address:https://serverurl/v1/audio/

Interface function: upload the QR code plate number and get the device number bound to the QR code plate.

parameter name Parameter Description Is the value required
appkey Application appkey Yes
method Requested interface name,getBindDevice Yes
paycode Code plate number (the content of the QR code of the receipt code) Yes
timestamp Timestamp, format yyyyMMddHHmmss Yes
nonce Random string generated on the client side. No more than 32 bits in length Yes
sign The signature of the request parameter Base64(HmacSHA256(parameter to be signed, appsecret)) The method of generating the character string to be signed is detailed in "Message Signature Instructions" Yes
															  
																
																import java.io.BufferedReader;
																import java.io.InputStream;
																import java.io.InputStreamReader;
																import java.io.OutputStream;
																import java.net.HttpURLConnection;
																import java.net.URL;
																import java.security.MessageDigest;
																import java.security.SecureRandom;
																import java.text.SimpleDateFormat;
																import java.util.Arrays;
																import java.util.Base64;
																import java.util.Date;
																import java.util.HashMap;
																import java.util.Map;
																import java.util.Random;
																import java.util.Set;
																import javax.crypto.Mac;
																import javax.crypto.spec.SecretKeySpec;


																import com.alibaba.fastjson.JSON;
																	


																	
																public static void main(String[] args) {
																	try {
																		String serverUrl = "<Your serverUrl>";
																		String appkey = "<Your appkey>";
																		String appsecret = "<Your appsecret>";
																		String method = "<Requested interface name>";
																		String paycode = "<Your payment code>";
																		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
																		String timestamp = dateFormat.format(new Date());						// Timestamp
																		char[] nonceChars = new char[32];
																		final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
																		final Random RANDOM = new SecureRandom();
																		for (int index = 0; index > nonceChars.length; ++index) {
																			nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
																		}
																		String none = new String(nonceChars); 									// Get random string
																		Map<String,Object> param = new HashMap<String,Object>();
																		param.put("appkey", appkey); 											// Setting parameters
																		.....;
																		String sign = generateSignature(param, appsecret, "HMAC-SHA256");		// Please refer to the signature sample generation
																		param.put("sign", sign);
																		String response = httpRequest(serverUrl, "POST", JSON.toJSONString(param));
																		System.out.println(response);											// Return result
																	} catch (Exception e) {
																		e.printStackTrace();
																	}
																}

																 public static String generateSignature(final Map<String,Object> data, String appsecret, String signType) // Generate data signature
																	throws Exception {
																		Set keySet = data.keySet();
																		String[] keyArray = (String[]) keySet.toArray(new String[keySet.size()]);
																		Arrays.sort(keyArray);
																		StringBuilder sb = new StringBuilder();
																		for (String k : keyArray) {
																			if (k.equals("sign")) {
																				continue;
																			}

																			if (data.get(k) == null || "null".equals(data.get(k))) { 				// If the parameter value is empty, it will not participate in the signature
																				data.remove(k);
																				continue;
																			}

																			Object value = data.get(k);
																			if (value instanceof Integer) {
																				value = sb.append(k).append("=").append(value).append("&");
																			} else {
																				if (String.valueOf(value).trim().length() > 0) {
																					sb.append(k).append("=").append(String.valueOf(value).trim()).append("&");
																				}
																			}
																		}
																		String sbr = sb.substring(0, sb.length() - 1);
																		if ("MD5".equals(signType)) {
																			java.security.MessageDigest md = MessageDigest.getInstance("MD5");
																			byte[] array = md.digest(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array);					// Hexadecimal base64 form
																		} else if ("HMAC-SHA256".equals(signType)) {
																			Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
																			SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes("UTF-8"), "HmacSHA256");
																			sha256_HMAC.init(secret_key);
																			byte[] array = sha256_HMAC.doFinal(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array); 					// Hexadecimal base64 form
																		}
																		return null;
																 }

																public static String httpRequest(String requestUrl, String requestMethod, String outputStr) // Send request method
																	throws Exception {
																		StringBuffer buffer = new StringBuffer();
																		HttpURLConnection httpUrlConn = null;
																		try {
																			URL url = new URL(requestUrl);
																			httpUrlConn = (HttpURLConnection) url.openConnection();

																			httpUrlConn.setDoOutput(true);
																			httpUrlConn.setDoInput(true);
																			httpUrlConn.setUseCaches(false);
																			httpUrlConn.setConnectTimeout(30000);
																			httpUrlConn.setReadTimeout(60000);
																			httpUrlConn.setRequestProperty("Content-type", "application/json");

																			httpUrlConn.setRequestMethod(requestMethod);								// Set the request method (GET/POST)

																			if ("GET".equalsIgnoreCase(requestMethod)) {
																				httpUrlConn.connect();
																			}

																			if (null != outputStr && outputStr.length() > 0) {							// When there is data to submit
																				OutputStream outputStream = null;
																				try {
																					outputStream = httpUrlConn.getOutputStream();
																					outputStream.write(outputStr.getBytes("UTF-8"));					// Pay attention to the encoding format to prevent Chinese garbled characters
																				} finally {
																					if (outputStream != null) {
																						outputStream.close();
																						outputStream = null;
																					}
																				}
																			}

																			InputStream inputStream = null;
																			InputStreamReader inputStreamReader = null;
																			BufferedReader bufferedReader = null;
																			try {
																				inputStream = httpUrlConn.getInputStream();								// Convert the returned input stream into a string
																				inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
																				bufferedReader = new BufferedReader(inputStreamReader);

																				String str = null;
																				while ((str = bufferedReader.readLine()) != null) {
																					buffer.append(str);
																				}
																			} finally {
																				if (bufferedReader != null) {
																					bufferedReader.close();
																					bufferedReader = null;
																				}
																				if (inputStreamReader != null) {
																					inputStreamReader.close();
																					inputStreamReader = null;
																				}
																				if (inputStream != null) {
																					inputStream.close();
																					inputStream = null;
																				}
																			}

																		} finally {
																			if (httpUrlConn != null) {
																				httpUrlConn.disconnect();
																			}
																		}
																		return buffer.toString();
																	}
																}
																	  
															  
															

Get device information

Request address:https://serverurl/v1/audio/

Interface function: check the information of a specified device.

parameter name Parameter Description Is the value required
appkey Application appkey Yes
method Requested interface name,getDeviceInfo Yes
devicesn device ID Yes
timestamp Timestamp, format yyyyMMddHHmmss Yes
nonce The random number generated by the client. Maximum length 32 bits Yes
sign The signature of the request parameter Base64(HmacSHA256(parameter to be signed, appsecret)) The method of generating the character string to be signed is detailed in "Message Signature Instructions" Yes
parameter name Parameter Description
code Return response code
msg Result description
status The binding status of the device (0 is not bound, 1 is bound)
state Device status (0 normal, 1 disabled)
is_online Whether online (0 online, 1 offline)
version current version
last_online_time Last online time
last_offline_time Last offline time
location_info Device location information, for example: {"descp","Xueqing Road, Haidian District, Beijing, near Huizhi Building"}
nonce The nonce when requested, bring it back as it is
sign Signature of response data Base64 (HmacSHA256 (parameter to be signed, appsecret)) The generation rules of the parameters to be signed are the same as the generation rules of the request signature
															  
																
																import java.io.BufferedReader;
																import java.io.InputStream;
																import java.io.InputStreamReader;
																import java.io.OutputStream;
																import java.net.HttpURLConnection;
																import java.net.URL;
																import java.security.MessageDigest;
																import java.security.SecureRandom;
																import java.text.SimpleDateFormat;
																import java.util.Arrays;
																import java.util.Base64;
																import java.util.Date;
																import java.util.HashMap;
																import java.util.Map;
																import java.util.Random;
																import java.util.Set;
																import javax.crypto.Mac;
																import javax.crypto.spec.SecretKeySpec;
																
																
																import com.alibaba.fastjson.JSON;
																		
																		
																		
																	                                                   
																public static void main(String[] args) {
																	try {
																		String serverUrl = "<Your serverUrl>";
																		String appkey = "<Your appkey>";
																		String appsecret = "<Your appsecret>";
																		String method = "<Requested interface name>";
																		String devicesn = "<Your device number>";
																		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
																		String timestamp = dateFormat.format(new Date());						// Timestamp
																		char[] nonceChars = new char[32];
																		final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
																		final Random RANDOM = new SecureRandom();
																		for (int index = 0; index > nonceChars.length; ++index) {
																			nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
																		}
																		String none = new String(nonceChars); 									// Get random string
																		Map<String,Object> param = new HashMap<String,Object>();
																		param.put("appkey", appkey); 											// Setting parameters
																		.....;
																		String sign = generateSignature(param, appsecret, "HMAC-SHA256");		// Please refer to the signature sample generation
																		param.put("sign", sign);
																		String response = httpRequest(serverUrl, "POST", JSON.toJSONString(param));
																		System.out.println(response);											// Return result
																	} catch (Exception e) {
																		e.printStackTrace();
																	}
																}
																  
																 public static String generateSignature(final Map<String,Object> data, String appsecret, String signType) // Generate data signature
																	throws Exception {
																		Set keySet = data.keySet();
																		String[] keyArray = (String[]) keySet.toArray(new String[keySet.size()]);
																		Arrays.sort(keyArray);
																		StringBuilder sb = new StringBuilder();
																		for (String k : keyArray) {
																			if (k.equals("sign")) {
																				continue;
																			}
																	 
																			if (data.get(k) == null || "null".equals(data.get(k))) { 				// If the parameter value is empty, it will not participate in the signature
																				data.remove(k);
																				continue;
																			}
																	 
																			Object value = data.get(k);
																			if (value instanceof Integer) {
																				value = sb.append(k).append("=").append(value).append("&");
																			} else {
																				if (String.valueOf(value).trim().length() > 0) {
																					sb.append(k).append("=").append(String.valueOf(value).trim()).append("&");
																				}
																			}
																		}
																		String sbr = sb.substring(0, sb.length() - 1);
																		if ("MD5".equals(signType)) {
																			java.security.MessageDigest md = MessageDigest.getInstance("MD5");
																			byte[] array = md.digest(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array);					// Hexadecimal base64 form
																		} else if ("HMAC-SHA256".equals(signType)) {
																			Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
																			SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes("UTF-8"), "HmacSHA256");
																			sha256_HMAC.init(secret_key);
																			byte[] array = sha256_HMAC.doFinal(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array); 					// Hexadecimal base64 form
																		}
																		return null;
																 }

																public static String httpRequest(String requestUrl, String requestMethod, String outputStr) // Send request method
																	throws Exception {
																		StringBuffer buffer = new StringBuffer();
																		HttpURLConnection httpUrlConn = null;
																		try {
																			URL url = new URL(requestUrl);
																			httpUrlConn = (HttpURLConnection) url.openConnection();
																
																			httpUrlConn.setDoOutput(true);
																			httpUrlConn.setDoInput(true);
																			httpUrlConn.setUseCaches(false);
																			httpUrlConn.setConnectTimeout(30000);
																			httpUrlConn.setReadTimeout(60000);
																			httpUrlConn.setRequestProperty("Content-type", "application/json");
																
																			httpUrlConn.setRequestMethod(requestMethod);								// Set the request method (GET/POST)
																
																			if ("GET".equalsIgnoreCase(requestMethod)) {
																				httpUrlConn.connect();
																			}
																
																			if (null != outputStr && outputStr.length() > 0) {							// When there is data to submit
																				OutputStream outputStream = null;
																				try {
																					outputStream = httpUrlConn.getOutputStream();
																					outputStream.write(outputStr.getBytes("UTF-8"));					// Pay attention to the encoding format to prevent Chinese garbled characters
																				} finally {
																					if (outputStream != null) {
																						outputStream.close();
																						outputStream = null;
																					}
																				}
																			}
																
																			InputStream inputStream = null;
																			InputStreamReader inputStreamReader = null;
																			BufferedReader bufferedReader = null;
																			try {
																				inputStream = httpUrlConn.getInputStream();								// Convert the returned input stream into a string
																				inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
																				bufferedReader = new BufferedReader(inputStreamReader);
																
																				String str = null;
																				while ((str = bufferedReader.readLine()) != null) {
																					buffer.append(str);
																				}
																			} finally { 
																				if (bufferedReader != null) {
																					bufferedReader.close();
																					bufferedReader = null;
																				}
																				if (inputStreamReader != null) {
																					inputStreamReader.close();
																					inputStreamReader = null;
																				}
																				if (inputStream != null) {
																					inputStream.close();
																					inputStream = null;
																				}
																			}
																
																		} finally {
																			if (httpUrlConn != null) {
																				httpUrlConn.disconnect();
																			}
																		}
																		return buffer.toString();
																	}
																}
																	  
															  
															

Unbind device

Request address:https://serverurl/v1/audio/

Interface function: release the binding relationship between the terminal device and the QR code plate.

parameter name Parameter Description Is the value required
appkey Application appkey Yes
method Requested interface name,unbindDevice Yes
devicesn device ID Yes
timestamp Timestamp, format yyyyMMddHHmmss Yes
nonce The random number generated by the client. Maximum length 32 bits Yes
sign The signature of the request parameter Base64(HmacSHA256(parameter to be signed, appsecret)) The method of generating the character string to be signed is detailed in "Message Signature Instructions" Yes
parameter name Parameter Description
code Return response code
msg Result description
nonce The nonce when requested, bring it back as it is
sign Signature of response data Base64 (HmacSHA256 (parameter to be signed, appsecret)) The generation rules of the parameters to be signed are the same as the generation rules of the request signature
															  
																
																import java.io.BufferedReader;
																import java.io.InputStream;
																import java.io.InputStreamReader;
																import java.io.OutputStream;
																import java.net.HttpURLConnection;
																import java.net.URL;
																import java.security.MessageDigest;
																import java.security.SecureRandom;
																import java.text.SimpleDateFormat;
																import java.util.Arrays;
																import java.util.Base64;
																import java.util.Date;
																import java.util.HashMap;
																import java.util.Map;
																import java.util.Random;
																import java.util.Set;
																import javax.crypto.Mac;
																import javax.crypto.spec.SecretKeySpec;
																
																
																import com.alibaba.fastjson.JSON;
																		
																		
																		
																	                                                   
																public static void main(String[] args) {
																	try {
																		String serverUrl = "<Your serverUrl>";
																		String appkey = "<Your appkey>";
																		String appsecret = "<Your appsecret>";
																		String method = "<Requested interface name>";
																		String devicesn = "<Your device number>";
																		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
																		String timestamp = dateFormat.format(new Date());						// Timestamp
																		char[] nonceChars = new char[32];
																		final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
																		final Random RANDOM = new SecureRandom();
																		for (int index = 0; index > nonceChars.length; ++index) {
																			nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
																		}
																		String none = new String(nonceChars); 									// Get random string
																		Map<String,Object> param = new HashMap<String,Object>();
																		param.put("appkey", appkey); 											// Setting parameters
																		.....;
																		String sign = generateSignature(param, appsecret, "HMAC-SHA256");		// Please refer to the signature sample generation
																		param.put("sign", sign);
																		String response = httpRequest(serverUrl, "POST", JSON.toJSONString(param));
																		System.out.println(response);											// Return result
																	} catch (Exception e) {
																		e.printStackTrace();
																	}
																}
																  
																 public static String generateSignature(final Map<String,Object> data, String appsecret, String signType) // Generate data signature
																	throws Exception {
																		Set keySet = data.keySet();
																		String[] keyArray = (String[]) keySet.toArray(new String[keySet.size()]);
																		Arrays.sort(keyArray);
																		StringBuilder sb = new StringBuilder();
																		for (String k : keyArray) {
																			if (k.equals("sign")) {
																				continue;
																			}
																	 
																			if (data.get(k) == null || "null".equals(data.get(k))) { 				// If the parameter value is empty, it will not participate in the signature
																				data.remove(k);
																				continue;
																			}
																	 
																			Object value = data.get(k);
																			if (value instanceof Integer) {
																				value = sb.append(k).append("=").append(value).append("&");
																			} else {
																				if (String.valueOf(value).trim().length() > 0) {
																					sb.append(k).append("=").append(String.valueOf(value).trim()).append("&");
																				}
																			}
																		}
																		String sbr = sb.substring(0, sb.length() - 1);
																		if ("MD5".equals(signType)) {
																			java.security.MessageDigest md = MessageDigest.getInstance("MD5");
																			byte[] array = md.digest(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array);					// Hexadecimal base64 form
																		} else if ("HMAC-SHA256".equals(signType)) {
																			Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
																			SecretKeySpec secret_key = new SecretKeySpec(appsecret.getBytes("UTF-8"), "HmacSHA256");
																			sha256_HMAC.init(secret_key);
																			byte[] array = sha256_HMAC.doFinal(sbr.getBytes("UTF-8"));
																			return Base64.getUrlEncoder().encodeToString(array); 					// Hexadecimal base64 form
																		}
																		return null;
																 }
																													 
																public static String httpRequest(String requestUrl, String requestMethod, String outputStr) // Send request method
																	throws Exception {
																		StringBuffer buffer = new StringBuffer();
																		HttpURLConnection httpUrlConn = null;
																		try {
																			URL url = new URL(requestUrl);
																			httpUrlConn = (HttpURLConnection) url.openConnection();
																
																			httpUrlConn.setDoOutput(true);
																			httpUrlConn.setDoInput(true);
																			httpUrlConn.setUseCaches(false);
																			httpUrlConn.setConnectTimeout(30000);
																			httpUrlConn.setReadTimeout(60000);
																			httpUrlConn.setRequestProperty("Content-type", "application/json");
																
																			httpUrlConn.setRequestMethod(requestMethod);								// Set the request method (GET/POST)
																
																			if ("GET".equalsIgnoreCase(requestMethod)) {
																				httpUrlConn.connect();
																			}
																
																			if (null != outputStr && outputStr.length() > 0) {							// When there is data to submit
																				OutputStream outputStream = null;
																				try {
																					outputStream = httpUrlConn.getOutputStream();
																					outputStream.write(outputStr.getBytes("UTF-8"));					// Pay attention to the encoding format to prevent Chinese garbled characters
																				} finally {
																					if (outputStream != null) {
																						outputStream.close();
																						outputStream = null;
																					}
																				}
																			}
																
																			InputStream inputStream = null;
																			InputStreamReader inputStreamReader = null;
																			BufferedReader bufferedReader = null;
																			try {
																				inputStream = httpUrlConn.getInputStream();								// Convert the returned input stream into a string
																				inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
																				bufferedReader = new BufferedReader(inputStreamReader);
																
																				String str = null;
																				while ((str = bufferedReader.readLine()) != null) {
																					buffer.append(str);
																				}
																			} finally { 
																				if (bufferedReader != null) {
																					bufferedReader.close();
																					bufferedReader = null;
																				}
																				if (inputStreamReader != null) {
																					inputStreamReader.close();
																					inputStreamReader = null;
																				}
																				if (inputStream != null) {
																					inputStream.close();
																					inputStream = null;
																				}
																			}
																
																		} finally {
																			if (httpUrlConn != null) {
																				httpUrlConn.disconnect();
																			}
																		}
																		return buffer.toString();
																	}
																}