[关闭]
@cfygaoyang 2018-09-29T06:31:49.000000Z 字数 11759 阅读 834

阿里飞燕


安装


说明

该包只支持 python3 , 如果使用 python2.7版本, 请连接至python3版本

安装

pip install feiyan

示例


  1. from feiyan.http.api import Cloud
  2. # 密钥配置
  3. app_key = '123456'
  4. app_secret = '12345678901234567890'
  5. # 实例化接口类
  6. c = Cloud(app_key, app_secret)
  7. # 接口请求参数
  8. params = {'grantType': 'project', 'res': 'a1234567890'}
  9. # 调用 api 函数
  10. res = c.token(params)
  11. # 输出回调内容
  12. print(res.content)

api 函数清单和参数说明


获取云端资源Token

token(params)

  1. {
  2. "grantType": "project",
  3. "res": "xxxxxx"
  4. }
  1. {
  2. "code":200,
  3. "data":{
  4. "isolationId":"a103ZqtDOCpQJFE9",
  5. "expireIn":7200000,
  6. "cloudToken":"d76c34b338184c3a933c39c3ae0ce071"
  7. },
  8. "id":"1538185690705015"
  9. }

刷新云端资源Token

refresh_token(token)

  1. {
  2. "code":200,
  3. "data":{
  4. "isolationId":"a103ZqtDOCpQJFE9",
  5. "expireIn":7200000,
  6. "cloudToken":"d76c34b338184c3a933c39c3ae0ce071"
  7. },
  8. "id":"1538185690705015"
  9. }

查询物的产品列表

thing_product_list_get(params, token)

  1. {
  2. 'productInfoQuery': {
  3. "pageNo": 1,
  4. "pageSize": 10
  5. }
  6. }
  1. {
  2. "code": 200,
  3. "data": [{
  4. "accessMethod": "DATA_DIRECT",
  5. "gmtModified": 1536298985000,
  6. "modifier": "501eal0af73dcc8fcce483d2777957b3ed6a4980",
  7. "productKey": "a1234567890",
  8. "extendProperties": [{
  9. "extendAttrId": 16467,
  10. "gmtModify": 1536806017000,
  11. "domain": 0,
  12. "extendAttrKey": "ACTION",
  13. "extendAttrValue": "ON",
  14. "gmtCreate": 1529053672000,
  15. "productKey": "a1d9uTa3b7h",
  16. "extendAttrName": "允许作为ACTION"
  17. }],
  18. "categoryName": "空气净化器",
  19. "deviceNumLimit": 500000,
  20. "creator": "501eal0af73dcc8fcce483d2777957b3ed6a4980",
  21. "productId": 213797,
  22. "netType": "NET_WIFI",
  23. "dataFormaINK_FORMAT": "ALINK_FORMAT",
  24. "aliyunCommodityCode": "ilop",
  25. "useId2Auth": false,
  26. "productSecret": "1234567890",
  27. "categoryKey": "AirPurifier",
  28. "nodeType": "DEVICE",
  29. "gmtCreate": 1527663512000,
  30. "domain": "abc123456789",
  31. "name": "Breathe2",
  32. "region": "cn-shanghai",
  33. "rbacTenantId": "BAE4F5145D20416EA228A564AE5F2467",
  34. "categoryId": 83,
  35. "status": "RELEASE_STATUS"
  36. }],
  37. "id": "1538188889522421"
  38. }

查询物的产品

