var express = require('express');
var routesEngine = require('./jerryapp/routes/index.js');
var app = express();
routesEngine(app);
app.listen(process.env.PORT || 3000, function () {
console.log('Listening on port, process.cwd(): ' + process.cwd() );
});
var request = require('request');
var echoService = require("../service/echo.js");
module.exports = function (app) {
app.route('/').post(function(req,res){
echoService(req, res);
});
};
var getXMLNodeValue = require("../tool/xmlparse.js");
var replyMessage = require("../tool/replyMessage.js");
const content_pattern = /<!\[CDATA\[(.*)\]\]>/;
module.exports = function(req, res){
var _da;
req.on("data",function(data){
_da = data.toString("utf-8");
});
req.on("end",function(){
var Content = getXMLNodeValue('Content',_da);
var body = content_pattern.exec(Content);
if( body.length === 2) {
Content = "Add by Jerry: " + body[1];
}
var xml = replyMessage(_da, Content);
res.send(xml);
});
};
module.exports = function(node_name, xml){
var tmp = xml.split("<"+node_name+">");
var _tmp = tmp[1].split("</"+node_name+">");
return _tmp[0];
};
var getXMLNodeValue = require("./xmlparse.js");
module.exports = function(originalBody, contentToReply){
var ToUserName = getXMLNodeValue('ToUserName', originalBody);
var FromUserName = getXMLNodeValue('FromUserName',originalBody);
var CreateTime = getXMLNodeValue('CreateTime',originalBody);
var MsgType = getXMLNodeValue('MsgType',originalBody);
var Content = contentToReply;
var MsgId = getXMLNodeValue('MsgId', originalBody);
var xml = '<xml><ToUserName>'+FromUserName+'</ToUserName><FromUserName>'+ToUserName+'</FromUserName><CreateTime>'+CreateTime+'</CreateTime><MsgType>'+MsgType+'</MsgType><Content>'+Content+'</Content></xml>';
console.log("xml to be sent: " + xml);
return xml;
};
var request = require('request');
var getXMLNodeValue = require("../tool/xmlparse.js");
var replyMessage = require("../tool/replyMessage.js");
const content_pattern = /<!\[CDATA\[(.*)\]\]>/;
const url = "http://www.tuling123.com/openapi/api?key=de4ae9269c7438c33de5806562a35cac&info=";
module.exports = function(req, res){
var _da;
req.on("data",function(data){
_da = data.toString("utf-8");
});
req.on("end",function(){
console.log("original text: " + _da);
var Content = getXMLNodeValue('Content',_da);
console.log("content: " + Content);
var body = content_pattern.exec(Content);
console.log("result size: " + body.length);
var requesturl = "";
if( body.length === 2){
requesturl = url + encodeURI(body[1]);
}
var options = {
url: requesturl,
method: "GET"
};
request(options,function(error,response,data){
if(data){
var text = JSON.parse(data).text;
var xml = replyMessage(_da, text);
res.send(xml);
}else {
res.send("Error when calling Tuning API: " + error);
console.log(error);
}
});
});
};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |