Authored by 陈峰

Merge branch 'feature/session2' into 'release/5.6'

sessionkey 低版本验证



See merge request !506
@@ -13,25 +13,6 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model @@ -13,25 +13,6 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model
13 const _ = require('lodash'); 13 const _ = require('lodash');
14 const urlP = require('url'); 14 const urlP = require('url');
15 15
16 -/**  
17 - * 处理旧版本的app兼容新接口  
18 - * @param {*} url url  
19 - * @param {*} data data  
20 - * @param {*} param param  
21 - * @param {*} method method  
22 - */  
23 -const middleApi = (url, data, param, method) => {  
24 - try {  
25 - let promise = method === 'post' ? api.post : api.get;  
26 -  
27 - if (!_.get(data, 'uid.sessionKey', '') && data.uid) {  
28 - data.app_version = '5.5.0';  
29 - }  
30 - return promise.call(api, url, data, param);  
31 - } catch (err) {  
32 - return null;  
33 - }  
34 -};  
35 const getResource = code => { 16 const getResource = code => {
36 return serviceApi.get('operations/api/v5/resource/get', { 17 return serviceApi.get('operations/api/v5/resource/get', {
37 content_code: code, 18 content_code: code,
@@ -39,43 +20,43 @@ const getResource = code => { @@ -39,43 +20,43 @@ const getResource = code => {
39 }); 20 });
40 }; 21 };
41 const vip = (limit) => { 22 const vip = (limit) => {
42 - return middleApi('', { 23 + return api.get('', {
43 method: 'app.student.vip', 24 method: 'app.student.vip',
44 limit: limit || 60 25 limit: limit || 60
45 }); 26 });
46 }; 27 };
47 const verifiedStudentTotal = () => { 28 const verifiedStudentTotal = () => {
48 - return middleApi('', { 29 + return api.get('', {
49 method: 'app.student.verifiedStudentTotal' 30 method: 'app.student.verifiedStudentTotal'
50 }); 31 });
51 }; 32 };
52 const getProvince = () => { 33 const getProvince = () => {
53 - return middleApi('', { 34 + return api.get('', {
54 method: 'app.studentMarket.getAddressList' 35 method: 'app.studentMarket.getAddressList'
55 }, { 36 }, {
56 cache: true 37 cache: true
57 }); 38 });
58 }; 39 };
59 const getSchool = code => { 40 const getSchool = code => {
60 - return middleApi('', { 41 + return api.get('', {
61 method: 'app.studentMarket.getSchoolInfoList', 42 method: 'app.studentMarket.getSchoolInfoList',
62 areaCode: code 43 areaCode: code
63 }); 44 });
64 }; 45 };
65 const getEducationLevelList = () => { 46 const getEducationLevelList = () => {
66 - return middleApi('', { 47 + return api.get('', {
67 method: 'app.studentMarket.getEducationLevelList' 48 method: 'app.studentMarket.getEducationLevelList'
68 }); 49 });
69 }; 50 };
70 const userAcquireStatus = (uid, couponIds) => { 51 const userAcquireStatus = (uid, couponIds) => {
71 - return middleApi('', { 52 + return api.get('', {
72 method: 'app.coupons.userAcquireStatus', 53 method: 'app.coupons.userAcquireStatus',
73 uid: uid, 54 uid: uid,
74 couponIds: couponIds 55 couponIds: couponIds
75 }); 56 });
76 }; 57 };
77 const verifyStudent = (uid, collegename, educationdegree, enrollmentyear) => { 58 const verifyStudent = (uid, collegename, educationdegree, enrollmentyear) => {
78 - return middleApi('', { 59 + return api.get('', {
79 method: 'app.student.verifyStudent', 60 method: 'app.student.verifyStudent',
80 uid: uid, 61 uid: uid,
81 client_type: 'h5', 62 client_type: 'h5',
@@ -85,7 +66,7 @@ const verifyStudent = (uid, collegename, educationdegree, enrollmentyear) => { @@ -85,7 +66,7 @@ const verifyStudent = (uid, collegename, educationdegree, enrollmentyear) => {
85 }); 66 });
86 }; 67 };
87 const verifyIdentity = (uid, certno, name, pageurl) => { 68 const verifyIdentity = (uid, certno, name, pageurl) => {
88 - return middleApi('', { 69 + return api.get('', {
89 method: 'app.student.verifyIdentity', 70 method: 'app.student.verifyIdentity',
90 uid: uid, 71 uid: uid,
91 client_type: 'h5', 72 client_type: 'h5',
@@ -101,7 +82,7 @@ const getUser = (uid) => { @@ -101,7 +82,7 @@ const getUser = (uid) => {
101 data: {} 82 data: {}
102 }); 83 });
103 } 84 }
104 - return middleApi('', { 85 + return api.get('', {
105 method: 'app.passport.profile', 86 method: 'app.passport.profile',
106 uid: uid 87 uid: uid
107 }, { 88 }, {
@@ -153,7 +134,7 @@ const getPlatForm = (req) => { @@ -153,7 +134,7 @@ const getPlatForm = (req) => {
153 if (isProduction) { 134 if (isProduction) {
154 yoho.http = 'https:'; 135 yoho.http = 'https:';
155 } 136 }
156 - yoho.uid = req.user.uid; 137 + yoho.uid = req.user.uid || req.query.uid;
157 yoho.isLogin = yoho.uid ? true : false; 138 yoho.isLogin = yoho.uid ? true : false;
158 return co(function*() { 139 return co(function*() {
159 let data = yield getUser(yoho.uid); 140 let data = yield getUser(yoho.uid);
@@ -391,7 +372,7 @@ exports.verifyidentity = (req, res, next) => { @@ -391,7 +372,7 @@ exports.verifyidentity = (req, res, next) => {
391 372
392 // 添加分享成功记录 373 // 添加分享成功记录
393 const addStudent = (ownuid, shareId) => { 374 const addStudent = (ownuid, shareId) => {
394 - return middleApi('', { 375 + return api.get('', {
395 method: 'app.student.addShare', 376 method: 'app.student.addShare',
396 uid: ownuid, 377 uid: ownuid,
397 shareUid: shareId 378 shareUid: shareId
@@ -738,6 +738,9 @@ const setMasterCard = (req, res, next) => { @@ -738,6 +738,9 @@ const setMasterCard = (req, res, next) => {
738 }; 738 };
739 739
740 const sessionKeyAuth = (req, res, next) => { 740 const sessionKeyAuth = (req, res, next) => {
  741 + if (!req.user.uid && req.query.uid) {
  742 + req.user.uid = req.query.uid;
  743 + }
741 next(); 744 next();
742 }; 745 };
743 746
@@ -14,8 +14,8 @@ const domains = { @@ -14,8 +14,8 @@ const domains = {
14 liveApi: 'http://testapi.live.yohops.com:9999/', 14 liveApi: 'http://testapi.live.yohops.com:9999/',
15 singleApi: 'http://api-test3.yohops.com:9999/', 15 singleApi: 'http://api-test3.yohops.com:9999/',
16 16
17 - api: 'http://api-test3.yohops.com:9999/',  
18 - service: 'http://service-test3.yohops.com:9999/', 17 + api: 'http://api.yoho.cn/',
  18 + service: 'http://service.yoho.cn/',
19 global: 'http://api-global.yohobuy.com', 19 global: 'http://api-global.yohobuy.com',
20 20
21 // liveApi: 'http://api.live.yoho.cn/', 21 // liveApi: 'http://api.live.yoho.cn/',
@@ -49,6 +49,30 @@ module.exports = () => { @@ -49,6 +49,30 @@ module.exports = () => {
49 appSessionType: req.cookies.app_client_type 49 appSessionType: req.cookies.app_client_type
50 }; 50 };
51 } 51 }
  52 +
  53 + if (!req.user.uid &&
  54 + (req.query.uid || (
  55 + req.cookies.app_uid &&
  56 + req.cookies.app_uid !== '0' &&
  57 + req.cookies.app_version &&
  58 + req.cookies.app_client_type
  59 + ))
  60 + ) {
  61 + let appUid = req.query.uid || req.cookies.app_uid;
  62 + let appVersion = req.query.app_version || req.cookies.app_version;
  63 + let appSessionType = req.query.client_type || req.cookies.app_client_type;
  64 +
  65 + req.query.uid = {
  66 + toString: () => {
  67 + return _.parseInt(appUid);
  68 + },
  69 + appVersion: appVersion,
  70 + appSessionType: appSessionType
  71 + };
  72 + res.cookie('app_uid', appUid.toString());
  73 + res.cookie('app_version', appVersion);
  74 + res.cookie('app_client_type', appSessionType);
  75 + }
52 next(); 76 next();
53 }; 77 };
54 }; 78 };
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 "xml2js": "^0.4.17", 50 "xml2js": "^0.4.17",
51 "yoho-express-session": "^2.0.0", 51 "yoho-express-session": "^2.0.0",
52 "yoho-md5": "^2.0.0", 52 "yoho-md5": "^2.0.0",
53 - "yoho-node-lib": "=0.2.18", 53 + "yoho-node-lib": "=0.2.20",
54 "yoho-zookeeper": "^1.0.8" 54 "yoho-zookeeper": "^1.0.8"
55 }, 55 },
56 "devDependencies": { 56 "devDependencies": {