| @@ -1,10 +1,10 @@ | |||||
| { | { | ||||
| "pages": [ | "pages": [ | ||||
| "pages/open/index", | |||||
| "pages/login/index", | "pages/login/index", | ||||
| "pages/rank/index", | |||||
| "pages/index/index", | "pages/index/index", | ||||
| "pages/open/index", | |||||
| "pages/out/index", | "pages/out/index", | ||||
| "pages/rank/index", | |||||
| "pages/AR/index", | "pages/AR/index", | ||||
| "components/loading/loading" | "components/loading/loading" | ||||
| ], | ], | ||||
| @@ -12,13 +12,16 @@ Page({ | |||||
| canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false | canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false | ||||
| }, | }, | ||||
| onLoad() { | onLoad() { | ||||
| if (wx.getUserProfile) { | |||||
| this.setData({ | |||||
| canIUseGetUserProfile: true | |||||
| }) | |||||
| } | |||||
| this.getUserProfile(e) | |||||
| // if (wx.getUserProfile) { | |||||
| // this.setData({ | |||||
| // canIUseGetUserProfile: true | |||||
| // }) | |||||
| // } | |||||
| }, | }, | ||||
| getUserProfile(e) { | getUserProfile(e) { | ||||
| console.log(34) | |||||
| // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 | // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 | ||||
| wx.getUserProfile({ | wx.getUserProfile({ | ||||
| desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 | desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 | ||||
| @@ -30,13 +33,5 @@ Page({ | |||||
| }) | }) | ||||
| } | } | ||||
| }) | }) | ||||
| }, | |||||
| getUserInfo(e) { | |||||
| // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 | |||||
| console.log(e) | |||||
| this.setData({ | |||||
| userInfo: e.detail.userInfo, | |||||
| hasUserInfo: true | |||||
| }) | |||||
| } | } | ||||
| }) | }) | ||||
| @@ -1,18 +1,16 @@ | |||||
| <!--index.wxml--> | <!--index.wxml--> | ||||
| <view class="container"> | <view class="container"> | ||||
| <view class="userinfo"> | <view class="userinfo"> | ||||
| <block wx:if="{{canIUseOpenData}}"> | |||||
| <!-- <block wx:if="{{canIUseOpenData}}"> | |||||
| <view class="userinfo-avatar"> | <view class="userinfo-avatar"> | ||||
| <open-data type="userAvatarUrl"></open-data> | <open-data type="userAvatarUrl"></open-data> | ||||
| </view> | </view> | ||||
| <open-data type="userNickName"></open-data> | <open-data type="userNickName"></open-data> | ||||
| </block> --> | |||||
| <block wx:if="{{!hasUserInfo}}"> | |||||
| <button bindtap="getUserProfile"> 获取头像昵称1 </button>> | |||||
| </block> | </block> | ||||
| <block wx:elif="{{!hasUserInfo}}"> | |||||
| <button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button> | |||||
| <button wx:elif="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button> | |||||
| <view wx:else> 请使用1.4.4及以上版本基础库 </view> | |||||
| </block> | |||||
| <block wx:else> | |||||
| <block wx:else> | |||||
| <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image> | <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image> | ||||
| <text class="userinfo-nickname">{{userInfo.nickName}}</text> | <text class="userinfo-nickname">{{userInfo.nickName}}</text> | ||||
| </block> | </block> | ||||
| @@ -4,7 +4,8 @@ const app = getApp() | |||||
| Page({ | Page({ | ||||
| data: { | data: { | ||||
| ischecked: true | |||||
| ischecked: true, | |||||
| token: '' | |||||
| }, | }, | ||||
| onLoad() { | onLoad() { | ||||
| @@ -19,7 +20,31 @@ Page({ | |||||
| ischecked: !this.data.ischecked | 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){ | if(!this.data.ischecked){ | ||||
| wx.showToast({ | wx.showToast({ | ||||
| title: '请勾选协议', | title: '请勾选协议', | ||||
| @@ -28,33 +53,69 @@ Page({ | |||||
| }) | }) | ||||
| return; | 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) { | getPhoneNumber(e) { | ||||
| console.log(e); | console.log(e); | ||||
| let that = this | let that = this | ||||
| if (e.detail.errMsg == "getPhoneNumber:ok") { | if (e.detail.errMsg == "getPhoneNumber:ok") { | ||||
| // console.log(e) | |||||
| const { | const { | ||||
| iv, | iv, | ||||
| encryptedData | encryptedData | ||||
| } = e.detail; | } = 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({ | // that.$u.api.bindMini({ | ||||
| // encrypted: encryptedData, | // encrypted: encryptedData, | ||||
| // iv | // iv | ||||
| @@ -12,8 +12,8 @@ | |||||
| <view class="text">勾选表示您已阅读并同意</view> | <view class="text">勾选表示您已阅读并同意</view> | ||||
| <view class="text text1">《隐私协议》</view> | <view class="text text1">《隐私协议》</view> | ||||
| </view> | </view> | ||||
| <!-- <button class="btn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">绑定手机</button> --> | |||||
| <view class="btn" bindtap="login">微信一键登录</view> | |||||
| <button class="btn" wx:if="{{token}}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">绑定手机号</button> | |||||
| <view class="btn" wx:else bindtap="getUserInfo">微信一键授权</view> | |||||
| <view class="btn btn1" bindtap="backGame">返回游戏</view> | <view class="btn btn1" bindtap="backGame">返回游戏</view> | ||||
| </view> | </view> | ||||
| </view> | </view> | ||||
| @@ -38,7 +38,8 @@ | |||||
| "useStaticServer": true, | "useStaticServer": true, | ||||
| "showES6CompileOption": false, | "showES6CompileOption": false, | ||||
| "disableUseStrict": false, | "disableUseStrict": false, | ||||
| "useCompilerPlugins": false | |||||
| "useCompilerPlugins": false, | |||||
| "minifyWXML": true | |||||
| }, | }, | ||||
| "compileType": "miniprogram", | "compileType": "miniprogram", | ||||
| "libVersion": "2.23.4", | "libVersion": "2.23.4", | ||||
| @@ -0,0 +1,6 @@ | |||||
| { | |||||
| "setting": { | |||||
| "compileHotReLoad": false | |||||
| }, | |||||
| "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html" | |||||
| } | |||||