Esempio n. 1
0
export function messageFilter(req) {
    // check request signature
    let hash = signature(req.query.timestamp, req.query.nonce);
    if (hash !== req.query.signature) {
        return CLIENT_ERROR
    }

    if (req.method === 'GET') { // echo
        return new Response(req.query.echostr);
    }

    let root = parse(co.yield(req.text()));
    let receiver = users[root.tousername.TEXT];
    if (!receiver) {
        return CLIENT_ERROR
    }

    req.receiver = receiver;

    if (req.query.encrypt_type === 'aes') {
        let encrypted = root.encrypt.TEXT;
        let msg_hash = signature(req.query.timestamp, req.query.nonce, encrypted);
        if (msg_hash !== req.query.msg_signature) {
            return CLIENT_ERROR
        }
        root = parse(receiver.decrypt(encrypted));
    }
    req.message = root;
}
 },function(response){
   var weatherObj = XML.parse(response.body)['soap:Body'].GetCityWeatherByZIPResponse.GetCityWeatherByZIPResult;
   return {
     location : weatherObj.City+", "+weatherObj.State,
     currentConditions : {
       condition : weatherObj.Description,
       temperature : weatherObj.Temperature+" F",
     }
   };
 });
 var weather = http.get('http://dd.weatheroffice.ec.gc.ca/citypage_weather/xml/'+prov+'/'+site+'_'+lang+'.xml',function(response){
     var weatherObj = XML.parse(response.body);
     return {
       location : weatherObj.location.name['#text']+", "+weatherObj.location.province['#text'],
       currentConditions : {
         condition : weatherObj.currentConditions.condition,
         temperature : weatherObj.currentConditions.temperature['#text']+" "+weatherObj.currentConditions.temperature['@units'],
       }
     };
   });
Esempio n. 4
0
exports.first_post = function() {
  var body = http.get(url),
      post = xml.parse(body).find("item")[0];
  
  return {
    title: post.find("title").text(),
    description:  post.find("description").text(),
    permalink: post.find("link").text(),
    published_at: post.find("pubDate").text()
  };
};
 }, function(response){
   var latLonListDwml = XML.parse(XML.parse(response.body)['SOAP-ENV:Body']['ns1:LatLonListCityNamesResponse']['listLatLonOut']['#text']);
   var latLonArray = _.chain([latLonListDwml.latLonList.split(' '),latLonListDwml.cityNameList.split('|')])
     .zip()
     .map(function(cityArray) {
       var latLonArray = cityArray[0].split(',')
       var nameArray = cityArray[1].split(',');
       return {
         name : nameArray[0],
         state : nameArray[1],
         latitude : latLonArray[0],
         longitude : latLonArray[1]
       };
     })
     .filter(function(site){
       return (!req.parameters.state || req.parameters.state.toLowerCase() == site.state.toLowerCase())
         && (!req.parameters.name || req.parameters.name.toLowerCase() == site.name.toLowerCase());
     })
     .sortBy(['state','name'])
     .value();
   return latLonArray;
 });
Esempio n. 6
0
	it("test suite", function() {
		for (var i = 1; i < 1143; i++) {
			var id = ("000" + i).slice(-4);
			var txt = fs.readFile("xml_files/xml/" + id + ".xml");
			var out = fs.readFile("xml_files/out/" + id + ".xml");

			var xdoc = xml.parse(txt);
			assert.equal(xdoc.toString(), out);

			var xdoc1 = xdoc.cloneNode();
			assert.notEqual(xdoc, xdoc1);
			assert.equal(xdoc1.toString(), out);

			xdoc1.normalize();
			assert.equal(xdoc1.toString(), out);
		}
	});
 var sites = http.get('http://dd.weatheroffice.ec.gc.ca/citypage_weather/xml/siteList.xml',function(response) {
     var siteList = XML.parse(response.body);
     return _.chain(siteList)
     .filter(function(site){
       var name = lang == 'f' ? site.nameFr : site.nameEn;
       return (!req.parameters.province || req.parameters.province.toLowerCase() == site.provinceCode.toLowerCase())
         && (!req.parameters.name || req.parameters.name.toLowerCase() == name.toLowerCase());
     })
     .map(function(site) {
       return {
         name : lang == 'f' ? site.nameFr : site.nameEn,
         province : site.provinceCode,
         stationID : site['@code']
       };
     })
     .sortBy(['province','name'])
     .value();
   });
Esempio n. 8
0
export function getPayResult(name, body) {
    let receiver = receivers[name];

    let respData = parse(co.yield(body.text()));
    if (respData.return_code.TEXT !== 'SUCCESS') {
        throw new Error(respData.return_msg.TEXT)
    } else if (respData.result_code.TEXT !== 'SUCCESS') {
        warn('getPayResult bad result_code:' + respData.result_code.TEXT, respData.err_code_des.TEXT);
        throw new Error(respData.err_code_des.TEXT)
    }

    let signature = respData.sign.TEXT;
    delete respData.sign;
    let ret_sign = pay_signature(respData, receiver.mch_key);

    if (signature !== ret_sign) {
        throw new Error('signature does not match')
    }

    return respData;
}