Error: Non-whitespace before first tag. 第二天自动回复问题?

来源:

B级片

2016-09-07

C:\Users\Administrator\Downloads\wechat>node --harmony app

listen1234

{ xml:

   { ToUserName: [ 'gh_b8e848cc8268' ],

     FromUserName: [ 'ot8kQxL_YmQSviBwFAu6CjX-NyJw' ],

     CreateTime: [ '1473227298' ],

     MsgType: [ 'text' ],

     Content: [ '选' ],

     MsgId: [ '6327463065028696805' ] } }

Unhandled rejection Error: Non-whitespace before first tag.

Line: 0

Column: 1

Char: [

    at error (C:\Users\Administrator\Downloads\wechat\node_modules\sax\lib\sax.js:667:10)

    at strictFail (C:\Users\Administrator\Downloads\wechat\node_modules\sax\lib\sax.js:693:7)

    at beginWhiteSpace (C:\Users\Administrator\Downloads\wechat\node_modules\sax\lib\sax.js:967:7)

    at Object.write (C:\Users\Administrator\Downloads\wechat\node_modules\sax\lib\sax.js:1019:11)

    at Parser.exports.Parser.Parser.parseString (C:\Users\Administrator\Downloads\wechat\node_modules\xml2js\lib\xml2js.js:508:31)

    at Parser.parseString (C:\Users\Administrator\Downloads\wechat\node_modules\xml2js\lib\xml2js.js:7:59)

    at Object.exports.parseString (C:\Users\Administrator\Downloads\wechat\node_modules\xml2js\lib\xml2js.js:540:19)

    at C:\Users\Administrator\Downloads\wechat\util.js:52:10

    at Promise._execute (C:\Users\Administrator\Downloads\wechat\node_modules\bluebird\js\release\debuggability.js:299:9)

    at Promise._resolveFromExecutor (C:\Users\Administrator\Downloads\wechat\node_modules\bluebird\js\release\promise.js:481:18)

    at new Promise (C:\Users\Administrator\Downloads\wechat\node_modules\bluebird\js\release\promise.js:77:14)

    at Object.exports.formatMessage (C:\Users\Administrator\Downloads\wechat\util.js:51:9)

    at Object.<anonymous> (C:\Users\Administrator\Downloads\wechat\g.js:39:23)

    at next (native)

    at Object.<anonymous> (C:\Users\Administrator\Downloads\wechat\node_modules\koa-compose\index.js:28:19)

    at next (native)




发送的消息收到了,但在执行var message = util.formatMessage(content.xml);方法时报错。卡了快一周了,求拯救啊!

写回答

2回答

Scott

2016-09-07

应该是 xml 的模板代码写错了,检查下标签大小写啊,语法嵌套啊,是否关闭啊,多余空格啊之类的

0
0

ReadingCommando

2016-09-09

这个不是xml模版的问题,我遇到问题和你一样。要感谢 nodejs微信课程群2 @Along的帮助问题顺利的解决了。

function formatMessage(result) {

  var message = {};


  if (typeof result === 'object') {

  var keys = Object.keys(result);


  for (var i = 0; i < keys.length; i++) {

  var item = result[keys[i]];

  var key = keys[i];


  if (!(item instanceof Array) || item.length === 0) {

  continue;

  }


  if (item.length === 1) {

  var val = item[0];


  if (typeof val === 'object') {

  mesage[key] = formatMessage(val);

  } else {

  message[key] = (val || '').trim();

  }

  } else {

  message[key] = [];


  for (var j = 0, k = item.lenght; j < k; j++) {

  message[key].push(formatMessage(item[j]));

  }

  }

  }

  }


  return message;

 }


exports.formatMessage = formatMessage ;



0
2
ReadingCommando
回复
Scott
回复 Scott是啊,谢谢啊!!!
2016-09-13
共2条回复

7天搞定Node.js微信公众号

Koa框架、ES2015新特性、MongoDB,开发微信公众号

1742 学习 · 787 问题

查看课程