From 017cccb2b835d9beb01cd329742f833f5fb531c8 Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Tue, 10 Jan 2017 15:11:10 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=94=B1=E4=BA=8E=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=AF=B9=E4=B8=8D=E5=90=8Cwechat=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=81=9A=E4=B8=8D=E5=90=8C=E7=9A=84=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=95=88=E6=9E=9C=EF=BC=8C=E5=9C=A8=E8=BF=9B=E5=85=A5=E6=97=B6?= =?UTF-8?q?=E5=B0=B1=E8=8E=B7=E5=8F=96=E6=95=8F=E6=84=9F=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 然而我觉得还是需要两个 token 分别判断用户的微信账号和customer帐号(因为不推荐使用open_id来判断,这样就需要两个了) --- app.js | 5 ++++- utils/profile.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index c5d9e16..765c312 100644 --- a/app.js +++ b/app.js @@ -8,7 +8,9 @@ App({ this.jsonModel = jsonApi.JsonApiDataStoreModel this.globalData.code = wx.getStorageSync('code') - this.getUserInfo() + this.getUserInfo(function(res) { + that.globalData.wechatUserType = res.data.wechat_user_type + }) this.request({ url: `${that.globalData.API_URL}/manage_features`, success: function(res) { that.globalData.featureManager = res.data } @@ -122,6 +124,7 @@ App({ }, globalData:{ + wechatUserType: 'normal', featureManager: {}, userInfo: null, currentCustomer: null, diff --git a/utils/profile.js b/utils/profile.js index b5819d8..04e7160 100644 --- a/utils/profile.js +++ b/utils/profile.js @@ -58,6 +58,20 @@ function getPassCode (mobile, cb) { }) } +function postEncryptedData(resolve) { + app.request({ + method: 'POST', + url: `${app.globalData.API_URL}/sessions/wechat_user_type`, + data: { + code: app.globalData.code, + encrypted: app.globalData.encrypted, + userInfo: app.globalData.userInfo + }, + success: resolve, + fail: function(res) {} + }) +} + module.exports = { getZichanSlides (resolve) { return getZichanSlides(resolve) @@ -67,5 +81,9 @@ module.exports = { }, getPassCode (mobile, cb) { return getPassCode(mobile, cb) + }, + + postEncryptedData (resolve) { + return postEncryptedData(resolve) } } \ No newline at end of file From 4d9ac4cfe9483fd9dc42fd52897b5fc85614a36e Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Tue, 10 Jan 2017 17:33:15 +0800 Subject: [PATCH 2/4] bugfix --- app.js | 6 ++++-- utils/profile.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 765c312..7ac4372 100644 --- a/app.js +++ b/app.js @@ -8,8 +8,10 @@ App({ this.jsonModel = jsonApi.JsonApiDataStoreModel this.globalData.code = wx.getStorageSync('code') - this.getUserInfo(function(res) { - that.globalData.wechatUserType = res.data.wechat_user_type + this.getUserInfo(function() { + profileUtil.postEncryptedData(function(res){ + that.globalData.wechatUserType = res.data.wechat_user_type + }) }) this.request({ url: `${that.globalData.API_URL}/manage_features`, diff --git a/utils/profile.js b/utils/profile.js index 04e7160..3c47be3 100644 --- a/utils/profile.js +++ b/utils/profile.js @@ -58,7 +58,8 @@ function getPassCode (mobile, cb) { }) } -function postEncryptedData(resolve) { +function postEncryptedData (resolve) { + var app = getApp() app.request({ method: 'POST', url: `${app.globalData.API_URL}/sessions/wechat_user_type`, From 31922862274ef23883db281a99b2010b86c73ed5 Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Tue, 10 Jan 2017 17:34:36 +0800 Subject: [PATCH 3/4] bugfix --- app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app.js b/app.js index 7ac4372..654aca5 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,6 @@ const jsonApi = require('utils/jsonapi-datastore/dist/jsonapi-datastore.js') require('utils/polyfill.js') +var profileUtil = require('utils/profile.js') App({ onLaunch: function () { From 07f4f8f3dde82821d95f926b7b5c8b5721cb2ff2 Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Wed, 11 Jan 2017 10:24:10 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B2=A1=E6=B3=95=E8=8E=B7=E5=8F=96app?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=90=8E=E6=8F=90=E5=89=8Drequire=E4=BC=9A?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E4=BB=96=E5=87=BD=E6=95=B0=E7=94=A8=E7=9A=84?= =?UTF-8?q?app=E4=B9=9F=E6=98=AFundefined=EF=BC=8C=E6=89=80=E4=BB=A5?= =?UTF-8?q?=E5=88=86=E5=BC=80=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 17 +++++++++++++++-- utils/profile.js | 36 +++--------------------------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/app.js b/app.js index 654aca5..5de24f6 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,5 @@ const jsonApi = require('utils/jsonapi-datastore/dist/jsonapi-datastore.js') require('utils/polyfill.js') -var profileUtil = require('utils/profile.js') App({ onLaunch: function () { @@ -10,7 +9,7 @@ App({ this.globalData.code = wx.getStorageSync('code') this.getUserInfo(function() { - profileUtil.postEncryptedData(function(res){ + that.postEncryptedData(function(res){ that.globalData.wechatUserType = res.data.wechat_user_type }) }) @@ -126,6 +125,20 @@ App({ } }, + postEncryptedData: function (resolve) { + this.request({ + method: 'POST', + url: `${this.globalData.API_URL}/sessions/wechat_user_type`, + data: { + code: this.globalData.code, + encrypted: this.globalData.encrypted, + userInfo: this.globalData.userInfo + }, + success: resolve, + fail: function(res) {} + }) + }, + globalData:{ wechatUserType: 'normal', featureManager: {}, diff --git a/utils/profile.js b/utils/profile.js index 3c47be3..610ce5c 100644 --- a/utils/profile.js +++ b/utils/profile.js @@ -1,6 +1,6 @@ const app = getApp() -function getZichanSlides (resolve) { +export function getZichanSlides (resolve) { app.authRequest({ url: `${app.globalData.API_URL}/my_assets`, header: { 'Content-Type': 'application/json'}, @@ -9,7 +9,7 @@ function getZichanSlides (resolve) { }) } -function postCustomerInfo (data, cb) { +export function postCustomerInfo (data, cb) { data['code'] = app.globalData.code data['encrypted'] = app.globalData.encrypted app.request({ @@ -45,7 +45,7 @@ function postCustomerInfo (data, cb) { }) } -function getPassCode (mobile, cb) { +export function getPassCode (mobile, cb) { app.request({ url: `${app.globalData.API_URL}/send_validation_code/send_message`, header: { 'Content-Type': 'application/json'}, @@ -58,33 +58,3 @@ function getPassCode (mobile, cb) { }) } -function postEncryptedData (resolve) { - var app = getApp() - app.request({ - method: 'POST', - url: `${app.globalData.API_URL}/sessions/wechat_user_type`, - data: { - code: app.globalData.code, - encrypted: app.globalData.encrypted, - userInfo: app.globalData.userInfo - }, - success: resolve, - fail: function(res) {} - }) -} - -module.exports = { - getZichanSlides (resolve) { - return getZichanSlides(resolve) - }, - postCustomerInfo (data, resolve) { - return postCustomerInfo(data, resolve) - }, - getPassCode (mobile, cb) { - return getPassCode(mobile, cb) - }, - - postEncryptedData (resolve) { - return postEncryptedData(resolve) - } -} \ No newline at end of file