30 lines
894 B
JavaScript
30 lines
894 B
JavaScript
"use strict";
|
|
const common_vendor = require("./vendor.js");
|
|
const common_config = require("./config.js");
|
|
function buildUrl(path) {
|
|
if (!path)
|
|
return common_config.API_BASE_URL;
|
|
if (path.startsWith("http"))
|
|
return path;
|
|
return common_config.API_BASE_URL + (path.startsWith("/") ? path : "/" + path);
|
|
}
|
|
function get(path, params = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
common_vendor.index.request({
|
|
url: buildUrl(path),
|
|
method: "GET",
|
|
data: params,
|
|
header: { "X-Shop-Id": common_config.SHOP_ID },
|
|
success: (res) => {
|
|
const { statusCode, data } = res;
|
|
if (statusCode >= 200 && statusCode < 300)
|
|
return resolve(data);
|
|
reject(new Error("HTTP " + statusCode));
|
|
},
|
|
fail: (err) => reject(err)
|
|
});
|
|
});
|
|
}
|
|
exports.get = get;
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/http.js.map
|