收藏
回答

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",
                        jsontrue,
                  }, function(error, response, body{
                        resolve({
                              body: body
                        })
                  });
            });
      });
      return app.serve();
}






调用代码:            let that = this;
            wx.cloud.callFunction({
                  name'books',
                  data: {
                        $url"bookinfo"//云函数路由参数
                        isbn: bn
                  },
                  successres => {
                        console.log(res);
                        if (res.result.body.status == 0) {
                              
                              db.collection('books').add({
                                    data: res.result.body.result,
                                    successfunction(res{
                                          wx.hideLoading();
                                          that.setData({
                                                bookinfo: res.result.body.result,
                                                show_afalse,
                                                show_btrue,
                                                show_cfalse,
                                                active1,
                                          })
                                    },
                                    failconsole.error
                              })
                        }else{
                              console.log("status not 0");
                        }
                  } ,
                  failerr => {
                        console.error(err)
                  } 

            })

控制台打印 res:

最后一次编辑于  2021-05-26
回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2021-05-26

    2021-05-26
    有用 1
    回复 8
    • 迷人.
      迷人.
      2021-05-26
      您好,感谢您的解答,我使用了您的云函数进行测试,为什么返回的数据跟您的不太一样?
      2021-05-26
      回复
    • 迷人.
      迷人.
      2021-05-26
      2021-05-26
      回复
    • Mr.Zhao
      Mr.Zhao
      发表于移动端
      2021-05-26回复迷人.
      亮代码
      2021-05-26
      回复
    • 迷人.
      迷人.
      2021-05-26回复Mr.Zhao
      2021-05-26
      回复
    • Mr.Zhao
      Mr.Zhao
      发表于移动端
      2021-05-26回复迷人.
      package.json也看下
      2021-05-26
      回复
    查看更多(3)
登录 后发表内容