1 | 'use strict';
|
2 |
|
3 | var util = require('./util');
|
4 | var wrapper = util.wrapper;
|
5 | var postJSON = util.postJSON;
|
6 | var make = util.make;
|
7 |
|
8 | make(exports, 'transferMessage', function (deviceType, deviceId, openid, content, callback) {
|
9 |
|
10 | var url = this.endpoint + '/device/transmsg?access_token=' + this.token.accessToken;
|
11 | var info = {
|
12 | 'device_type': deviceType,
|
13 | 'device_id': deviceId,
|
14 | 'open_id': openid,
|
15 | 'content': new Buffer(content).toString('base64')
|
16 | };
|
17 | this.request(url, postJSON(info), wrapper(callback));
|
18 | });
|
19 |
|
20 | make(exports, 'transferStatus', function (deviceType, deviceId, openid, status, callback) {
|
21 |
|
22 | var url = this.endpoint + '/device/transmsg?access_token=' + this.token.accessToken;
|
23 | var info = {
|
24 | 'device_type': deviceType,
|
25 | 'device_id': deviceId,
|
26 | 'open_id': openid,
|
27 | 'msg_type': '2',
|
28 | 'device_status': status
|
29 | };
|
30 | this.request(url, postJSON(info), wrapper(callback));
|
31 | });
|
32 |
|
33 | make(exports, 'createDeviceQRCode', function (deviceIds, callback) {
|
34 |
|
35 | var url = this.endpoint + '/device/create_qrcode?access_token=' + this.token.accessToken;
|
36 | var info = {
|
37 | 'device_num': deviceIds.length,
|
38 | 'device_id_list': deviceIds
|
39 | };
|
40 | this.request(url, postJSON(info), wrapper(callback));
|
41 | });
|
42 |
|
43 | make(exports, 'authorizeDevices', function (devices, optype, productid, callback) {
|
44 |
|
45 | var url = this.endpoint + '/device/authorize_device?access_token=' + this.token.accessToken;
|
46 | var data = {
|
47 | 'device_num': devices.length,
|
48 | 'device_list': devices,
|
49 | 'op_type': optype
|
50 | };
|
51 | if (typeof productid !== 'function') {
|
52 | data.product_id = productid;
|
53 | } else {
|
54 | callback = productid;
|
55 | }
|
56 | this.request(url, postJSON(data), wrapper(callback));
|
57 | });
|
58 |
|
59 |
|
60 | make(exports, 'getDeviceQRCode', function (product_id, callback) {
|
61 |
|
62 | var url = this.endpoint + '/device/getqrcode?access_token=' + this.token.accessToken + '&product_id=' + product_id;
|
63 | this.request(url, {dataType: 'json'}, wrapper(callback));
|
64 | });
|
65 |
|
66 | make(exports, 'bindDevice', function (deviceId, openid, ticket, callback) {
|
67 |
|
68 | var url = this.endpoint + '/device/bind?access_token=' + this.token.accessToken;
|
69 | var data = {
|
70 | ticket: ticket,
|
71 | device_id: deviceId,
|
72 | openid: openid
|
73 | };
|
74 | this.request(url, postJSON(data), wrapper(callback));
|
75 | });
|
76 |
|
77 | make(exports, 'unbindDevice', function (deviceId, openid, ticket, callback) {
|
78 |
|
79 | var url = this.endpoint + '/device/unbind?access_token=' + this.token.accessToken;
|
80 | var data = {
|
81 | ticket: ticket,
|
82 | device_id: deviceId,
|
83 | openid: openid
|
84 | };
|
85 | this.request(url, postJSON(data), wrapper(callback));
|
86 | });
|
87 |
|
88 |
|
89 | make(exports, 'compelBindDevice', function (deviceId, openid, callback) {
|
90 |
|
91 | var url = this.endpoint + '/device/compel_bind?access_token=' + this.token.accessToken;
|
92 | var data = {
|
93 | device_id: deviceId,
|
94 | openid: openid
|
95 | };
|
96 | this.request(url, postJSON(data), wrapper(callback));
|
97 | });
|
98 |
|
99 | make(exports, 'compelUnbindDevice', function (deviceId, openid, callback) {
|
100 |
|
101 | var url = this.endpoint + '/device/compel_unbind?access_token=' + this.token.accessToken;
|
102 | var data = {
|
103 | device_id: deviceId,
|
104 | openid: openid
|
105 | };
|
106 | this.request(url, postJSON(data), wrapper(callback));
|
107 | });
|
108 |
|
109 | make(exports, 'getDeviceStatus', function (deviceId, callback) {
|
110 |
|
111 | var url = this.endpoint + '/device/get_stat?access_token=' + this.token.accessToken + '&device_id=' + deviceId;
|
112 | this.request(url, {dataType: 'json'}, wrapper(callback));
|
113 | });
|
114 |
|
115 | make(exports, 'verifyDeviceQRCode', function (ticket, callback) {
|
116 |
|
117 | var url = this.endpoint + '/device/verify_qrcode?access_token=' + this.token.accessToken;
|
118 | var data = {
|
119 | ticket: ticket
|
120 | };
|
121 | this.request(url, postJSON(data), wrapper(callback));
|
122 | });
|
123 |
|
124 | make(exports, 'getOpenID', function (deviceId, deviceType, callback) {
|
125 |
|
126 | var url = this.endpoint + '/device/get_openid?access_token=' + this.token.accessToken + '&device_id=' + deviceId + '&device_type=' + deviceType;
|
127 | this.request(url, {dataType: 'json'}, wrapper(callback));
|
128 | });
|
129 |
|
130 | make(exports, 'getBindDevice', function (openid, callback) {
|
131 |
|
132 | var url = this.endpoint + '/device/get_bind_device?access_token=' + this.token.accessToken + '&openid=' + openid;
|
133 | this.request(url, {dataType: 'json'}, wrapper(callback));
|
134 | });
|