时间:2019-04-30 来源:小程序工厂
const request = require('request-promise');
exports.main = (event, context) => {
let cityID = event.cityID;
const options = {
method: 'GET',
url: 'http://d1.weather.com.cn/sk_2d/101010100.html',
header: {
Referer: 'http://www.weather.com.cn/weather1d/101010100.shtml'
},
json: true
};
return await request(options);
}
参考
首先安装 request-promise
npm 命令 npm install request-promise
// 云函数入口文件
const cloud = require('wx-server-sdk')
//npm install request-promise
const rp = require('request-promise');
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
//appid 和秘钥 jscode
const appid = 'wxxxxxxxx',
secret = 'xxxxxxxxxxxx',_JSCODE='';
const AccessToken_options = {
method: 'GET',
url: 'https://api.weixin.qq.com/sns/jscode2session',
qs: {
appid,
secret,
grant_type:'authorization_code'
js_code:_JSCODE
},
json: true
};
const resultValue = await rp(AccessToken_options);
return { resultValue }
}