-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
41 lines (37 loc) · 1.15 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Created by zerob13 on 2/9/17.
*/
import fetch from 'node-fetch';
import iconvLite from 'iconv-lite';
const END_POINT = 'http://open.memobird.cn/home';
const BIND_USER = '/setuserbind';
const PRINT_PAPER = '/printpaper';
export function bindUser(ak, timestamp, memobirdID, useridentifying) {
let query = END_POINT + BIND_USER + '?ak=' + ak + '×tamp=' + timestamp
+ '&memobirdID=' + memobirdID + '&useridentifying=' + useridentifying;
return fetch(encodeURI(query))
.then(res => res.json());
}
export function printPaper(ak, timestamp, printcontent, type, memobirdID, userID) {
let content;
if (type === 'T') {
content = Buffer.from(iconvLite.encode(printcontent, 'gbk')).toString('base64');
} else if (type === 'P') {
content = printcontent;
}
let query = END_POINT + PRINT_PAPER;
return fetch(query, {
method: 'POST',
body: JSON.stringify({
'ak': ak, 'timestamp': timestamp,
'printcontent': type + ':' + content,
'memobirdID': memobirdID,
'userID': userID
}),
headers: {'Content-Type': 'application/json'},
})
.then((res) => {
let re = res.json();
return re;
});
}