thing_product_get(params, token)

  1. {
  2. 'productKey': '1234567890'
  3. }
  1. {
  2. "code": 200,
  3. "data": {
  4. "accessMethod": "DATA_DIRECT",
  5. "gmtModified": 1536544723000,
  6. "modifier": "501eal0af73dcc8fcce483d2777957b3ed6a4980",
  7. "extendProperties": [{
  8. "extendAttrId": 8137,
  9. "gmtModify": 1536299101000,
  10. "domain": 0,
  11. "extendAttrKey": "PUBLIC_VERSION_APP",
  12. "extendAttrValue": "OFF",
  13. "gmtCreate": 1527663512000,
  14. "productKey": "1234567890",
  15. "extendAttrName": "加入公版APP标记"
  16. }, {
  17. "extendAttrId": 8134,
  18. "gmtModify": 1527000,
  19. "domain": 0,
  20. "extendAttrKey": "ILOP_SERVICE_GOOGLEHOME",
  21. "extendAttrValue": "OFF",
  22. "gmtCreate": 1527663512000,
  23. "productKey": "b1YEAzMF80d",
  24. "extendAttrName": "开通googleHome服"
  25. }],
  26. "productKey ": "b1YEAzMF80d ",
  27. "categoryName ": "空气净化器 ",
  28. "deviceNumLimit ": 500000,
  29. "creator": "501eal0af73dcc8fcce483d2777957b3ed6a4980",
  30. "productId": 123456,
  31. "dataFormat": "ALINK_FORMAT",
  32. "netType": "NET_WIFI",
  33. "useId2Auth": false,
  34. "aliyunCommodityCode": "ilop",
  35. "categoryKey": "AirPurifier",
  36. "productSecret": "1234567890",
  37. "nodeType": "DEVICE",
  38. "gmtCreate": 1527663512000,
  39. "domain": "b1YEAzMF80d",
  40. "name": "Breathe2",
  41. "region": "cn-shanghai",
  42. "rbacTenantId": "BAE4F5145D20416EA228A564AE5F2467",
  43. "categoryId": 83,
  44. "status": "RELEASE_STATUS"
  45. },
  46. "id": "1538189551927810"
  47. }

获取物的属性

thing_properties_get(params, token)

  1. {
  2. 'iotId': 'c69B4mcRz26v6JGLgOJD0010336900'
  3. }
  1. {
  2. "code": 200,
  3. "data": [{
  4. "iotId": "c69B4mcRz26v6JGLgOJD0010336900",
  5. "gmtModified": 1537871668144,
  6. "attribute": "AppointmentTime",
  7. "batchId": "f979237c50be4605881a4d2702cf6ead",
  8. "value": 108.0000000000000000
  9. }, {
  10. "iotId": "c69B4mcRz26v6JGLgOJD0010336900",
  11. "gmtModified": 1537871666958,
  12. "attribute": "CurrentTemperature",
  13. "batchId": "441b6438f292433badac829f6a463fcd",
  14. "value": 27.0000000000000000
  15. }, {
  16. "iotId": "c69B4mcRz26v6JGLgOJD0010336900",
  17. "gmtModified": 1537871668946,
  18. "attribute": "DeviceConfiguration",
  19. "batchId": "6af55fbd191f43009958d2303e380375",
  20. "value": {
  21. "MotorSpeedPWM_2": 27368,
  22. "MotorSpeedPWM_1": 11428,
  23. "CalibrationPM25": 0,
  24. "AlarmPM25": 30,
  25. "AlarmCO2": 1000,
  26. "CalibrationCO2": 0,
  27. "MotorSpeedPWM_3": 43156
  28. }
  29. }, {
  30. "iotId": "c69B4mcRz26v6JGLgOJD0010336900",
  31. "gmtModified": 1537871660604,
  32. "attribute": "_sys_device_pid",
  33. "batchId": "9d1b63b9-aace-49dc-8623-85eb41f9ef0d",
  34. "value": "AliOSThings"
  35. }],
  36. "id": "1538190327259799"
  37. }

获取物的模板

