当前位置:网站首页>[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]所创,转载请带上原文链接,感谢
边栏推荐
- Kubernetes权限管理之RBAC (一)
- Flink的安装部署
- Abbyy finereader 15 added edit table cell function
- Revealing the logic of moving path selection in Summoner Canyon?
- C console calls ffmpeg to push MP4 video file to stream media open source service platform easydarwin process
- Ultra simple integration of Huawei system integrity testing, complete equipment security protection
- day83:luffy:添加购物车&导航栏购物车数字显示&购物车页面展示
- iOS下带小数点的数字键盘
- JS object array de duplication
- The basic principle of MRAM
猜你喜欢

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

都要2021年了,现代C++有什么值得我们学习的?

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

Almost finished all the list titles, I found these things...

40 tips for life that may be useful

骚操作!嵌套 JSON 秒变 Dataframe!

【STM32H7】第6章 ThreadX GUIX上手之STM32H7 DMA2D加速

Kubernetes权限管理之RBAC (一)

2020中国电信终端技术与标准论坛上专家解读四大热门产业

百亿级数据分表后怎么分页查询?
随机推荐
如何使用RTSP推流组件EasyPusher将MP4文件推到EasyDarwin开源平台?
配置ng-zerro的nz-date-picker时间选择组件
Nine kinds of distributed primary key ID generation schemes of sub database and sub table are quite comprehensive
ABBYY FineReader 15新增编辑页面布局功能
Gesture switch background, let live with goods more immersive
C#控制台调用FFMPEG推MP4视频文件至流媒体开源服务平台EasyDarwin过程
Abbyy finereader 15 adds editing page layout function
Git老鸟查询手册
【云小课】版本管理发展史之Git+——代码托管
【邀你投票】谁是2020年这些开源大事件背后的关键推动者?
Day83: Luffy: add shopping cart & navigation bar shopping cart digital display & shopping cart page display
It will be 2021. What is the modern C + + worth learning?
AQS源码深入分析之条件队列
Revealing the logic of moving path selection in Summoner Canyon?
RBAC of kubernetes authority management (1)
零基础小白python入门——深入Python中的文件操作
Introduction to zero base little white Python
Numeric keyboard with decimal point in IOS
云数据库的本质是什么?探究华为云数据库的核心价值
Leetcode 48 rotating image