每日运势小程序
This commit is contained in:
39
DailyFortuneGuide/services/fortuneService.js
Normal file
39
DailyFortuneGuide/services/fortuneService.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const config = require("../config/index");
|
||||
|
||||
function post(endpoint, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof tt === "undefined" || !tt.request) {
|
||||
reject(new Error("request_api_unavailable"));
|
||||
return;
|
||||
}
|
||||
|
||||
tt.request({
|
||||
url: `${config.apiBaseUrl}${endpoint}`,
|
||||
method: "POST",
|
||||
data,
|
||||
timeout: 60000,
|
||||
success(response) {
|
||||
const { statusCode, data: payload } = response;
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
resolve(payload);
|
||||
return;
|
||||
}
|
||||
const error = new Error("request_failed");
|
||||
error.statusCode = statusCode;
|
||||
error.data = payload;
|
||||
reject(error);
|
||||
},
|
||||
fail(error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function analyzeFortune(payload) {
|
||||
return post("/api/daily-fortune/analyze", payload);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
analyzeFortune
|
||||
};
|
||||
Reference in New Issue
Block a user