content发送1-4之间的消息能够正常回复,一发5、6就不行,看后台的情况是无法获取到data
代码如下:
1 2 3 4 5 6 7 8 9 10 | else if (content === '5' ){ var data = yield wechatApi.uploadMaterial( 'image' ,path.join(__dirname, '/2.jpg' )) reply = { type: 'image' , mediaId: data.media_id } console.log(data) console.log(reply) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | Wechat.prototype.uploadMaterial = function (type, filepath){ var that = this var form = { //构造一个表单 media: fs.createReadStream(filepath) } var appID = this .appID var appSecret = this .appSecret // var url = api.accessToken + '&appid=' + appID + '&secret=' + appSecret return new Promise( function (resolve,reject){ //Promise 实例 that .fetchAccessToken() .then( function (data){ var url = api.upload + 'access_token=' + data. access_token + '&type=' + type request({methos: 'POST' ,url: url, formData:form, json: true }).then( function (response){ var _data = response[1] if (_data){ resolve(_data) console.log(_data) } else { throw new Error( 'Upload material fails' ) } }) . catch ( function (err){ reject(err) }) }) }) } |