在执行deleteMenu()的时候,deleteMenu()里面的then错误,这是为什么?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | Wechat.prototype.deleteMenu = function (){ var that = this return new Promise( function (resolve, reject){ that .fetchAccessToken() .then( function (data){ var url = api.menu.del + 'access_token=' + data.access_token request({method: 'GET' , url: url, json: true }).then( function (response){ var _data = response.body if (_data) { resolve(_data) } else { throw new Error( 'Get menu fails' ) } }) . catch ( function (err){ reject(err) }) }) }) } |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | 'use strict' var config = require( '../config' ) var Wechat = require( '../wechat/wechat' ) var menu = require( './menu' ) var wechatApi = new Wechat(config.wechat) var path = require( 'path' ) wechatApi.deleteMenu().then( function (){ return wechatApi.createMenu(menu) }) .then( function (msg){ console.log(msg) }) exports.reply = function * (next){ var message = this .weixin if (message.MsgType === 'event' ) { if (message.Event === 'subscribe' ) { if (message.EventKey) { console.log( '扫描二维码进来的:' + message.EventKey + '' + message.ticket) } this .body = '哈哈,你订阅了微信号' } else if (message.Event === 'unsubscribe' ) { console.log( '无情取关' ) this .body = '' } else if (message.Event === 'LOCATION' ) { this .body = '您上报的位置是:' + message.Latitude + '/' + message.Longitude + '-' + message.Precision } else if (message.Event === 'CLICK' ) { this .body = '您点击了菜单:' + message.EventKey } else if (message.Event === 'SCAN' ) { console.log( '关注后扫二维码' + message.EventKey + ' ' + message.ticket) this .body = '看到你扫了一下哦' } else if (message.Event === 'VIEW' ) { this .body = '您点击了菜单中的链接:' + message.EventKey } else if (message.Event === 'scancode_push' ) { console.log(message.ScanCodeInfo.ScanType) console.log(message.ScanCodeInfo.ScanResult) this .body = '您点击了菜单中的链接:' + message.EventKey } else if (message.Event === 'scancode_waitmsg' ) { console.log(message.ScanCodeInfo.ScanType) console.log(message.ScanCodeInfo.ScanResult) this .body = '您点击了菜单中的链接:' + message.EventKey } else if (message.Event === 'pic_sysphoto' ) { console.log(message.SendPicsInfo.PicList) console.log(message.SendPicsInfo.Count) this .body = '您点击了菜单中的链接:' + message.EventKey } else if (message.Event === 'pic_photo_or_album' ) { console.log(message.SendPicsInfo.PicList) console.log(message.SendPicsInfo.Count) this .body = '您点击了菜单中的链接:' + message.EventKey } else if (message.Event === 'pic_weixin' ) { console.log(message.SendPicsInfo.PicList) console.log(message.SendPicsInfo.Count) this .body = '您点击了菜单中的链接:' + message.EventKey } else if (message.Event === 'location_select' ) { console.log(message.SendLocationInfo.Location_X) console.log(message.SendLocationInfo.Location_Y) console.log(message.SendLocationInfo.Scale) console.log(message.SendLocationInfo.Label) console.log(message.SendLocationInfo.Poiname) console.log(message.SendPicsInfo.Count) this .body = '您点击了菜单中的链接:' + message.EventKey } } else if (message.MsgType === 'text' ) { var content = message.Content var reply = '额,你说的“' + message.Content + '”太复杂了,我不懂。' if (content === '1' ) { reply = '天下第一吃大米' console.log(message) } else if (content === '2' ) { reply = '天下第一吃豆腐' } else if (content === '3' ) { reply = '天下第一吃仙丹' } else if (content === '张杨海是谁' ) { reply = '张' } else if (content === '4' ) { reply = [{ title: '技术改变世界' , description: '只是个描述而已' , picUrl: 'http://tu.dytt.com/20160426054059859.jpg' , url: 'http://virjay.com' }] } else if (content === '5' ) { var data = yield wechatApi.uploadMaterial( 'image' , path.join(__dirname, '../2.jpg' )) reply = { type: 'image' , mediaId: data.media_id } } else if (content === '6' ) { var data = yield wechatApi.uploadMaterial( 'video' , path.join(__dirname, '../6.mp4' )) reply = { type: 'video' , title: '蝙蝠侠:黑暗骑士' , description: '蝙蝠侠与小丑的故事...' , mediaId: data.media_id } } else if (content === '7' ) { var data = yield wechatApi.uploadMaterial( 'image' , path.join(__dirname, '../2.jpg' )) reply = { type: 'music' , title: '音悦台' , description: '放松一下...' , musicUrl: 'http://virjay.com/7.mp3' , thumbMediaId: data.media_id } } else if (content === '8' ) { var data = yield wechatApi.uploadMaterial( 'image' , path.join(__dirname, '../2.jpg' ),{type: 'image' }) reply = { type: 'image' , mediaId: data.media_id } } else if (content === '9' ) { var data = yield wechatApi.uploadMaterial( 'image' , path.join(__dirname, '../6.mp4' ),{type: 'video' , description: '{"title":"batman", "introduction": "batman..."}' }) reply = { type: 'video' , title: '蝙蝠侠:黑暗骑士' , description: '蝙蝠侠与小丑的故事...' , mediaId: data.media_id } } else if (content === '10' ) { var picData = yield wechatApi.uploadMaterial( 'image' , path.join(__dirname, '../2.jpg' ),{}) var media = { articles: [{ title: 'tututu' , thumb_media_id: picData.media_id, author: 'virjay' , digest: '没有摘要' , show_cover_pic: 1, content: '没有内容' , content_source_url: 'http://www.virjay.com' },{ title: 'tututu2' , thumb_media_id: picData.media_id, author: 'virjay' , digest: '没有摘要' , show_cover_pic: 1, content: '没有内容' , content_source_url: 'http://www.virjay.com' }] } data = yield wechatApi.uploadMaterial( 'news' , media, {}) data = yield wechatApi.fetchMaterial(data.media_id, 'news' , {}) console.log(data) var items = data.news_item var news = [] items.forEach( function (items){ news.push({ title: items.title, description: items.digest, picUrl: picData.url, url: items.url }) }) reply = news } else if (content === '11' ) { var counts = yield wechatApi.countMaterial() console.log(JSON.stringify(counts)) var results = yield [ wechatApi.batchMaterial({ type: 'image' , offset: 0, count: 10 }), wechatApi.batchMaterial({ type: 'video' , offset: 0, count: 10 }), wechatApi.batchMaterial({ type: 'voice' , offset: 0, count: 10 }), wechatApi.batchMaterial({ type: 'news' , offset: 0, count: 10 }) ] console.log(JSON.stringify(results)) reply = '1' } else if (content === '12' ) { // var group = yield wechatApi.createGroup('wechat') // console.log('新分组 wechat:') // console.log(group) // var groups = yield wechatApi.fetchGroups() // console.log('加了 wechat 后的分组列表:') // console.log(groups) var group2 = yield wechatApi.checkGroup(message.FromUserName) console.log( '查看自己的分组' ) console.log(group2) // var result = yield wechatApi.moveGroup(message.FromUserName,100) // console.log('移动到分组100') // console.log(result) // var result2 = yield wechatApi.moveGroup([message.FromUserName],101) // console.log('批量移动到分组101') // console.log(result2) var result3 = yield wechatApi.updateGroup(101, 'Custom' ) console.log( '重命名结果:' ) console.log(result3) var groups3 = yield wechatApi.fetchGroups() console.log( '更新后的分组列表:' ) console.log(groups3) // var result4 = yield wechatApi.deleteGroup(100) // console.log('删除100分组:') // console.log(result4) // var groups4 = yield wechatApi.fetchGroups() // console.log('更新后的分组列表:') // console.log(groups4) reply = 'Group done!' } else if (content === '13' ) { var user = yield wechatApi.fetchUsers(message.FromUserName, 'zh_CN' ) console.log(user) var openIds = [ { openid: message.FromUserName, lang: 'zh_CN' } ] var users = yield wechatApi.fetchUsers(openIds) console.log(users) reply = JSON.stringify(user) } else if (content === '14' ) { var userlist = yield wechatApi.listUsers() console.log(userlist) reply = userlist.total } else if (content === '15' ) { var mpnews = { media_id: 'eSjpAvdDK68FjK2nRbbq5zXB_hzzICx8TJ8wn3-Io7s' } var test = { 'content' : 'test' } var msgData = yield wechatApi.sendByGroup( 'image' , mpnews, 101) console.log(msgData) reply = 'Yeah!' } else if (content === '16' ) { var mpnews = { media_id: 'eSjpAvdDK68FjK2nRbbq5zXB_hzzICx8TJ8wn3-Io7s' } // var test = { // 'content' : 'test' // } var msgData = yield wechatApi.previewMass( 'image' , mpnews, 'oO2E0wZFvj4hcDAcwTc5NE79Ib04' ) console.log(msgData) reply = 'Yeah!' } else if (content === '17' ) { var msgData = yield wechatApi.checkMass( '6297401665371273792' ) console.log(msgData) reply = 'Yeah!' } this .body = reply } yield next } |