content发送1-4之间的消息能够正常回复,一发5、6就不行,看后台的情况是无法获取到data
代码如下:
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) }
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) }) }) }) }