https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
为什么在云函数入口块里面使用request会报错无法识别wx.呢?麻烦帮看一下,谢谢
errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID e6cfc5a3-85dd-11ea-9942-525400a6bef5, cloud function service error code -504002, error message wx is not defined
ReferenceError: wx is not defined
const https = require('https')
http://nodejs.cn/api/https.html#https_https_get_url_options_callback
// 云函数入口文件 const cloud = require('wx-server-sdk') const https = require("https"); cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 云函数入口函数 exports.main = async(event, context) => { const wxContext = cloud.getWXContext() let randomV = function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; //不含最大值,含最小值 } console.log(randomV(0, 4294967295)) let randomVO = randomV(0, 4294967295); return new Promise(rs, rj=>{ const postData = querystring.stringify({ "From_Account": "test1234", "StartIndex": 0, "StandardSequence": 0, "CustomSequence": 0 }); const options = { hostname: 'console.tim.qq.com', port: 443, path: '/v4/sns/friend_get?sdkappid=1400328244&identifier=admin&usersig=xxx&random=99999999&contenttype=json', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } }; const req = https.request(options, (res) => { console.log(`状态码: ${res.statusCode}`); console.log(`响应头: ${JSON.stringify(res.headers)}`); res.setEncoding('utf8'); var res = ''; res.on('data', (chunk) => { res += chunk }); res.on('end', () => { rs({ event, resData: res, openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID, }) }); }); req.on('error', (e) => { rj(e.message); }); // 将数据写入请求主体。 req.write(postData); req.end(); }) }
若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人
由于我是初学者,哈哈哈哈,不知道不能这样用,谢谢大神指路啦,谢谢
网络请求需要自己去实现的哦 wx.request是仅在小程序端使用的
wx只能用在小程序端。
请求网络要自己实现,不能在使用wx接口了