thing_tsl_get(params, token)

  1. {
  2. 'iotId': 'c69B4mcRz26v6JGLgOJD0010336900'
  3. }
  1. {
  2. "code": 200,
  3. "data": {
  4. "schema": "https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
  5. "profile": {
  6. "productKey": "a1d9uTa3b7h",
  7. "deviceName": "c69B4mcRz26v6JGLgOJD"
  8. },
  9. "link": "/sys/a1d9uTa3b7h/c69B4mcRz26v6JGLgOJD/thing/",
  10. "services": [{
  11. "outputData": [],
  12. "identifier": "set",
  13. "inputData": [{
  14. "identifier": "WIFI_Band",
  15. "dataType": {
  16. "specs": {
  17. "length": "255"
  18. },
  19. "type": "text"
  20. },
  21. "name": "频段"
  22. },
  23. {
  24. "identifier": "WIFI_AP_BSSID",
  25. "dataType": {
  26. "specs": {
  27. "length": "255"
  28. },
  29. "type": "text"
  30. },
  31. "name": "热点BSSID"
  32. }
  33. ],
  34. "identifier": "get",
  35. "inputData": [
  36. "LockState",
  37. "WIFI_Band",
  38. "WiFI_RSSI",
  39. "WIFI_AP_BSSID",
  40. "WIFI_Channel",
  41. "WiFI_SNR"
  42. ],
  43. "method": "thing.service.property.get",
  44. "name": "get",
  45. "required": true,
  46. "callType": "async",
  47. "desc": "属性获取"
  48. },
  49. {
  50. "outputData": [],
  51. "identifier": "AddKey",
  52. "inputData": [{
  53. "identifier": "LockType",
  54. "dataType": {
  55. "specs": {
  56. "1": "指纹",
  57. "2": "密码",
  58. "3": "卡",
  59. "4": "机械钥匙"
  60. },
  61. "type": "enum"
  62. },
  63. "name": "开锁方式"
  64. },
  65. {
  66. "identifier": "UserLimit",
  67. "dataType": {
  68. "specs": {
  69. "1": "普通用户",
  70. "2": "管理员",
  71. "3": "劫持用户"
  72. },
  73. "type": "enum"
  74. },
  75. "name": "用户权限"
  76. }
  77. ],
  78. "method": "thing.service.AddKey",
  79. "name": "添加钥匙",
  80. "required": true,
  81. "callType": "async"
  82. }
  83. ],
  84. "properties": [{
  85. "identifier": "LockState",
  86. "dataType": {
  87. "specs": {
  88. "0": "关闭",
  89. "1": "打开"
  90. },
  91. "type": "enum"
  92. },
  93. "name": "门锁状态",
  94. "accessMode": "r",
  95. "required": true
  96. }],
  97. "events": [{
  98. "outputData": [{
  99. "identifier": "LockState",
  100. "dataType": {
  101. "specs": {
  102. "0": "关闭",
  103. "1": "打开"
  104. },
  105. "type": "enum"
  106. },
  107. "name": "门锁状态"
  108. }],
  109. "identifier": "post",
  110. "method": "thing.event.property.post",
  111. "name": "post",
  112. "type": "info",
  113. "required": true,
  114. "desc": "属性上报"
  115. },
  116. {
  117. "outputData": [{
  118. "identifier": "ErrorCode",
  119. "dataType": {
  120. "specs": {
  121. "0": "正常"
  122. },
  123. "type": "enum"
  124. },
  125. "name": "故障代码"
  126. }],
  127. "identifier": "Error",
  128. "method": "thing.event.Error.post",
  129. "name": "故障上报",
  130. "type": "error",
  131. "required": true
  132. },
  133. {
  134. "outputData": [{
  135. "identifier": "KeyID",
  136. "dataType": {
  137. "specs": {
  138. "length": "10"
  139. },
  140. "type": "text"
  141. },
  142. "name": "钥匙ID"
  143. }],
  144. "identifier": "KeyAddedNotification",
  145. "method": "thing.event.KeyAddedNotification.post",
  146. "name": "添加钥匙通知",
  147. "type": "info",
  148. "required": true
  149. },
  150. {
  151. "outputData": [{
  152. "identifier": "LockType",
  153. "dataType": {
  154. "specs": {
  155. "1": "指纹",
  156. "2": "密码",
  157. "3": "卡",
  158. "4": "机械钥匙"
  159. },
  160. "type": "enum"
  161. },
  162. "name": "开锁方式"
  163. }],
  164. "identifier": "KeyDeletedNotification",
  165. "method": "thing.event.KeyDeletedNotification.post",
  166. "name": "删除钥匙通知",
  167. "type": "info",
  168. "required": true
  169. },
  170. {
  171. "outputData": [],
  172. "identifier": "TamperAlarm",
  173. "method": "thing.event.TamperAlarm.post",
  174. "name": "防撬报警",
  175. "type": "alert",
  176. "required": true
  177. }
  178. ]
  179. },
  180. "id": "1538190870103674"
  181. }

