Skip to content

Commit ce1165b

Browse files
cclientcclient
authored andcommitted
init
1 parent cc6dffb commit ce1165b

File tree

7 files changed

+428
-0
lines changed

7 files changed

+428
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### 天猫淘宝api请求签名算法服务
2+
3+
### 该项目简单封装了从天猫淘宝,前端web页面提取的签名算法,因数据抓取服务不全是由js实现,为方便应用,封装为web服务,供其他语言项目调用
4+
5+
### 天猫淘宝的接口访问方式为 http jsonp api,调用时需对请求作签名
6+
7+
#### 示例
8+
9+
```js
10+
11+
function test() {
12+
// s = a(n.token + "&" + i + "&" + r + "&" + t.data)
13+
var token = "36cf6e2437097843b0c2671005d480aa"
14+
var i = '1478745430781'
15+
var r = '12574478'
16+
var data = '{"app":"tlive","sourceId":"900acac6-0d83-4b8a-9d26-dca8e9336ca9","type":1,"timeStamp":1477488912630,"id":"200216664"}'
17+
var s = sign(token + "&" + i + "&" + r + "&" + data)
18+
// s=50985d6f8f00c9cbb2fb7c5a98f3008a
19+
var tt = 'e7648eaf00c07e744ffe27e1ae37db5f_1478764995915&1478763990723&12574478&{"app":"tlive","sourceId":"900acac6-0d83-4b8a-9d26-dca8e9336ca9","type":1,"direction":0,"timeStamp":1477485240775,"id":199720496,"count":20,"includeCommentCount":true}'
20+
var aa = '7e666c912e7a55abe5010f804722d5a5&1478748652065&12574478&{"app":"tlive","sourceId":"900acac6-0d83-4b8a-9d26-dca8e9336ca9","type":1,"timeStamp":1477484451253,"id":"199686181"}'
21+
var ss = sign(aa)
22+
console.log(ss)
23+
// 22ed6f6eaa5334f70b3a9ac66e1b33f6
24+
'7e666c912e7a55abe5010f804722d5a5&1478756923699&12574478&{"app":"tlive","sourceId":"900acac6-0d83-4b8a-9d26-dca8e9336ca9","type":1,"timeStamp":1477485727641,"id":"199770637"}'
25+
}
26+
27+
```
28+

app.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var favicon = require('serve-favicon');
4+
var logger = require('morgan');
5+
// var cookieParser = require('cookie-parser');
6+
var bodyParser = require('body-parser');
7+
var tmall = require('./routes/tmall');
8+
9+
var app = express();
10+
// view engine setup
11+
app.set('views', path.join(__dirname, 'views'));
12+
app.set('view engine', 'ejs');
13+
14+
// uncomment after placing your favicon in /public
15+
//app.use(favicon(__dirname + '/public/favicon.ico'));
16+
app.use(logger('dev'));
17+
app.use(bodyParser.json());
18+
app.use(bodyParser.urlencoded({extended: false}));
19+
// app.use(cookieParser());
20+
app.use(express.static(path.join(__dirname, 'public')));
21+
22+
app.use('/tmall', tmall);
23+
24+
// catch 404 and forward to error handler
25+
app.use(function (req, res, next) {
26+
var err = new Error('Not Found');
27+
err.status = 404;
28+
next(err);
29+
});
30+
31+
// error handlers
32+
33+
// development error handler
34+
// will print stacktrace
35+
// if (app.get('env') === 'development') {
36+
// app.use(function (err, req, res, next) {
37+
// res.status(err.status || 500);
38+
// res.render('error', {
39+
// message: err.message,
40+
// error: err
41+
// });
42+
// });
43+
// }
44+
//
45+
// // production error handler
46+
// // no stacktraces leaked to user
47+
// app.use(function (err, req, res, next) {
48+
// res.status(err.status || 500);
49+
// res.render('error', {
50+
// message: err.message,
51+
// error: {}
52+
// });
53+
// });
54+
55+
module.exports = app;

bin/www

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('baidusingserver:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "tmallsign",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"start": "node ./bin/www"
7+
},
8+
"dependencies": {
9+
"body-parser": "~1.12.0",
10+
"debug": "~2.1.1",
11+
"ejs": "~2.3.1",
12+
"express": "~4.12.2",
13+
"morgan": "~1.5.1",
14+
"serve-favicon": "~2.2.0"
15+
}
16+
}

0 commit comments

Comments
 (0)