npm install bcrypt 加密模块
qt.gtimg.cn/q=s_pksz00858
webAPP单页多应用
股票查询应用
var crypto=require('crypto');
var http=require("http");
var iconv=require("iconv-lite");
var StockDataSource=function(){
this.name='stock'this.accesskey='your accesskey'this.host='g.sae.sina.com.cn'this.api_act='/financehq/list='};
StockDataSource.prototype.getQuoteData=function(stockList){
vartimestamp=(Math.floor((+newDate)/1000))varqueryString=stockList;
varuri=this.api_act+queryString;varmsg="GET\n"+uri+"\nx-sae-accesskey:"+this.accesskey+"\nx-sae-timestamp:"+timestamp;
varhmac=crypto.createHmac('sha256',this.secretkey);
hmac.update(msg);
vars=hmac.digest("base64");varreq_options{
hostname:this.host,
method:'GET',
path:uri,
headers:{'x-sae-accesskey':this.accesskey,'x-sae-timestamp':''+timestamp,'Authorizaition':"SAEV1_HMAC_SHA256"+s } };
varreq=http.request(req_options,function(res){
varbody='';
res.on('data',function(d){body+=d;
}).on('end',function(){console.log(iconv.decode(newBuffer(body),"GBK"));
});
});
req.end();};vards=newStockDataSource();
ds.getQuoteData("sh000001,sz000001,hk01816");