触发物的服务

thing_service_invoke(params, token)

  1. {
  2. "iotId": "D95D242941CE821ECCE4F31A2697",
  3. "identifier": "xxxx",
  4. "args": {}
  5. }
  1. {
  2. "code": 200,
  3. "data": {},
  4. "id": "1538190870103674"
  5. }

设置物的属性

thing_properties_set(params, token)

  1. {
  2. "iotId": "D95D242941CE821ECCE4F31A2697",
  3. "items": {}
  4. }
  1. {
  2. "code": 200,
  3. "data": {},
  4. "id": "1538190870103674"
  5. }

获取物的连接状态

thing_status_get(params, token)

  1. {
  2. "iotId": "D95D242941CE821ECCE4F31A2697"
  3. }
  1. {
  2. "code": 200,
  3. "data": {
  4. "time": 1537871888000,
  5. "status": 3
  6. },
  7. "id": "1538193184384915"
  8. }

获取物的基本信息

thing_info_get(params, token)

  1. {
  2. "iotId": "D95D242941CE821ECCE4F31A2697"
  3. }
  1. {
  2. "code": 200,
  3. "data": {
  4. "gmtModified": 1537871888000,
  5. "activeTime": 1537871662000,
  6. "deviceKey": "c69B4mcRz26v6JGLgOJD",
  7. "statusLast": 1,
  8. "productKey": "a1d9uTa3b7h",
  9. "gmtCreate": 1537856353000,
  10. "iotId": "c69B4mcRz26v6JGLgOJD0010336900",
  11. "deviceSecret": "Pcxnrhc1DikSMnZ48FUIH9brb1Rc5sYr",
  12. "name": "c69B4mcRz26v6JGLgOJD",
  13. "thingType": "DEVICE",
  14. "region": "cn-shanghai",
  15. "firmwareVersion": "app-1.0.0-20180925.1338",
  16. "rbacTenantId": "BAE4F5145D20416EA228A564AE5F2467",
  17. "status": 3
  18. },
  19. "id": "1538193367379207"
  20. }

批量获取物

