ISBN接口调用失败?
[图片] 我在浏览器中请求该接口正常返回数据,[图片] 但是在小程序使用云函数调用该接口,返回信息却是appkey为空? 云函数代码: const appkey = '885595fd63350f83';
const cloud = require('wx-server-sdk')
const TcbRouter = require('tcb-router');
const rq = require('request');
cloud.init()
// 云函数入口函数
exports.main = async(event, context) => {
const app = new TcbRouter({
event
});
//根据isbn码获取图书详情信息
app.router('bookinfo', async(ctx) => {
ctx.body = new Promise(resolve => {
rq({
url: 'https://api.jisuapi.com/isbn/query?appkey=' + appkey + '&isbn=' + event.isbn,
method: "GET",
json: true,
}, function(error, response, body) {
resolve({
body: body
})
});
});
});
return app.serve();
}
调用代码: let that = this;
wx.cloud.callFunction({
name: 'books',
data: {
$url: "bookinfo", //云函数路由参数
isbn: bn
},
success: res => {
console.log(res);
if (res.result.body.status == 0) {
db.collection('books').add({
data: res.result.body.result,
success: function(res) {
wx.hideLoading();
that.setData({
bookinfo: res.result.body.result,
show_a: false,
show_b: true,
show_c: false,
active: 1,
})
},
fail: console.error
})
}else{
console.log("status not 0");
}
} ,
fail: err => {
console.error(err)
}
}) 控制台打印 res: [图片]