113 lines
3.1 KiB
JavaScript
113 lines
3.1 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const modules_api_md5 = require("./md5.js");
|
|
function objectToQueryParams(obj) {
|
|
return Object.keys(obj).map((key) => encodeURIComponent(key) + "=" + encodeURIComponent(obj[key])).join("&");
|
|
}
|
|
var AppServer = function() {
|
|
};
|
|
var serverConfig = {};
|
|
var baseUrl = "https://music.shhuanmeng.com";
|
|
serverConfig.apiUrl_Music_GetMusicGenresList = baseUrl + "/api/Music/GetMusicGenresList";
|
|
serverConfig.apiUrl_Music_GetMusicGenresInfo = baseUrl + "/api/Music/GetMusicGenresInfo";
|
|
AppServer.prototype.getPostFormBody = function(postData) {
|
|
Object.assign({}, postData);
|
|
};
|
|
AppServer.prototype.getSign = function(postData) {
|
|
let arr = [];
|
|
for (let key in postData) {
|
|
if (key == "sign")
|
|
continue;
|
|
arr.push(key);
|
|
}
|
|
arr.sort();
|
|
let str = "";
|
|
for (let i in arr) {
|
|
let value = postData[arr[i]];
|
|
if (value || value == 0) {
|
|
str += value;
|
|
}
|
|
}
|
|
let saltKey = "";
|
|
try {
|
|
let token = common_vendor.index.getStorageSync("token");
|
|
if (token) {
|
|
saltKey = token.split(".")[2];
|
|
}
|
|
} catch (e) {
|
|
saltKey = "";
|
|
}
|
|
str += saltKey;
|
|
let sign = modules_api_md5.md5(str);
|
|
return sign;
|
|
};
|
|
AppServer.prototype.postData = async function(url, postData) {
|
|
let authToken = common_vendor.index.getStorageSync("token");
|
|
return common_vendor.index.request({
|
|
url,
|
|
method: "POST",
|
|
header: {
|
|
"Content-Type": "application/json",
|
|
"Authorization": authToken
|
|
},
|
|
data: JSON.stringify(postData)
|
|
}).then((res) => {
|
|
console.log(`post,url=${url},form=${formBody},response=${res.data}`);
|
|
return res.data;
|
|
}).catch((err) => {
|
|
console.error(err);
|
|
return err;
|
|
});
|
|
};
|
|
AppServer.prototype.getData = async function(url, postData) {
|
|
let authToken = common_vendor.index.getStorageSync("token");
|
|
if (postData != null) {
|
|
var parmat = objectToQueryParams(postData);
|
|
if (url.indexOf("?") > -1) {
|
|
url += "&" + parmat;
|
|
} else {
|
|
url += "?" + parmat;
|
|
}
|
|
}
|
|
return common_vendor.index.request({
|
|
url,
|
|
method: "GET",
|
|
header: {
|
|
"Authorization": authToken
|
|
}
|
|
// data: JSON.stringify(postData)
|
|
}).then((res) => {
|
|
console.log(`post,url=${url},response=${res.data}`);
|
|
return res.data;
|
|
}).catch((err) => {
|
|
console.error(err);
|
|
return err;
|
|
});
|
|
};
|
|
AppServer.prototype.GetMusicGenresList = async function() {
|
|
var url = serverConfig.apiUrl_Music_GetMusicGenresList;
|
|
return this.getData(url).then((data) => {
|
|
return data;
|
|
});
|
|
};
|
|
AppServer.prototype.GetServerList = async function() {
|
|
return this.postData(serverConfig.apiUrl_AppConfig_GetServerList).then((data) => {
|
|
console.log(data);
|
|
});
|
|
};
|
|
AppServer.prototype.GetPlatformIsAndroid = function() {
|
|
let port = common_vendor.index.getSystemInfoSync().platform;
|
|
switch (port) {
|
|
case "android":
|
|
console.log("运行Android上", port);
|
|
return true;
|
|
case "ios":
|
|
console.log("运行iOS上", port);
|
|
return false;
|
|
default:
|
|
console.log("运行在开发者工具上");
|
|
return false;
|
|
}
|
|
};
|
|
exports.AppServer = AppServer;
|