things_info_get(params, token)

  1. {
  2. "productKey": "a1d9uTa3b7h",
  3. "status": 3,
  4. 'currentPage': 1,
  5. 'pageSize': 2
  6. }
  1. {
  2. "code": 200,
  3. "data": [{
  4. "gmtModified": 1534922756000,
  5. "activeTime": 1529651482000,
  6. "deviceKey": "rwpefi5N8sIPWBiL5LNc",
  7. "gmtCreate": 1529546182000,
  8. "productKey": "a1d9uTa3b7h",
  9. "statusLast": 1,
  10. "iotId": "rwpefi5N8sIPWBiL5LNc0010e16a00",
  11. "deviceSecret": "5Cjez2vpxJmAZyaNxLC6PCrK45OckBW6V+jv+KlO4Egl51dLNnK7CMa6j/W9ZKVV",
  12. "name": "rwpefi5N8sIPWBiL5LNc",
  13. "thingType": "DEVICE",
  14. "region": "cn-shanghai",
  15. "firmwareVersion": "app-1.0.0-20180705.1111",
  16. "rbacTenantId": "BAE4F5145D20416EA228A564AE5F2467",
  17. "status": 3
  18. }, {
  19. "gmtModified": 1537863306000,
  20. "activeTime": 1536842173000,
  21. "deviceKey": "YJSSBqiCaV8v57ez1yI8",
  22. "gmtCreate": 1529559542000,
  23. "productKey": "a1d9uTa3b7h",
  24. "statusLast": 1,
  25. "iotId": "YJSSBqiCaV8v57ez1yI80010c05e00",
  26. "deviceSecret": "18dP050cpclibg22/SUmXvF61v/C3zp6eOLymYDrypEl51dLNnK7CMa6j/W9ZKVV",
  27. "name": "YJSSBqiCaV8v57ez1yI8",
  28. "thingType": "DEVICE",
  29. "region": "cn-shanghai",
  30. "firmwareVersion": "app-1.0.0-20180903.2246",
  31. "rbacTenantId": "BAE4F5145D20416EA228A564AE5F2467",
  32. "status": 3
  33. }],
  34. "id": "1538193644477318"
  35. }

获取物的事件 timeline 数据

thing_event_timeline_get(params, token)

  1. {
  2. "iotId": "rwpefi5N8sIPWBiL5LNc0010e16a00",
  3. "identifier": "xxxx",
  4. "eventType": "Error",
  5. "start": 1517217645000,
  6. "end": 1587217645000,
  7. "pageSize": 10,
  8. "ordered": True
  9. }
  1. {
  2. "code":200,
  3. "data":{
  4. "items": [
  5. {
  6. "eventCode": "Error",
  7. "iotId": "YzqEnI5DY03rxLS2pjjo0010840500",
  8. "eventName": "故障上报",
  9. "eventType": "info",
  10. "eventBody": {
  11. "ErrorCode": 0
  12. },
  13. "batchId": "5ebc6a9c7d15459f823edde6d28c8fb3",
  14. "timestamp": 1516342985261
  15. },
  16. {
  17. "eventCode": "Error",
  18. "iotId": "YzqEnI5DY03rxLS2pjjo0010840500",
  19. "eventName": "故障上报",
  20. "eventType": "info",
  21. "eventBody": {
  22. "ErrorCode": 0
  23. },
  24. "batchId": "4a0b5a7ac85e470684438d5ff77456f1",
  25. "timestamp": 1516342995305
  26. }
  27. ],
  28. "timestamp": 1516343075699
  29. },
  30. "id":"1538194017374719"
  31. }

获取物的属性timeline数据

thing_property_timeline_get(params, token)

  1. {
  2. "iotId": "D95D242941CE821ECCE4F31A2697",
  3. "identifier": "xxxx",
  4. "start": 1517217645000,
  5. "end": 1517217645000,
  6. "pageSize": 10,
  7. "ordered": True
  8. }
  1. {
  2. "code": 200,
  3. "data": {
  4. "items": [
  5. {
  6. "iotid": "xqxyZjSKzCwaGdlvbv0O0010851c00",
  7. "data": 1.23,
  8. "modifytime": 1511812747287,
  9. "property": "LightVolt",
  10. "batchId": "2fc766c5e7064554933ed1f3e4b61803",
  11. "group": null,
  12. "timestamp": 1511812747245
  13. },
  14. {
  15. "iotid": "xqxyZjSKzCwaGdlvbv0O0010851c00",
  16. "data": 1.24,
  17. "modifytime": 1511812747288,
  18. "property": "LightVolt",
  19. "batchId": "2fc766c5e7064554933ed1f3e4b61803",
  20. "group": null,
  21. "timestamp": 1511812747245
  22. }
  23. ],
  24. "timestamp": 1511812747245
  25. },
  26. "id":"1538194017374719"
  27. }

分页查询用户列表

