007 nodejs服务端api接口内请求另一api接口

  • 方法一:

  • 目标接口地址

https://api.q.qq.com/sns/jscode2session?appid=' + qq.APPID + '&secret=' + qq.APPSECRET + '&js_code=' + req.query.code + '&grant_type=authorization_code
  • 请求实现

// QQ小程序配置信息
const qq = require('../config/Config')

router.get('/onLogin', function (req, res) {
  const url = 'https://api.q.qq.com/sns/jscode2session?appid=' + qq.APPID + '&secret=' + qq.APPSECRET + '&js_code=' + req.query.code + '&grant_type=authorization_code'
  request.get(url, function (req,resp, res) {
    console.log(res)
  })

方法二:推荐

npm install -g xd-synchttp
const sync = require('xd-synchttp');

let content = "";
const url = 'www.baidu.com';
try{
    content = sync.http_get(url,0);
    //0为不超时,其他数值为超时秒数
}
catch(err)
{
    console.log(err);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章