当前位置:网站首页>[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]所创,转载请带上原文链接,感谢
边栏推荐
- ABBYY FineReader 15新增编辑页面布局功能
- How to gracefully prevent switch switching of view UI?
- 40 tips for life that may be useful
- Gesture switch background, let live with goods more immersive
- How to implement a simple student management system with C + +
- How to use binary search algorithm
- 【STM32H7】第6章 ThreadX GUIX上手之STM32H7 DMA2D加速
- 分享用MathType编辑字母与数学公式的技巧
- How to edit summation formula in MathType
- In the third stage, the day20 Shopping Cart module is added, the interceptor is added, the user authority is checked, and the order module is realized
猜你喜欢

如何运用二分查找算法

What is the essence of cloud database? Explore the core value of Huawei cloud database

EMQ X 在中国建设银行物联网平台中的应用

DCL单例模式中的缺陷及单例模式的其他实现

第三阶段 Day19 用户回显 封装Cookie 商品远程调用 购物车模块 CRUD操作

超简单集成华为系统完整性检测,搞定设备安全防护

解析:C++如何实现简单的学生管理系统(源码分享)

【神级操作】 以中国传统的孔子和老子的思想,来分析忍者代码!

Installation and deployment of Flink

又一道比较运算符相关的面试题让我明白基础很重要
随机推荐
传统采购模式已变!汽车采购职能该如何创新?
LeetCode 48 旋转图像
C#控制台调用FFMPEG推MP4视频文件至流媒体开源服务平台EasyDarwin过程
[God level operation] analyze the Ninja code with the traditional Chinese thoughts of Confucius and Laozi!
js对象数组去重
【神级操作】 以中国传统的孔子和老子的思想,来分析忍者代码!
How the API gateway carries the API economic ecological chain
dat.GUI 打造可视化工具(一)
A practical chrome Gadget: xtrace
如何使用RTSP推流组件EasyPusher将MP4文件推到EasyDarwin开源平台?
[最佳实践]了解 Eolinker 如何助力远程办公
Git老鸟查询手册
磁阻式随机存储器MRAM基本原理
What is the essence of cloud database? Explore the core value of Huawei cloud database
运用强大的 PowerBI 桑基图表示复杂运营业务流
Share tips on editing letters and mathematical formulas with MathType
Almost finished all the list titles, I found these things...
PHP - curl copy paste access SMS verification code example
iOS下带小数点的数字键盘
手把手教你使用容器服务 TKE 集群审计排查问题