In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the method of the interface specification of the Internet of things". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's study and learn "what is the method of the interface specification of the Internet of things"?
I. Development process
Register a developer account.
Cloud developer creates cloud application projects and acquires client_id & secret.
Description: the name of developer platform key is accessId & accessKey.
Create SDK: on the graffiti IoT platform, select App Workbench > App SDK > get SDK > enter parameters as required > get schema (Channel ID).
Business development based on OpenAPI.
After the test is correct, the developer will release it by himself.
II. Authorization process
Each business OpenAPI needs to be verified by token.
Description: graffiti OpenAPI follows the OAuth 2.0 protocol standard.
Third, simple mode
For cloud docking scenarios, graffiti provides implicit authorization to obtain:
Sign and verify the developer client_id and secret according to the graffiti cloud OpenAPI interface specification.
The graffiti cloud verifies and issues tokens to the third-party cloud.
Description: the permission dimension of the token obtained by implicit authorization is the developer dimension. The scope of operation permission of token is the scope that the developer has permission to operate, such as the application user data of the developer (add, delete, modify, query), the device data under the product and the device data bound by the user under the application.
IV. Interface specification
Environment description
The users of each interface should call the corresponding API according to their own region.
Https://openapi.tuyacn.com in China
Https://openapi.tuyaus.com in America
European https://openapi.tuyaeu.com
India https://openapi.tuyain.com
Request mode
The supported request methods are as follows:
GET
PUT
POST
DELETE
Note: when the request method is POST, Content-Type needs to use application/json.
Request header setting
Any API needs to add the following parameters to the header:
Note: the parameter access_token is required when the business API (non-token API) is requested.
V. signature specification
Graffiti Cloud uses HMAC-SHA256 to create a summary. Two sets of signature algorithms are available according to different application scenarios:
Token management interface (get token, refresh token)
Sign = HMAC-SHA256 (client_id + t, secret). ToUpperCase ()
Use the applied client_id and the 13-bit standard timestamp of the current request to be spliced into a string to be signed. The applied cloud application secret is used as the key to participate in the hash digest. The resulting string is finally capitalized.
Service interface
Sign = HMAC-SHA256 (client_id access_token + t, secret) .toUpperCase ()
Use the applied cloud application client_id + the currently valid request token + the 13-bit standard timestamp of the current request to assemble the string to be signed, and use the applied cloud application secret as the key to participate in the hash digest. The resulting string is finally converted to uppercase.
Signature example
Prepare parameters:
Client_id:1KAD46OrT9HafiKdsXeg
Secret:4OHBOnWOqaEC1mWXOpVL3yV50s0qGSRC
T:1588925778000
Access_token:3f4eda2bdec17232f67c0b188af3eec1
Token management interface signature:
String to be signed: 1KAD46OrT9HafiKdsXeg1588925778000
Signature result: HMAC-SHA256 (1KAD46OrT9HafiKdsXeg15889257780001.4OHBOnWOqaEC1mWXOpVL3yV50s0qGSRC)
Ceaafb5ccdc2f723a9fd3e91d3d2238ee0dd9a6d7c3c365deb50fc2af277aa83
Turn uppercase to: CEAAFB5CCDC2F723A9FD3E91D3D2238EE0DD9A6D7C3C365DEB50FC2AF277AA83
Business Interface:
String to be signed: 1KAD46OrT9HafiKdsXeg3f4eda2bdec17232f67c0b188af3eec11588925778000
Signature result: HMAC-SHA256 (1KAD46OrT9HafiKdsXeg3f4eda2bdec17232f67c0b188af3eec11588925778000t 4OHBOnWOqaEC1mWXOpVL3yV50s0qGSRC)
36c30e300f226b68add014dd1ef56a81edb7b7a817840485769b9d6c96d0faa1
Turn uppercase to: 36C30E300F226B68ADD014DD1EF56A81EDB7B7A817840485769B9D6C96D0FAA1
The implementation of HMAC SHA256 in various languages:
Javascript HMAC SHA256
/ * Run the code online with this jsfiddle. Dependent upon an open source js library called http://code.google.com/p/crypto-js/.**/ var hash = CryptoJS.HmacSHA256 ("Message", "secret"); var hashInBase64 = hash.toString (). ToUpperCase (); [xss_clean] (hashInBase64)
PHP HMAC SHA256
/ * * PHP has built in methods for hash_hmac (PHP 5) and base64_encode (PHP 4, PHP 5) resulting in no outside dependencies. Say what you want about PHP but they have the cleanest code for this example.**/$s = hash_hmac ('sha256',' Message', 'secret', true); echo strtoupper (var_dump ($s))
Java HMAC SHA256
/ * * Dependent on Apache Commons Codec to encode in base64.**/import javax.crypto.Mac;import javax.crypto.spec.SecretKeySpec;import org.apache.commons.codec.binary.Base64;public class ApiSecurityExample {public static void main (String [] args) {try {String secret = "secret"; String message = "Message"; Mac sha256_HMAC = Mac.getInstance ("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec (secret.getBytes (), "HmacSHA256") Sha256_HMAC.init (secret_key); byte [] bytes = sha256_HMAC.doFinal (message.getBytes ()); String hash = new HexBinaryAdapter (). Marshal (bytes). ToUpperCase (); System.out.println (hash);} catch (Exception e) {System.out.println ("Error");}
C# HMAC SHA256
Using System;using System.Security.Cryptography;namespace Test {public class MyHmac {public static string Encrypt (string message, string secret) {secret = secret? "; var encoding = new System.Text.UTF8Encoding (); byte [] keyByte = encoding.GetBytes (secret); byte [] messageBytes = encoding.GetBytes (message) Using (var hmacsha256 = new HMACSHA256 (keyByte)) {byte [] hashmessage = hmacsha256.ComputeHash (messageBytes); StringBuilder builder = new StringBuilder (); for (int I = 0; I < hashmessage.Length) ToUpper +) {builder.Append (hashmessage [I] .ToString ("x2"));} return builder.ToString () .ToString ();}}
The returned results are uniformly returned with JSON. The general format is as follows:
Request successful
{"success": true, "result": {/ / object}}
Request exception
{"success": false, "code": 1010, "msg": "token illegal"}
VI. Overview of Integrated SDK Java
Currently, Java-based Tuya Cloud SDK encapsulates token-related, user-related and device-related interfaces to speed up the development of cloud-to-cloud docking.
Developers only need to pay attention to the calls of the business function methods used, and build the corresponding TuyaClient instance, which will automatically update the token and complete the call to the corresponding API. SDK mainly includes the following features. For more information on APIs, please refer to the corresponding module below:
Token related (no user calls required)
User-related (get the list of users, register users, get the list of devices under users)
Device-related (get the device distribution network token, get the list of all devices under the distribution network token, etc.)
Integrated SDK
IDEA Import jar package
Eclipse Import jar package
General module
As some of the new APIs cannot be synchronously integrated into SDK in time, developers can scale horizontally through SDK general APIs to meet the needs of development.
Get the Header list:
/ * get Header list * @ param isToken whether it is a token-related request, usually false * @ return * / public List getHeaders (Boolean isToken)
Universal graffiti interface:
/ * * Universal graffiti API * @ param url * @ param method request type (e.g. GET) * @ param headers request header content (additional header) * @ param body * @ return * / public String commonHttpRequest (String url, HttpMethod method, Map headers, Object body)
Invocation example
The following is an example of a registered user:
TuyaClient client = new TuyaClient (clientId, secret, RegionEnum.CN); String uid = client.registerUser ("testApp", "86", "18212345678", MD5Util.getMD5 ("123456") "nickName", UserTypeEnum.MOBLIE); System.out.println ("successful synchronization user:" + uid) Thank you for your reading. the above is the content of "what is the method of the interface specification of the Internet of things". After the study of this article, I believe you have a deeper understanding of the method of the interface specification of the Internet of things. the specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.