Wechat.prototype.uploadMaterial = function(type,filepath){ var that = this; var form = { media: fs.createReadStream(filepath) }; console.log(form); return new Promise(function(resolve,reject){ that .fetchAccessToken() .then(function(data){ var url = api.upload + '?access_token=' + data.access_token + '&type=' + type; request({method: 'POST',url: url,formData: form ,json:true}).then(function(response){ var _data = response.body; console.log('----------'); console.log(_data);//{ errcode: 48001, // errmsg: 'api unauthorized hint: [33JkdA0026ure1]' } //这段输出为错误48001.,我以为是没权限,就用微信调试工具去试。测试如图。。 // 接口权限有权限,但调用的时候又报48001,而且access_token也验证成功了 console.log('_data.media_Id为' + _data.media_Id); if(_data){ resolve(_data); } else{ throw new Error('upload fail'); } }) .catch(function(err){ reject(err); }) }) }) }
另我的公众号是个人订阅号,且未认证(个人订阅号无法认证。和这个有关系吗?)