|
@@ -2,7 +2,7 @@ var express = require('express');
|
|
|
var request = require('superagent');
|
|
|
var router = express.Router();
|
|
|
var base = 'http://apis.juhe.cn/mobile/get?key=9f719ab7014f2cbdc7b394edf70d0f76';
|
|
|
-//var cookie = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' };
|
|
|
+var cookie = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36' };
|
|
|
router.get('/', function(req, res, next) {
|
|
|
getMobile(req, res, next);
|
|
|
});
|
|
@@ -11,7 +11,7 @@ router.post('/', function(req, res, next) {
|
|
|
});
|
|
|
|
|
|
function getMobile(req, res, next) {
|
|
|
- var type = req.query.type || req.body.type;
|
|
|
+ var type = req.query.type || req.body.type || 'json';
|
|
|
var phone = req.query.phone || req.body.phone;
|
|
|
var callback = req.query.callback || req.body.callback;
|
|
|
var url = base + '&phone=' + phone + '&dtype=' + type;
|
|
@@ -22,7 +22,19 @@ function getMobile(req, res, next) {
|
|
|
message: ''
|
|
|
}
|
|
|
};
|
|
|
- request.get(url).set(req.headers).end(function(err, response) {
|
|
|
+ if(!phone){
|
|
|
+ output['status']={
|
|
|
+ code:-1,
|
|
|
+ message:'phone number is empty.'
|
|
|
+ };
|
|
|
+ if (callback) {
|
|
|
+ res.jsonp(output);
|
|
|
+ } else {
|
|
|
+ res.json(output);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ request.get(url).set(cookie).end(function(err, response) {
|
|
|
var body = {};
|
|
|
if (response && response.text) {
|
|
|
body = response.text;
|
|
@@ -49,13 +61,13 @@ function getMobile(req, res, next) {
|
|
|
};
|
|
|
}
|
|
|
if (callback) {
|
|
|
- return res.jsonp(output);
|
|
|
+ res.jsonp(output);
|
|
|
} else {
|
|
|
- return res.json(output);
|
|
|
+ res.json(output);
|
|
|
}
|
|
|
} else {
|
|
|
res.header('content-type', 'text/xml; charset=utf-8');
|
|
|
- return res.send(body);
|
|
|
+ res.send(body);
|
|
|
}
|
|
|
});
|
|
|
}
|