当前位置:网站首页>[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]所创,转载请带上原文链接,感谢
边栏推荐
- PHP - cURL复制粘贴性接入短信验证码示例
- Kubernetes权限管理之RBAC (一)
- A great guide to curl
- Markdown plug-in of vscode
- From Silicon Valley to Xiaomi, Cui Baoqiu's 25 years of open source life
- Simple implementation of activity workflow interactive demo
- Rabbitmq installation
- mongodb 源码实现系列 - 网络传输层模块实现三
- Android软键盘遮挡的四种解决方案
- In the third stage, day19 users echo packaged cookie products and remotely call Shopping Cart module crud operation
猜你喜欢
Abbyy finereader 15 adds editing page layout function
AQS源码深入分析之条件队列
[最佳实践]了解 Eolinker 如何助力远程办公
How the API gateway carries the API economic ecological chain
Kubernetes权限管理之RBAC (一)
Git old bird search manual
浅谈API网关(API Gateway)如何承载API经济生态链
菜鸟福音,28本书籍循序渐进让你成为大牛!(附学习大纲一份)
非常值得一看的 Curl 用法指南
Experts' interpretation of four hot industries in 2020 China telecom terminal technology and Standards Forum
随机推荐
小程序调用原生onShareAppMessage分享,imageUrl参数是mp4格式怎么办
Ultra simple integration of Huawei system integrity testing, complete equipment security protection
RBAC of kubernetes authority management (1)
PHP - cURL复制粘贴性接入短信验证码示例
ABBYY FineReader 15 新增编辑表格单元格功能
Defects in singleton mode of DCL and other implementations of singleton
Using powerful powerbi Sangji diagram to express complex operation business flow
Configure the NZ date picker time selection component of ng zerro
A practical chrome Gadget: xtrace
菜鸟福音,28本书籍循序渐进让你成为大牛!(附学习大纲一份)
Numeric keyboard with decimal point in IOS
上云嘉年华,超低价云服务器来袭
dat.GUI Creating visualization tools (1)
Introduction to zero base little white Python
ABBYY FineReader 15新增编辑页面布局功能
2020中国电信终端技术与标准论坛上专家解读四大热门产业
How to implement a simple student management system with C + +
几乎刷完了力扣所有的链表题,我发现了这些东西。。。
JT-day10
运用强大的 PowerBI 桑基图表示复杂运营业务流