当前位置:网站首页>[graffiti Internet of things footprint] graffiti cloud platform interface description
[graffiti Internet of things footprint] graffiti cloud platform interface description
2020-11-09 19:12:00 【IOT cloud workshop】
Preface series of articles >>>【 Doodling the footprints of the Internet of things 】API And SDK Introduce
Our series of articles , It's all about how to complete an intelligence “ Space kissing machine ” Development of . I hope it can help the long-distance love __or__ Exotic lovers !
In this article, we will explain in general based on OpenAPI What's involved in development is API Calling method 、 standard 、 Examples and integration SDK Related content . The content will be hard core , Please pay attention to !
One 、 Development process
- register Developer account .
- Cloud development creates cloud application projects , obtain client_id & secret.
explain : Developer Platform key For the name of the accessId & accessKey.
- establish SDK: stay Doodle IoT platform , choice App The workbench > App SDK > obtain SDK > Fill in the parameters as required > obtain schema( Channel logo ).
- be based on OpenAPI Business development .
- After the test is correct , Developers release themselves .
Two 、 Authorization process
Every business OpenAPI All need to be done token check .
explain : Doodle OpenAPI follow OAuth 2.0 Protocol standard .
3、 ... and 、 Simple mode
For the cloud cloud docking scenario , Graffiti provides an implicit way to obtain :

- According to the graffiti cloud OpenAPI Interface specification for developers client_id and secret Do signature verification .
- Graffiti cloud verifies and issues token to third party cloud .
explain : Obtained by implicit authorization token, The permission dimension is the developer dimension ,token The operation permission range of the developer is the scope of the permission Operation of the developer , Such as operating ( increase 、 Delete 、 Change 、 check ) Developer's application user data , The device data under the product and the device data bound by the user under the application .
Four 、 The interface specification
Environmental statement
Each user of the interface should call the corresponding interface according to its own region .
China proper https://openapi.tuyacn.com
Americas https://openapi.tuyaus.com
Europe https://openapi.tuyaeu.com
India https://openapi.tuyain.com
Request mode
Support can be requested in the following way :
- GET
- PUT
- POST
- DELETE
explain : When the request mode is POST when ,Content-Type Need to use application/json.
Request header Settings
Any interface needs to be in header Add the following parameters to :

