UNPKG

5.3 kBJavaScriptView Raw
1'use strict';
2
3var util = require('./util');
4var wrapper = util.wrapper;
5var postJSON = util.postJSON;
6var make = util.make;
7
8make(exports, 'transferMessage', function (deviceType, deviceId, openid, content, callback) {
9 // https://api.weixin.qq.com/device/transmsg?access_token=ACCESS_TOKEN
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
20make(exports, 'transferStatus', function (deviceType, deviceId, openid, status, callback) {
21 // https://api.weixin.qq.com/device/transmsg?access_token=ACCESS_TOKEN
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
33make(exports, 'createDeviceQRCode', function (deviceIds, callback) {
34 // https://api.weixin.qq.com/device/create_qrcode?access_token=ACCESS_TOKEN
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
43make(exports, 'authorizeDevices', function (devices, optype, productid, callback) {
44 // https://api.weixin.qq.com/device/authorize_device?access_token=ACCESS_TOKEN
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//第三方公众账号通过设备id从公众平台批量获取设备二维码。
60make(exports, 'getDeviceQRCode', function (product_id, callback) {
61 // https://api.weixin.qq.com/device/create_qrcode?access_token=ACCESS_TOKEN
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
66make(exports, 'bindDevice', function (deviceId, openid, ticket, callback) {
67 // https://api.weixin.qq.com/device/bind?access_token=ACCESS_TOKEN
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
77make(exports, 'unbindDevice', function (deviceId, openid, ticket, callback) {
78 // https://api.weixin.qq.com/device/unbind?access_token=ACCESS_TOKEN
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
89make(exports, 'compelBindDevice', function (deviceId, openid, callback) {
90 // https://api.weixin.qq.com/device/compel_bind?access_token=ACCESS_TOKEN
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
99make(exports, 'compelUnbindDevice', function (deviceId, openid, callback) {
100 // https://api.weixin.qq.com/device/compel_unbind?access_token=ACCESS_TOKEN
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
109make(exports, 'getDeviceStatus', function (deviceId, callback) {
110 // https://api.weixin.qq.com/device/get_stat?access_token=ACCESS_TOKEN&device_id=DEVICE_ID
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
115make(exports, 'verifyDeviceQRCode', function (ticket, callback) {
116 // https://api.weixin.qq.com/device/verify_qrcode?access_token=ACCESS_TOKEN
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
124make(exports, 'getOpenID', function (deviceId, deviceType, callback) {
125 // https://api.weixin.qq.com/device/get_openid?access_token=ACCESS_TOKEN&device_type=DEVICE_TYPE&device_id=DEVICE_ID
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
130make(exports, 'getBindDevice', function (openid, callback) {
131 // https://api.weixin.qq.com/device/get_bind_device?access_token=ACCESS_TOKEN&openid=OPENID
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});