Skip to content

Commit

Permalink
fix: 处理第三方接口异常提醒
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiu-Jun committed May 3, 2023
1 parent e74c672 commit 490ded2
Showing 1 changed file with 36 additions and 47 deletions.
83 changes: 36 additions & 47 deletions app/service/notifyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,66 +36,55 @@ class NotifyUtils extends Service {

// 获取随机励志吉言
async getLizhi() {
try {
const { app } = this
const res = await app.curl(apiUrl.words, {
method: 'GET',
dataType: 'json'
})
const { app } = this
const res = await app.curl(apiUrl.words, {
method: 'GET',
dataType: 'json'
})
if(res.status === 200) {
return res.data.hitokoto || null
} catch (error) {
return null
} else {
throw new Error("随机励志吉言获取失败,这是一个免费的借口")
}
}

// 获取天气
async getWether() {
try {
const { app, service } = this
// let cityData = fs.readFileSync('./utils/usercity.json', 'utf8')
let cityData = app.config.userCity || null
if(!cityData) return null
const res = await app.curl(`${apiUrl.gdWether}`, {
method: 'GET',
dataType: 'json',
data: {
key: app.config.apiConfig.amap.appKey,
city: app.config.userData.city,
city: cityData.adcode
}
})

if(res.status === 200 && res.data.status === '1') {
const wether = res.data.lives[0]
return wether
} else {
return null
const { app, service } = this
// let cityData = fs.readFileSync('./utils/usercity.json', 'utf8')
let cityData = app.config.userCity || null
if(!cityData) return null
const res = await app.curl(`${apiUrl.gdWether}`, {
method: 'GET',
dataType: 'json',
data: {
key: app.config.apiConfig.amap.appKey,
city: app.config.userData.city,
city: cityData.adcode
}


} catch (error) {
console.log(error)
return null
})

if(res.status === 200 && res.data.status === '1') {
const wether = res.data.lives[0]
return wether
} else {
throw new Error('天气接口请求失败')
}

}

// 获取彩虹屁
async getCaihongPi() {
try {
const { app } = this
const res = await app.curl(`${apiUrl.tianxing}/caihongpi/index?key=${app.config.apiConfig.tianxingKey}`, {
method: 'GET',
dataType: 'json'
})
if(res.status === 200 && res.data.code === 200) {
return res.data.newslist[0].content
} else {
return null
}
} catch (error) {
return null
const { app } = this
const res = await app.curl(`${apiUrl.tianxing}/caihongpi/index?key=${app.config.apiConfig.tianxingKey}`, {
method: 'GET',
dataType: 'json'
})
if(res.status === 200 && res.data.code === 200) {
return res.data.newslist[0].content
} else {
throw new Error('第三方天行彩虹屁接口请求失败')
}

}

// aiText
Expand Down

0 comments on commit 490ded2

Please sign in to comment.