explain : Business interface ( Not token Interface ) The request requires parameters access_token.
5、 ... and 、 Signature specification
Graffiti cloud uses HMAC-SHA256 Create a summary , According to different application scenarios , Two signature algorithms are currently available :
- Token management interface ( Get token 、 Refresh token )
sign = HMAC-SHA256(client_id + t, secret).toUpperCase()
Use the applied client_id With the current request 13 Bit standard timestamps are spliced into strings to be signed , Use the applied Cloud Application secret Participate in hash digest as key , The resulting string , Finally, capitalize ;
- Business interface
sign = HMAC-SHA256(client_id + access_token + t, secret).toUpperCase()
Use the applied cloud app client_id + Currently valid request token + Currently requested 13 Bit standard timestamps are spliced into strings to be signed , Use the applied Cloud Application secret Participate in hash digest as key , The resulting string , Finally, capitalize .
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(1KAD46OrT9HafiKdsXeg1588925778000,4OHBOnWOqaEC1mWXOpVL3yV50s0qGSRC)
ceaafb5ccdc2f723a9fd3e91d3d2238ee0dd9a6d7c3c365deb50fc2af277aa83
Put it in capitals :CEAAFB5CCDC2F723A9FD3E91D3D2238EE0DD9A6D7C3C365DEB50FC2AF277AA83
- Business interface :
String to be signed :1KAD46OrT9HafiKdsXeg3f4eda2bdec17232f67c0b188af3eec11588925778000
Signature result :HMAC-SHA256(1KAD46OrT9HafiKdsXeg3f4eda2bdec17232f67c0b188af3eec11588925778000,4OHBOnWOqaEC1mWXOpVL3yV50s0qGSRC)
36c30e300f226b68add014dd1ef56a81edb7b7a817840485769b9d6c96d0faa1
Put it in capitals :36C30E300F226B68ADD014DD1EF56A81EDB7B7A817840485769B9D6C96D0FAA1
- All kinds of languages HMAC SHA256 The implementation of the :
Javascript HMAC SHA256
/**
Run the code online with this jsfiddle. Dependent upon an open source js library calledhttp://code.google.com/p/crypto-js/.
**/
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>
<script>
var hash = CryptoJS.HmacSHA256("Message", "secret");
var hashInBase64 = hash.toString().toUpperCase();
document.write(hashInBase64);
</script>
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; i++)
{
builder.Append(hashmessage[i].ToString("x2"));
}
return builder.ToString().ToUpper();
}
}
}
}
Return results United return JSON, The general format is as follows :
The request is successful
{
"success": true,
"result": {
//object
}
}
Request exception
{
"success": false,
"code": 1010,
"msg": "token illegal "
}
6、 ... and 、 Integrate SDK Java summary
Currently available based on Java Of Tuya Cloud SDK Encapsulates the token relevant 、 User related and device related interfaces , In order to accelerate the development of cloud cloud docking .
Developers only need to pay attention to the call of business function methods used , Build the corresponding TuyaClient example , The instance will be updated automatically token And complete the correspondence API Call to .SDK It mainly includes the following functions , For detailed interface information, please refer to the corresponding module later :
token relevant ( No user calls are required )
User correlation ( Get the list of users 、 Registered users 、 Get the device list under the user )
Equipment related ( Get the equipment distribution network token、 Get the distribution network token Under the list of all devices and other interfaces )
Integrate SDK
IDEA Import jar package : https://jingyan.baidu.com/article/0f5fb0993e9e1f6d8334ead2.html
Eclipse Import jar package : https://jingyan.baidu.com/article/ca41422fc76c4a1eae99ed9f.html
GitHub Address
https://github.com/TuyaInc/tuya_cloud_sdk_java
General module
Because some new interfaces cannot be synchronized and integrated to SDK, Developers can use SDK The general interface is extended horizontally to meet the needs of development .
obtain Header list :
/**
* obtain Header list
* @param isToken Whether it is token Relevant request , It's usually false
* @return
*/
public List<Header> getHeaders(Boolean isToken)
Universal graffiti interface :
/**
* Universal graffiti interface
* @param url
* @param method Request type ( for example :GET)
* @param headers Request header content ( Extra new header)
* @param body
* @return
*/
public String commonHttpRequest(String url, HttpMethod method, Map<String, String> headers, Object body)
Invoke the sample
Here 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(" Successfully synchronized user : "+ uid);
Golang
Golang SDK Source code address , Please see the Golang SDK.
版权声明
本文为[IOT cloud workshop]所创,转载请带上原文链接,感谢
边栏推荐
- It will be 2021. What is the modern C + + worth learning?
- Ultra simple integration of Huawei system integrity testing, complete equipment security protection
- 浅谈API网关(API Gateway)如何承载API经济生态链
- Share tips on editing letters and mathematical formulas with MathType
- Git + -- Code hosting in the history of version management
- How the API gateway carries the API economic ecological chain
- DCL单例模式中的缺陷及单例模式的其他实现
- 手把手教你使用容器服务 TKE 集群审计排查问题
- 非常值得一看的 Curl 用法指南
- How to use binary search algorithm
猜你喜欢

零基础小白python入门——深入Python中的文件操作

GPS timing system (network timing instrument) application of e-government system

SQL Server附加数据库拒绝访问解决方法汇总

60 余位技术高管齐聚松山湖,华为云第一期核心伙伴开发者训练营圆满落幕

几乎刷完了力扣所有的链表题,我发现了这些东西。。。

又一道比较运算符相关的面试题让我明白基础很重要

如何用代码上传头像,并添加自己的版权信息?

第三阶段 Day20 购物车模块实现 添加拦截器 添加用户权限校检 实现订单模块

财务管理系统如何帮助企业实现财务自动化管理?

C console calls ffmpeg to push MP4 video file to stream media open source service platform easydarwin process
随机推荐
Rookie gospel, 28 books step by step to make you a big bull! (a copy of learning syllabus attached)
Android instance - simple login layout
Almost finished all the list titles, I found these things...
浅谈API网关(API Gateway)如何承载API经济生态链
Container technology (3) building local registry [15]
Installation and deployment of Flink
YoMo Codec - Y3的性能评测报告
Share tips on editing letters and mathematical formulas with MathType
Markdown plug-in of vscode
小程序调用原生onShareAppMessage分享,imageUrl参数是mp4格式怎么办
JS object array de duplication
容器技术(三)搭建本地 Registry【15】
dat.GUI 打造可视化工具(一)
How to use RTSP streaming component easypusher to push MP4 files to easydarwin open source platform?
The database executes truncate table cm_ CHECK_ ITEM_ How does his recover
都要2021年了,现代C++有什么值得我们学习的?
High performance library dpdk concise understanding
容器技术(三)镜像小结【16】
揭秘在召唤师峡谷中移动路径选择逻辑?
海外仓见证中欧跨境电商蓬勃发展