From dbbe87b425eb9a2caad74523afa2cdb81c4fc654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A4=E5=8D=83=E4=BA=A9=E5=B0=8F=E5=B0=91=E7=88=B7?= <517059477@qq.com> Date: Thu, 10 Mar 2022 20:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nsgk_entry/app.js | 25 ++--- nsgk_entry/pages/show/show.js | 36 +++--- nsgk_entry/pages/user/login/login.js | 51 +++++++-- nsgk_entry/pages/user/login/login.wxml | 10 +- nsgk_entry/project.config.json | 150 ++++++++++++------------- nsgk_entry/utils/API.js | 13 +-- nsgk_entry/utils/storage.js | 32 +++++- nsgk_entry/utils/util.js | 83 +++++++------- 8 files changed, 233 insertions(+), 167 deletions(-) diff --git a/nsgk_entry/app.js b/nsgk_entry/app.js index ee73cc5..aa4e89c 100644 --- a/nsgk_entry/app.js +++ b/nsgk_entry/app.js @@ -7,16 +7,14 @@ App({ //存储storage初始化globalData数据-- //何时存储,用来判断,不用获取code that.initGlobalData(); - //授权处理 - UTIL.initSQFromWX(); //获取code - // UTIL.getCOdeFromWX({ - // complate: (code) => { - // console.log('app:微信code,' + code); - // // //获取openId - // that.getOpenIdFromFW(code); - // } - // }); + UTIL.getCOdeFromWX({ + complate: (code) => { + console.log('app:微信code,' + code); + // //获取openId + that.getOpenIdFromFW(code); + } + }); //获取设备信息 wx.getSystemInfo({ success: function (res) { @@ -71,12 +69,13 @@ App({ UTIL.httpRequestNoneDetal(API.URL_GET_OPENID, sendData, "POST", { success: (res) => { if (res._code == API.SUCCESS_CODE) { - console.log("成功获取到openId:" + res._data.openid); UTIL.showToastNoneIcon("openId:" + res._data.openid); } else { //未获取到openId - console.log("失败,获取到openId:" + res._msg); - UTIL.showToastNoneIcon("openId:失败"); + // console.log("失败,获取到openId:" + res.msg); + STORAGE.setOpenId(res.data.openId) + STORAGE.setSessionKey(res.data.sessionKey) + // UTIL.showToastNoneIcon("openId:失败"); } } }) @@ -153,6 +152,6 @@ App({ selfClass: '', }, }); - }, 200000); + }, 2000); }, }) diff --git a/nsgk_entry/pages/show/show.js b/nsgk_entry/pages/show/show.js index 9bbeb95..05de84b 100644 --- a/nsgk_entry/pages/show/show.js +++ b/nsgk_entry/pages/show/show.js @@ -123,9 +123,9 @@ Page({ } , fail: (res) => { - wx.navigateTo({ - url: '/pages/wxAuth/wxAuth', - }) + // wx.navigateTo({ + // url: '/pages/wxAuth/wxAuth', + // }) } } @@ -224,21 +224,21 @@ Page({ v: 3, warehouseId: 10005 } - UTIL.httpRequest(API.URL_ZB_RECOMMEND_LIST, sendData, - { - success: (res) => { - if (res._code == API.SUCCESS_CODE) { - UTIL.showToastNoneIcon("数据共:" + res._data.length + "条"); - } else { - UTIL.showToastNoneIcon(res._msg) - } - }, - fail: (res) => { - UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP) - }, - complete: (res) => { - } - }); + // UTIL.httpRequest(API.URL_ZB_RECOMMEND_LIST, sendData, + // { + // success: (res) => { + // if (res._code == API.SUCCESS_CODE) { + // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条"); + // } else { + // UTIL.showToastNoneIcon(res._msg) + // } + // }, + // fail: (res) => { + // UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP) + // }, + // complete: (res) => { + // } + // }); } , diff --git a/nsgk_entry/pages/user/login/login.js b/nsgk_entry/pages/user/login/login.js index 3fcd41f..f633f1d 100644 --- a/nsgk_entry/pages/user/login/login.js +++ b/nsgk_entry/pages/user/login/login.js @@ -1,5 +1,7 @@ // pages/index/index.js import * as UTIL from '../../../utils/util.js'; +import * as API from '../../../utils/API.js'; +import * as STORAGE from '../../../utils/storage' const APP = getApp(); Page({ @@ -7,7 +9,8 @@ Page({ * 页面的初始数据 */ data: { - isIPhoneX:false + isIPhoneX:false, + privacyCheck:true //用户协议 }, /** @@ -67,19 +70,53 @@ Page({ onShareAppMessage: function () { }, - - getPhoneNumber: function(e) { + checkboxChange: function(res) { + let checkStatus = false; + if(res.detail.value.length!=0){ + checkStatus = true; + }else{ + checkStatus = false; + } + this.setData({ + privacyCheck:checkStatus + }) + }, + getPhoneNumber: function(res) { let that = this; let { detail - } = e; - console.log(detail) + } = res; if (!detail.encryptedData) { + //允许授权 APP.showToast("未获取到手机号码,注册失败!"); return; + }else if(this.data.privacyCheck == false){ + APP.showToast("请阅读并同意用户协议和隐私政策!"); + return; } - - + let sendData = { + sessionKey:STORAGE.getSessionKey(), + iv:detail.iv, + encryptedData:detail.encryptedData + } + UTIL.httpRequest(API.URL_POST_DECRYPTEDWXDATA, sendData,{ + success: (res) => { + if (res._code == API.SUCCESS_CODE) { + // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条"); + } else { + //待删 + wx.navigateTo({ + url: '/pages/index/index', + }) + UTIL.showToastNoneIcon(res.msg) + } + }, + fail: (res) => { + UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP) + }, + complete: (res) => { + } + }); //     if (res.detail.userInfo) { //       //用户按了允许授权按钮 //       var that = this; diff --git a/nsgk_entry/pages/user/login/login.wxml b/nsgk_entry/pages/user/login/login.wxml index 8869e6d..8595723 100644 --- a/nsgk_entry/pages/user/login/login.wxml +++ b/nsgk_entry/pages/user/login/login.wxml @@ -9,10 +9,12 @@ - + + + diff --git a/nsgk_entry/project.config.json b/nsgk_entry/project.config.json index 9d51a13..b15c898 100644 --- a/nsgk_entry/project.config.json +++ b/nsgk_entry/project.config.json @@ -1,82 +1,82 @@ { - "description": "项目配置文件", - "packOptions": { - "ignore": [ - { - "type": "file", - "value": ".eslintrc.js" - } - ] - }, - "setting": { - "urlCheck": false, - "es6": true, - "enhance": true, - "postcss": true, - "preloadBackgroundData": false, - "minified": true, - "newFeature": false, - "coverView": true, - "nodeModules": false, - "autoAudits": false, - "showShadowRootInWxmlPanel": true, - "scopeDataCheck": false, - "uglifyFileName": false, - "checkInvalidKey": true, - "checkSiteMap": false, - "uploadWithSourceMap": true, - "compileHotReLoad": false, - "lazyloadPlaceholderEnable": false, - "useMultiFrameRuntime": true, - "useApiHook": true, - "useApiHostProcess": true, - "babelSetting": { - "ignore": [], - "disablePlugins": [], - "outputPath": "" + "description": "项目配置文件", + "packOptions": { + "ignore": [ + { + "type": "file", + "value": ".eslintrc.js" + } + ] }, - "useIsolateContext": true, - "userConfirmedBundleSwitch": false, - "packNpmManually": false, - "packNpmRelationList": [], - "minifyWXSS": true, - "disableUseStrict": false, - "minifyWXML": true, - "showES6CompileOption": false, - "useCompilerPlugins": false, - "ignoreUploadUnusedFiles": true - }, - "compileType": "miniprogram", - "libVersion": "2.21.1", - "appid": "wxaace54cc2cf8924b", - "projectname": "WXMB", - "debugOptions": { - "hidedInDevtools": [] - }, - "scripts": {}, - "staticServerOptions": { - "baseURL": "", - "servePath": "" - }, - "isGameTourist": false, - "condition": { - "search": { - "list": [] + "setting": { + "urlCheck": false, + "es6": true, + "enhance": true, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": false, + "coverView": true, + "nodeModules": false, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": false, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "lazyloadPlaceholderEnable": false, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": true, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "useIsolateContext": true, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "disableUseStrict": false, + "minifyWXML": true, + "showES6CompileOption": false, + "useCompilerPlugins": false, + "ignoreUploadUnusedFiles": true }, - "conversation": { - "list": [] + "compileType": "miniprogram", + "libVersion": "2.21.1", + "appid": "wx90a68c6fdd650f48", + "projectname": "WXMB", + "debugOptions": { + "hidedInDevtools": [] }, - "game": { - "list": [] + "scripts": {}, + "staticServerOptions": { + "baseURL": "", + "servePath": "" }, - "plugin": { - "list": [] - }, - "gamePlugin": { - "list": [] - }, - "miniprogram": { - "list": [] + "isGameTourist": false, + "condition": { + "search": { + "list": [] + }, + "conversation": { + "list": [] + }, + "game": { + "list": [] + }, + "plugin": { + "list": [] + }, + "gamePlugin": { + "list": [] + }, + "miniprogram": { + "list": [] + } } - } } \ No newline at end of file diff --git a/nsgk_entry/utils/API.js b/nsgk_entry/utils/API.js index 3bcee59..4a60dbe 100644 --- a/nsgk_entry/utils/API.js +++ b/nsgk_entry/utils/API.js @@ -8,7 +8,7 @@ let { //用户登录页面,接口检测用户token失效,需跳转重新登录 const USER_LOGIN_PAGE_PATH='/pages/user/login/login'; //接口成功 -const SUCCESS_CODE = '000000'; +const SUCCESS_CODE = '200'; //微信登陆失效 const INVALID_USER_TOKEN_CODE = '001007'; @@ -25,12 +25,12 @@ const MSG_INVALID_USER_TOKEN='登陆信息失效,请重新登陆'; /****************接口提示信息end**************** /****************接口地址start****************/ -/* 定位获取附近的商店 */ -const URL_LOCATION_SHOPQUERYBYLOCATION = `${URL_PREFIX}/location/shopquerybylocation`; -/* 根据版块信息获取推荐数据 */ -const URL_ZB_RECOMMEND_LIST = `${URL_PREFIX}/recommend/list`; //获取openId const URL_GET_OPENID=`${URL_PREFIX}/wechat/codeLogin`; +// 获取手机号解密接口 +const URL_POST_DECRYPTEDWXDATA = `${URL_PREFIX}/wechat/decryptedWXData`; + + /****************接口地址end****************/ export { @@ -44,7 +44,6 @@ export { MSG_FALSE_TO, MSG_ERROR_TO, MSG_INVALID_USER_TOKEN, - URL_LOCATION_SHOPQUERYBYLOCATION, - URL_ZB_RECOMMEND_LIST, URL_GET_OPENID, + URL_POST_DECRYPTEDWXDATA } \ No newline at end of file diff --git a/nsgk_entry/utils/storage.js b/nsgk_entry/utils/storage.js index 9c56301..9e3c808 100644 --- a/nsgk_entry/utils/storage.js +++ b/nsgk_entry/utils/storage.js @@ -10,7 +10,6 @@ function getMemberId() { */ function setMemberId(memberId) { wx.setStorageSync('memberId', memberId); - } /** * 获取当前登录用户的 token @@ -25,6 +24,33 @@ function getToken() { function setToken(token) { wx.setStorageSync('token', token); } +/** + * 获取当前登录用户的 openId + */ +function getOpenId() { + return wx.getStorageSync('openId'); +} +/** + * 设置用户openId + * @param {用户openId} openId + */ +function setOpenId(openId) { + wx.setStorageSync('openId', openId); +} + +/** + * 获取当前登录用户的 sessionKey + */ +function getSessionKey() { + return wx.getStorageSync('sessionKey'); +} +/** + * 设置用户openId + * @param {用户openId} sessionKey + */ +function setSessionKey(sessionKey) { + wx.setStorageSync('sessionKey', sessionKey); +} export { @@ -32,4 +58,8 @@ export { setMemberId, getToken, setToken, + getOpenId, + setOpenId, + getSessionKey, + setSessionKey } diff --git a/nsgk_entry/utils/util.js b/nsgk_entry/utils/util.js index f60a70f..6337178 100644 --- a/nsgk_entry/utils/util.js +++ b/nsgk_entry/utils/util.js @@ -208,50 +208,50 @@ function handleFail(data = '') { /** * 微信授权 获取信息 */ -function initSQFromWX() { - let that = this; - wx.getSetting({ - success(res) { +// function initSQFromWX() { +// let that = this; +// wx.getSetting({ +// success(res) { - // if (res.authSetting['scope.userInfo']) { - // console.log('个人信息:authSetting 已授权'); - // } else { - // console.log('个人信息:authSetting 未授权'); - // } - if (res.authSetting['scope.userLocation']) { - //定位已开启,暂不做功能处理 - console.log('定位:authSetting 已授权'); - getApp().globalData.setInfo.locationOpenIdWX = true; - } else { - //定位未开启,申请授权 - wx.authorize({ - scope: 'scope.userLocation', - success() { - //定位已开启,暂不做功能处理 - console.log('定位:wx.authorize success'); - getApp().globalData.setInfo.locationOpenIdWX = true; - } - , - fail() { - //如果之前已经拒绝过,直接返回fail 不弹窗 - console.log('定位:wx.authorize fail'); - getApp().globalData.setInfo.locationOpenIdWX = false; - wx.navigateTo({ - url: '/pages/wxAuth/wxAuth', - }) +// // if (res.authSetting['scope.userInfo']) { +// // console.log('个人信息:authSetting 已授权'); +// // } else { +// // console.log('个人信息:authSetting 未授权'); +// // } +// if (res.authSetting['scope.userLocation']) { +// //定位已开启,暂不做功能处理 +// console.log('定位:authSetting 已授权'); +// getApp().globalData.setInfo.locationOpenIdWX = true; +// } else { +// //定位未开启,申请授权 +// wx.authorize({ +// scope: 'scope.userLocation', +// success() { +// //定位已开启,暂不做功能处理 +// console.log('定位:wx.authorize success'); +// getApp().globalData.setInfo.locationOpenIdWX = true; +// } +// , +// fail() { +// //如果之前已经拒绝过,直接返回fail 不弹窗 +// console.log('定位:wx.authorize fail'); +// getApp().globalData.setInfo.locationOpenIdWX = false; +// wx.navigateTo({ +// url: '/pages/wxAuth/wxAuth', +// }) - } +// } - }) +// }) - } - }, - fail(e) { - }, - complete() { - } - }); -} +// } +// }, +// fail(e) { +// }, +// complete() { +// } +// }); +// } /** * 获取微信Code @@ -262,6 +262,7 @@ function getCOdeFromWX({ complate }) { success: function (data) { console.log(data) complate(data.code); + hideLoadingHaveMask() }, fail: function (err) { hideLoadingHaveMask(); @@ -354,8 +355,6 @@ export { httpRequest, httpRequestNoneDetal, - - initSQFromWX, getCOdeFromWX, getLocationFromWX, getUserInfoFomWX,