Perjanjian Pemrosesan dan Keamanan Data


<button bindtap='login' loading="{{isLoading}}">Authorized login</button>
import Config from './utils/configData';const app = getApp();Page({data: {isLoading: false,},login: function () {this.setData({isLoading: true})wx.login({success: (res) => {console.log('wx.login success===', res)if (res.code) {wx.request({url: `${Config.BASEURL}/getUserInfo`,method: "POST",data: {appid: Config.APPID,code: res.code},success: (res) => {this.setData({isLoading: false})console.log('wx.request success===', res)const { code = -1, data = {} } = res?.data || {};if (code === 200) {wx.showToast({title: 'Logged in successfully',icon: 'success',duration: 500})// Or store via wx.setStorageapp.globalData.userInfo = {avatarUrl: data.avatarUrl,account: data.account,nickName: data.userName,id: data.id,token: data.token,phoneNumber: data.phone,emailAddress: data.email}setTimeout(() => {wx.navigateBack({delta: 1})}, 500)} else {const msg = res?.data?.data?.msg || '/getUserInfo request fail'const errcode = res?.data?.data?.errcode || codeconsole.log('/getUserInfo request fail', res)wx.showModal({title: 'Login failed',confirmText: 'Confirm',content: `/getUserInfo fail:${msg}[code:${errcode}]`,showCancel: false})}},fail: (err) => {this.setData({isLoading: false})console.log('wx.request fail', err)wx.showModal({title: 'Login failed',confirmText: 'Confirm',content: err.errMsg,showCancel: false})},})} else {this.setData({isLoading: false})console.log('wx.login does not return code', res)wx.showModal({title: 'Login failed',confirmText: 'Confirm',content: res.errMsg,showCancel: false})}},fail: (err) => {this.setData({isLoading: false})console.log('wx.login fail===', err)wx.showModal({title: 'Login failed',confirmText: 'Confirm',content: err.errMsg,showCancel: false})}})}})
getPhoneNumber. After the user permission is provided, use the bindgetphonenumber event to get the callback information. Pass the dynamic token code from the callback information through a custom API (e.g.,/getUserPhone in the example code) to the mini program backend service, and call the getuserphonenumber API provided by the platform’s OpenServer to obtain the user’s mobile number with the code.
getEmailAddress. After the user permission is provided, use the bindgetemailaddress event to get the callback information. Pass the dynamic token code from the callback information through a custom API (e.g.,/getUserEmailDirect in the example code) to the mini program backend service, and call the getemailaddress API provided by the platform’s OpenServer to obtain the user’s email with the code.
<view><buttonopen-type="getPhoneNumber"bindtap="clickGetPhoneNumber"bindgetphonenumber="handleGetPhoneNumber">Get Phone Number</button><buttonopen-type="getEmailAddress"bindtap="clickGetEmailAddress"bindgetemailaddress="handleGetEmailAddress">Get Email Address</button></view>
import Config from './utils/configData';var app = getApp();Page({data: {phoneNumber: '',emailAddress: '',},clickGetEmailAddress() {wx.showLoading();},clickGetPhoneNumber() {wx.showLoading();},handleGetPhoneNumber(e) {console.log('getPhoneNumber success===', e.detail)const { code, errMsg } = e.detailif (code) {wx.request({url: `${Config.BASEURL}/getUserPhone`,method: "POST",data: {appid: Config.APPID,code,token: app.globalData.userInfo.token // Login state},success: (res) => {wx.hideLoading()console.log('getPhoneNumber request success===', res)const { code = -1, data = {}, msg } = res?.data || {};if (code === 200) {this.setData({phoneNumber: data?.phoneNumber})} else {const msg = res?.data?.data?.msg || res?.data || '/getPhoneNumber request fail'const errcode = res?.data?.data?.errcode || codeconsole.log('/getPhoneNumber request fail', res)wx.showModal({title: 'Failed to retrieve phone number',confirmText: 'Confirm',content: `/getPhoneNumber fail:${msg}[code:${errcode}]`,showCancel: false})}},fail: (err) => {wx.hideLoading()console.log('wx.request fail', err)wx.showModal({title: 'wx.request fail',confirmText: 'Confirm',content: err.errMsg,showCancel: false})},})} else {wx.hideLoading()console.log('getPhoneNumber does not return code', e.detail)wx.showModal({title: 'getPhoneNumber fail',confirmText: 'Confirm',content: errMsg,showCancel: false})}},handleGetEmailAddress(e) {console.log('getEmailAddress success===', e.detail)const { code, errMsg } = e.detailif (code) {wx.request({url: `${Config.BASEURL}/getUserEmailDirect`,method: "POST",data: {appid: Config.APPID,code},success: (res) => {wx.hideLoading()console.log('getEmailAddress request success===', res)const { code = -1, data = {}, msg } = res?.data || {};if (code === 200) {this.setData({emailAddress: data?.emailAddress})} else {const msg = res?.data?.data?.msg || res?.data || '/getEmailAddress request fail'const errcode = res?.data?.data?.errcode || codeconsole.log('/getEmailAddress request fail', res)wx.showModal({title: 'Failed to retrieve email address',confirmText: 'Confirm',content: `/getEmailAddress fail:${msg}[code:${errcode}]`,showCancel: false})}},fail: (err) => {wx.hideLoading()console.log('wx.request fail', err)wx.showModal({title: 'wx.request fail',confirmText: 'Confirm',content: err.errMsg,showCancel: false})},})} else {wx.hideLoading()console.log('getEmailAddress does not return code', e.detail)wx.showModal({title: 'getEmailAddress fail',confirmText: 'Confirm',content: errMsg,showCancel: false})}}})
chooseAvatar. After the user selects the desired profile photo, the temporary path of profile photo information can be obtained through the callback of the bindchooseavatar event.
nickname. When users type in the input field, the host app's nickname will appear above the keyboard. By tapping the nickname, it will automatically fill the input field. The latest value can be obtained through the bindchange event bindchange event of the input.
<view class="userInfo-container"><view class="settingItem"><text class="caption">Profile Picture</text><view class="avatar-empty"></view><button class="headerButton" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar"><image src="{{userHead}}" class="userHead" mode="aspectFill" /></button></view><view class="settingItem"><text class="caption">Nickname</text><inputvalue="{{nickName}}"type="nickname"class="value"placeholder="Please enter a nickname"bindchange="nickNameChange" /></view></view>
import Config from './utils/configData';var app = getApp();Page({data: {userHead: '',userHeadBase64: '',nickName: '',},onChooseAvatar(e) {console.log('onChooseAvatar===', e)const { avatarUrl } = e.detailif(avatarUrl.includes('/tmp')) {const fs = wx.getFileSystemManager();fs.readFile({filePath: avatarUrl,encoding: 'base64',success: (data) => {this.setData({userHeadBase64: 'data:image/png;base64,' + data.data,userHead: 'data:image/png;base64,' + data.data})},fail: (err) => {console.error('readFile error===', err);}});}if(avatarUrl) {this.setData({userHead: avatarUrl,})}},nickNameChange(e) {console.log('nickNameChange===', e.detail.value)this.setData({nickName: e.detail.value})}})
Page {width: 100%;min-height: 100vh;background: #f2f2f2;display: flex;flex-direction: column;}.userInfo-container {display: flex;flex-direction: column;}.settingItem {display: flex;width: 100%;box-sizing: border-box;flex-direction: row;background: white;border-bottom: #dedede solid 1px;padding: 26rpx;align-items: center;}.avatar-empty {flex: 1;}.headerButton {padding: 15rpx;width: 46px !important;height: 46px !important;border-radius: 8px;}.userHead {width: 100%;height: 100%;pointer-events: none;}.settingItem .caption, .settingItem .value {font-size: 30rpx;color: #333;}.settingItem .value {flex: 1;text-align: right;}
`${Config.BASEURL}/getUserInfo` API, which is called by the mini program. The purpose of this API is to exchange a code for a unique user identifier and establish the login state of the mini program.GET https://xxx.xxx.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan