在获取图文消息的时候response回来的body是空的。没有media_Id老师.每日调用接口有上线弄了几天了都。
Wechat.prototype.uploadMaterial = function(type, material,permanent){
var that = this;
var form = {}
var uploadUrl = api.temporary.upload
if(permanent){
uploadUrl = api.permanent.upload
_.extend(form,permanent)//form兼容所有的上传类型
}
if(type ==='pic'){
uploadUrl = api.permanent.uploadNewsPic
}
if(type ==='news'){
uploadUrl = api.permanent.uploadNews
}else{
form.media = fs.createReadStream(material)
}
//如果传进来的是图文那么material是数组 如果传进来是视频图片等 那么material 传进来的路径
return new Promise(function(resolve,reject){
that
.fetchAccessToken()//拿到token
.then(function(data){
var url = uploadUrl +'access_token='+data.access_token
if(!permanent){
url += '&type='+ type
}else{
form.access_token = data.access_token
}
var options = {
method:"POST",
url:url,
json:true,
}
if(type ==='news'){
options.body = form
}else{
options.formData = form
}
console.log(options)
request(options).then(function(response){
console.log(response)
var _data = response.body;
/* console.log(response)*/
/* console.log(_data)*/
if(_data){
resolve(_data)
}
else{
throw new Error('Upload material fails')
}
})
.catch(function(err){
reject(err)
})
})
})
}