account_query_identity_by_page(params, token)

  1. {
  2. "offset": 0,
  3. "count": 1
  4. }
  1. {
  2. "code": 200,
  3. "data": [{
  4. "gmtModified": 1536931534000,
  5. "loginId": "36014",
  6. "nickName": "17681870200",
  7. "onlineStatus": 0,
  8. "gmtCreate": 1531462622000,
  9. "lastLoginTime": 1536931534000,
  10. "identityId": "50e1op23399ee0c1f32e84f78241f62eed2a6183",
  11. "loginName": "17681870200",
  12. "tenantId": "BAE4F5145D20416EA228A564AE5F2467",
  13. "loginSource": "openAccount",
  14. "status": "0"
  15. }],
  16. "id": "1538197847763446"
  17. }

通过三方外标查询账号信息

account_get_by_openid(params ,token)

  1. {
  2. "openId":"10000000001",
  3. "openIdAppKey":"xxx"
  4. }
  1. {
  2. "code": 200,
  3. "data": {
  4. "gmtModified": 1537952076000,
  5. "loginId": "56947",
  6. "nickName": "18150106733",
  7. "gmtCreate": 1537952076000,
  8. "lastLoginTime": 1537952076000,
  9. "identityId": "5099opcfba51921fe9d11157b6ad715a0c572941",
  10. "loginName": "18150106733",
  11. "tenantId": "BAE4F5145D20416EA228A564AE5F2467",
  12. "loginSource": "openAccount",
  13. "status": "0"
  14. },
  15. "id": "1538198838429908"
  16. }

获取用户绑定的设备列表(包括设备详情)详情内容

device_query_by_user(params ,token)

  1. {
  2. "openId":"10000000001",
  3. "openIdAppKey":"xxx"
  4. }
  1. {
  2. "code": 200,
  3. "data": {
  4. "code": 200,
  5. "data": [{
  6. "gmtModified": 1537870633000,
  7. "categoryImage": "http://iotx-paas-admin.oss-cn-shanghai.aliyuncs.com/publish/image/1526474025826.png",
  8. "netType": "NET_WIFI",
  9. "groupId": "",
  10. "nodeType": "DEVICE",
  11. "productKey": "b1YEAzMF80d",
  12. "gmtCreate": 1537870633000,
  13. "deviceName": "izLR74cr5WVKt0RDvkZA",
  14. "identityAlias": "15721595369",
  15. "productName": "Breathe2",
  16. "iotId": "izLR74cr5WVKt0RDvkZA0010f40d00",
  17. "owned": 0,
  18. "identityId": "5081opd8f24e72faeb45194bfabeff5355238011",
  19. "thingType": "DEVICE",
  20. "status": 1
  21. }, {
  22. "gmtModified": 1537843991000,
  23. "categoryImage": "http://iotx-paas-admin.oss-cn-shanghai.aliyuncs.com/publish/image/1526474025826.png",
  24. "netType": "NET_WIFI",
  25. "nickName": "BREATHE2",
  26. "groupId": "",
  27. "nodeType": "DEVICE",
  28. "productKey": "b1YEAzMF80d",
  29. "gmtCreate": 1537843897000,
  30. "deviceName": "OSp1Uuw3kDMBUQDznhWQ",
  31. "identityAlias": "15721595369",
  32. "productName": "Breathe2",
  33. "iotId": "OSp1Uuw3kDMBUQDznhWQ0010a98e00",
  34. "owned": 1,
  35. "identityId": "5081opd8f24e72faeb45194bfabeff5355238011",
  36. "thingType": "DEVICE",
  37. "status": 1
  38. }],
  39. "message": "success"
  40. },
  41. "id": "1538198926424070"
  42. }

解绑用户和设备

user_device_unbind(params, token)

  1. {
  2. "openId":"10000000001",
  3. "openIdAppKey":"xxx",
  4. "iotId": "zzzzzzzzzzzzzz"
  5. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注