From ad9729fde33c48ccadbe6df547066e3db150f3ae Mon Sep 17 00:00:00 2001 From: corala <18339694416@163.com> Date: Thu, 14 Apr 2022 18:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=88=E6=9D=83=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 4 +- pages/index/index.js | 21 ++++---- pages/index/index.wxml | 12 ++--- pages/login/index.js | 95 ++++++++++++++++++++++++++++++------- pages/login/index.wxml | 4 +- project.config.json | 3 +- project.private.config.json | 6 +++ 7 files changed, 103 insertions(+), 42 deletions(-) create mode 100644 project.private.config.json diff --git a/app.json b/app.json index 59f602d..4077b13 100644 --- a/app.json +++ b/app.json @@ -1,10 +1,10 @@ { "pages": [ - "pages/open/index", "pages/login/index", - "pages/rank/index", "pages/index/index", + "pages/open/index", "pages/out/index", + "pages/rank/index", "pages/AR/index", "components/loading/loading" ], diff --git a/pages/index/index.js b/pages/index/index.js index 40666ea..80b9f5b 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -12,13 +12,16 @@ Page({ canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false }, onLoad() { - if (wx.getUserProfile) { - this.setData({ - canIUseGetUserProfile: true - }) - } + this.getUserProfile(e) + + // if (wx.getUserProfile) { + // this.setData({ + // canIUseGetUserProfile: true + // }) + // } }, getUserProfile(e) { + console.log(34) // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 @@ -30,13 +33,5 @@ Page({ }) } }) - }, - getUserInfo(e) { - // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 - console.log(e) - this.setData({ - userInfo: e.detail.userInfo, - hasUserInfo: true - }) } }) diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 469dcff..7768340 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -1,18 +1,16 @@ - + + + > - - - - 请使用1.4.4及以上版本基础库 - - + {{userInfo.nickName}} diff --git a/pages/login/index.js b/pages/login/index.js index f307267..e633f9b 100644 --- a/pages/login/index.js +++ b/pages/login/index.js @@ -4,7 +4,8 @@ const app = getApp() Page({ data: { - ischecked: true + ischecked: true, + token: '' }, onLoad() { @@ -19,7 +20,31 @@ Page({ ischecked: !this.data.ischecked }) }, - login(){ + + // 绑定用户头像信息 + bindNickname(obj) { + let that = this + let params = { + headPortrait: obj.avatarUrl, + nickName: obj.nickName, + sex: obj.gender, //1男 2女 + region: (obj.province&&obj.city)?(obj.province + ' ' + obj.city): '' + } + wx.request({ + url: 'http://49.232.159.78:9999/coupon/c/person/bindNickname', + method: "POST", + data: params, + header: { + Authorization: 'bearer '+ that.data.token + }, + success(res) { + if (res.statusCode == 200) { + console.log('绑定用户头像信息成功') + } + } + }) + }, + getUserInfo(){ if(!this.data.ischecked){ wx.showToast({ title: '请勾选协议', @@ -28,33 +53,69 @@ Page({ }) return; } - wx.login({ - success (res) { - console.log(res) - if (res.code) { - //发起网络请求 - // wx.request({ - // url: 'https://example.com/onLogin', - // data: { - // code: res.code - // } - // }) - } else { - console.log('登录失败!' + res.errMsg) - } + let that = this + wx.getUserProfile({ + desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + console.log(res) + wx.login({ + success (res1) { + if (res1.code) { + //发起网络请求 + wx.request({ + url: 'http://49.232.159.78:9999/auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@' + res1.code, + method: "POST", + data: { + }, + header: { + Authorization: "Basic YXBwbGV0OmFwcGxldA==", + }, + success(res2) { + console.log(33) + if (res2.statusCode == 200) { + console.log(res2) + that.setData({ + token: res2.data.access_token + }) + that.bindNickname(res.userInfo) + } + } + }) + } else { + console.log('登录失败!' + res.errMsg) + } + } + }) } }) + }, // 授权手机号 getPhoneNumber(e) { console.log(e); let that = this if (e.detail.errMsg == "getPhoneNumber:ok") { - // console.log(e) const { iv, encryptedData } = e.detail; + wx.request({ + url: 'http://49.232.159.78:9999/coupon/c/person/bindMini', + method: "POST", + data: { + encrypted: encryptedData, + iv + }, + header: { + Authorization: 'bearer '+ that.data.token + }, + success(res) { + console.log(res) + if (res.statusCode == 200) { + // console.log(res) + } + } + }) // that.$u.api.bindMini({ // encrypted: encryptedData, // iv diff --git a/pages/login/index.wxml b/pages/login/index.wxml index cddfa57..4cae4f0 100644 --- a/pages/login/index.wxml +++ b/pages/login/index.wxml @@ -12,8 +12,8 @@ 勾选表示您已阅读并同意 《隐私协议》 - - 微信一键登录 + + 微信一键授权 返回游戏 \ No newline at end of file diff --git a/project.config.json b/project.config.json index 625b37d..7bb98d8 100644 --- a/project.config.json +++ b/project.config.json @@ -38,7 +38,8 @@ "useStaticServer": true, "showES6CompileOption": false, "disableUseStrict": false, - "useCompilerPlugins": false + "useCompilerPlugins": false, + "minifyWXML": true }, "compileType": "miniprogram", "libVersion": "2.23.4", diff --git a/project.private.config.json b/project.private.config.json new file mode 100644 index 0000000..d31c1f0 --- /dev/null +++ b/project.private.config.json @@ -0,0 +1,6 @@ +{ + "setting": { + "compileHotReLoad": false + }, + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html" +} \ No newline at end of file