const appKey = "k5hfiei5eevouvjohkapjaudpk2gakpaxha22fiy"; const appSecret = "e65ffb25148b08207088148d5bce114d"; function constructParameter(body) { let params = []; for (let key in body) { params.push(body[key].toString()); } params.sort(); let digest = ""; for (let param of params) { console.log(param) digest += param; } let sha1 = require('sha1'); body.signature = sha1(digest).toUpperCase(); let p = ''; for (let key in body) { p += key; p += "="; p += encodeURIComponent(body[key]); p += "&"; } p = p.slice(0, -1); return p; } const yzs = { get_access_token: function (ip, flushToken) { let body = {}; body.subsystemId = 16; body.clientId = ip; body.timestamp = parseInt(new Date().getTime() / 1000); body.flushToken = flushToken; return fetch("http://116.198.37.53:8080/rest/v2/token/get_access_token", { method: "POST", body: constructParameter(body), headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', }, }).then(response => response.json()).then((json) => { console.log(json); return json.result.accessToken; }).catch(error => { console.log(error); }); }, update_access_token: function (ip, accessToken) { let body = {}; body.subsystemId = 16; body.clientId = ip; body.timestamp = parseInt(new Date().getTime() / 1000); body.accessToken = accessToken; return fetch("http://116.198.37.53:8080/rest/v2/token/refresh_access_token", { method: "POST", body: constructParameter(body), headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', }, }).then(response => response.json()).then((json) => { console.log(json); return json.result.accessToken; }).catch(error => { console.log(error); }); }, get_user_info: function (ip, accessToken) { let body = {}; body.subsystemId = 16; body.clientId = ip; body.timestamp = parseInt(new Date().getTime() / 1000); body.accessToken = accessToken; return fetch("http://116.198.37.53:8080/rest/v2/user/get_user_info", { method: "POST", body: constructParameter(body), headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', }, }).then(response => response.json()).then((json) => { console.log(json); return json.result; }).catch(error => { console.log(error); }); }, user_select: function (ip, accessToken) { let sha256 = require('sha256'); let timestamp = new Date().getTime(); let sig = appKey + timestamp.toString() + appSecret; sig = sha256(sig).toUpperCase();; let url = `/api/app/app-voice-recorder/rest/v1/user/select?accessToken=${encodeURIComponent(accessToken)}&phoneUdid=${encodeURIComponent(ip)}`; console.log("url: ", url) return fetch(url, { headers: { 'appKey': appKey, 'timestamp': timestamp, 'signature': sig, }, }).then(response => { console.log(response); response.text() }).then((json) => { console.log(json) return json; }); }, get_record_list: function (accessToken, passportId) { let sha256 = require('sha256'); let timestamp = new Date().getTime(); let sig = appKey + timestamp.toString() + appSecret; sig = sha256(sig).toUpperCase();; let url = `/api/app/app-voice-recorder/rest/v1/trans/info/list?accessToken=${encodeURIComponent(accessToken)}&passportId=${passportId}`; console.log("url: ", url) return fetch(url, { headers: { 'appKey': appKey, 'timestamp': timestamp, 'signature': sig, }, }).then(response => { console.log(response); response.text() }).then((json) => { console.log(json) return json; }); }, login: function (ip) { let md5 = require('md5'); let body = {}; body.subsystemId = 16; body.clientId = ip; body.timestamp = parseInt(new Date().getTime() / 1000); body.account = "13682423271"; body.password = md5("yzs123456"); return fetch("http://116.198.37.53:8080/rest/v2/user/login", { method: "POST", body: constructParameter(body), // mode: "no-cors", headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', "Access-Control-Allow-Origin": "*", }, }).then(response => response.json()).then((json) => { console.log("flushToken: ", json.result.flushToken); return json.result.flushToken; }).catch(error => { console.log(error); }); } }; export default yzs;