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){
var timestamp=(Math.floor((+new Date)/1000))
var queryString=stockList;
var uri=this.api_act+queryString;
var msg="GET\n"+uri+"\nx-sae-accesskey:"+this.accesskey+"\nx-sae-timestamp:"+timestamp;
var hmac=crypto.createHmac('sha256',this.secretkey);
hmac.update(msg);
var s=hmac.digest("base64");
var req_options{
hostname:this.host,
method:'GET',
path:uri,
headers:{
'x-sae-accesskey':this.accesskey,
'x-sae-timestamp':''+timestamp,
'Authorizaition':"SAEV1_HMAC_SHA256"+s
}
};
var req=http.request(req_options,function(res){
var body='';
res.on('data',function(d){
body+=d;
}).on('end',function(){
console.log(iconv.decode(new Buffer(body),"GBK"));
});
});
req.end();
};
var ds=new StockDataSource();
ds.getQuoteData("sh000001,sz000001,hk01816");