| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import {
- imgServerUrl
- } from '../../config/config.js'
- import {
- decodePhone
- } from '../../services/wx.js'
- import {
- updataStorageData
- } from '../../utils/storage.js'
- var app = getApp()
- Page({
- data: {
- canIUse: wx.canIUse('button.open-type.getPhoneNumber'),
- imgServerUrl: imgServerUrl,
- isShow: true
- },
- onLoad: function(options) {
- app.globalData.noPhone = true
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1]; //当前页面
- var prevPage = pages[pages.length - 2]; //上一个页面
- prevPage.setData({
- noPhone: false
- })
- },
- getPhoneNumber: function(e) {
- console.log(e)
- let iv = e.detail.iv || ''
- let encryptedData = e.detail.encryptedData || ''
- if (iv) {
- //用户按了允许授权按钮
- this.decodePhoneCallback({
- iv: iv,
- encryptedData: encryptedData,
- }).then(data => {
- app.globalData.noPhone = false
- console.log('手机号解密:', data)
- updataStorageData('phone', data.data.hpUser.phone);
- wx.navigateBack()
- })
- } else {
- wx.setStorageSync('resumeUrl', '')
- //用户按了拒绝按钮
- wx.showModal({
- title: '警告',
- content: '您点击了拒绝授权,将无法正常使用小程序,请授权之后再进入!!!',
- confirmText: '返回授权',
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击了“返回授权”')
- }
- }
- })
- }
- },
- // 手机号解密回调 返回成功失败
- decodePhoneCallback(params) {
- return new Promise((resolve, reject) => {
- decodePhone({
- 'encryptedData': encodeURIComponent(params.encryptedData),
- 'iv': encodeURIComponent(params.iv),
- 'user_id': app.globalData.userId,
- 'user_token': app.globalData.userToken
- }).then(data => {
- resolve(data)
- }).catch(data => {
- reject(false)
- })
- })
- }
- })
|