فهرست منبع

update mobile and weather apis

dotos 8 سال پیش
والد
کامیت
35c24af470
4فایلهای تغییر یافته به همراه38 افزوده شده و 22 حذف شده
  1. 14 6
      routes/mobile.js
  2. 1 1
      routes/v2.js
  3. 20 11
      routes/weather.js
  4. 3 4
      utils/utils.js

+ 14 - 6
routes/mobile.js

@@ -3,7 +3,7 @@ const request = require('superagent');
 const utils = require('../utils/utils');
 const router = express.Router();
 const base = 'http://jshmgsdmfb.market.alicloudapi.com/shouji/query';
-const APPCODE = 'c8c963a57cd7452a962e53653f03d2f6';
+const APPCODE = '5db8c4dbb31b424ab673cec87fb6770e';
 router.get('/', function(req, res, next) {
     getMobile(req, res, next);
 });
@@ -22,17 +22,25 @@ let getMobile = (req, res, next) => {
         data: {},
         status: {
             code: -1,
-            message: 'phone number is empty.'
+            message: '请确定你的请求方式像这样:/mobile?shouji=13800138000'
         }
     };
     if(_params['shouji']){
-        config['headers']['Authorization'] = `APPCODE ${APPCODE}`;
-        res.send(config)
+        config['headers'] =  {
+            "Host":"jshmgsdmfb.market.alicloudapi.com",
+            "X-Ca-Timestamp":Date.now(),
+            "gateway_channel":"http",
+            "X-Ca-Request-Mode":"debug",
+            "X-Ca-Key":"24605515",
+            "X-Ca-Stage":"RELEASE",
+            "Content-Type":"application/json; charset=utf-8",
+            "Authorization":`APPCODE ${APPCODE}`
+        }
+        //config['gzip'] = null;
+        //res.send(config)
         utils.createServer(config).then(ret => {
-            console.log(1)
             cb && res.jsonp(ret) || res.send(ret);
         }).catch(ex => {
-            console.log(ex)
             output = {
                 status: {
                     code: -2,

+ 1 - 1
routes/v2.js

@@ -26,7 +26,7 @@ const convert = (req, res, next) => {
             message: 'Please Set URL Like This: ' + protocol + '://' + host + '/v2/?url=http[s]://YourWantProxyUrl.Com'
         }
     };
-    if(config.uri){
+    if(config.url){
         utils.createServer(config).then(ret => {
             cb && res.jsonp(ret) || res.send(ret);
         }).catch(ex => {

+ 20 - 11
routes/weather.js

@@ -1,10 +1,10 @@
-let express = require('express');
-let request = require('superagent');
-let utils = require('../utils/utils');
-let router = express.Router();
-let base = 'http://op.juhe.cn/onebox/weather/query';
-let key = 'e0540a109f5a73e9df2981cdeb9d106f';
-let 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' };
+const express = require('express');
+const request = require('superagent');
+const utils = require('../utils/utils');
+const router = express.Router();
+const base = 'http://jisutqybmf.market.alicloudapi.com/weather/query';
+const APPCODE = '5db8c4dbb31b424ab673cec87fb6770e';
+
 router.get('/*', function(req, res, next) {
     getWeather(req, res, next);
 });
@@ -23,12 +23,21 @@ let getWeather = (req, res, next) => {
         data: {},
         status: {
             code: -1,
-            message: ' city name is empty.'
+            message: '请确定你的请求方式像这样:/weather?city=番禺'
         }
     };
-    if(_params['cityname']){
-        config['uri'] = `${config['uri']}&key=${key}`;
-        config['gzip'] = '';
+    if(_params['city']){
+        config['headers'] =  {
+            "Host":"jisutqybmf.market.alicloudapi.com",
+            "X-Ca-Timestamp":Date.now(),
+            "gateway_channel":"http",
+            "X-Ca-Request-Mode":"debug",
+            "X-Ca-Key":"24605515",
+            "X-Ca-Stage":"RELEASE",
+            "Content-Type":"application/json; charset=utf-8",
+            "Authorization":`APPCODE ${APPCODE}`
+        }
+        //config['gzip'] = '';
         utils.createServer(config).then(ret => {
             cb && res.jsonp(ret) || res.send(ret);
         }).catch(ex => {

+ 3 - 4
utils/utils.js

@@ -8,8 +8,7 @@ const qs = require('qs');
 const createServer = (config) => {
     return new Promise((resolve, reject) => {
         request(config, (err, ret, body) => {
-            console.log(config)
-            if (!err && ret.statusCode === 200) {
+            if (!err) {
                 resolve(body)
             } else {
                 reject(err)
@@ -43,7 +42,7 @@ const convert = (req,res,next,url) => {
         if (i === 'url') {
             let o = temp.split('?');
             let uri = o[0]
-            config['uri'] = uri;
+            config['url'] = uri;
             headers['host'] = uri.replace(/^(http|https):\/\//g, '').split('/')[0];
             if (o.length > 1) {
                 o[1].split('&').forEach(item => {
@@ -56,7 +55,7 @@ const convert = (req,res,next,url) => {
         }
     }
     if (method === 'POST') config['json'] = params;
-    else config['uri'] = config['uri'] ? `${config['uri']}?${qs.stringify(params)}` : (url?`${url}?${qs.stringify(params)}`:null) ;
+    else config['url'] = config['url'] ? `${config['url']}?${qs.stringify(params)}` : (url?`${url}?${qs.stringify(params)}`:null) ;
     config['headers'] = headers;
     return [config,protocol,host,cb,params]
 }