uni-app解密手机号

<!-- bindgetphonenumber -->微信登录获取电话号码<!-- bindgetphonenumber -->微信登录获取电话号码<!-- bindgetphonenumber -->微信登录获取电话号码<!-- bindgetphonenumber -->微信登录获取电话号码<!-- bindgetphonenumber -->微信登录获取电话号码<template> <view> <!-- bindgetphonenumber --> <button type="primary" open-type="getUserInfo" @click="getuserinfo" withCredentials="true">微信登录</button> <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取电话号码</button> </view> </template.


<script> 

    export default { 

        data() { 

            return { 

            }; 

        }, 

        onLoad: function() { 

            uni.login({ 

                success: function(res) { 

                    // 获取code 

                    // console.log(JSON.stringify(res)); 

                } 

            }); 

        }, 

        methods: { 

            getPhoneNumber: function(e) { 

                console.log(e); 

                if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { 

                } else { 

                } 

                //              console.log(JSON.stringify(e.encryptedData)); 

                //              console.log(JSON.stringify(e.iv)); 

            }, 

            getUserInfo: function(loginType, cb) { 

                var that = this 

                if (this.globalData.userInfo) { 

                    typeof cb == "function" && cb(this.globalData.userInfo, true); 

                } else { 

                    //1.调用登录接口 

                    wx.login({ 

                        success: function() { 

                            wx.getUserInfo({ 

                                success: function(res) { 

                                    that.globalData.userInfo = res.userInfo; 

                                    typeof cb == "function" && cb(that.globalData.userInfo, true); 

                                }, 

                                fail: function() { 

                                    //2.第一次登陆不强制授权,直接返回 

                                    if (loginType == 0) { 

                                        typeof cb == "function" && cb(that.globalData.userInfo, false); 

                                    } else { 

                                        //3.授权友好提示 

                                        wx.showModal({ 

                                            title: '提示', 

                                            content: "您还未授权登陆,部分功能将不能使用,是否重新授权?", 

                                            showCancel: true, 

                                            cancelText: "否", 

                                            confirmText: "是", 

                                            success: function(res) { 

                                                //4.确认授权调用wx.openSetting 

                                                if (res.confirm) { 

                                                    if (wx.openSetting) { //当前微信的版本 ,是否支持openSetting 

                                                        wx.openSetting({ 

                                                            success: (res) => { 

                                                                if (res.authSetting["scope.userInfo"]) { //如果用户重新同意了授权登录 

                                                                    wx.getUserInfo({ 

                                                                        success: function(res) { 

                                                                            that.globalData.userInfo = res.userInfo; 

                                                                            typeof cb == "function" && cb(that.globalData.userInfo, true); 

                                                                        } 

                                                                    }) 

                                                                } else { //用户还是拒绝 

                                                                    typeof cb == "function" && cb(that.globalData.userInfo, false); 

                                                                } 

                                                            }, 

                                                            fail: function() { //调用失败,授权登录不成功 

                                                                typeof cb == "function" && cb(that.globalData.userInfo, false); 

                                                            } 

                                                        }) 

                                                    } else { 

                                                        typeof cb == "function" && cb(that.globalData.userInfo, false); 

                                                    } 

                                                } else { 

                                                    typeof cb == "function" && cb(that.globalData.userInfo, false); 

                                                } 

                                            } 

                                        }) 

                                    } 

                                } 

                            }) 

                        } 

                    }) 

                } 

            } 

        } 

    } 

</script> 

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 简介: 微信登陆,在新建一个微信小程序Hello World项目的时候,就可以看到项目中出现了我们的微信头像,其实...
    大海_e68f阅读 1,857评论 1 4
  • ▲关注「言财」,承诺你成长 微信应用号(小程序,「应用号」的新称呼)终于来了! 目前还处于内测阶段,微信只邀请了部...
    言财阅读 1,667评论 0 0
  • 在JavaScript中,回调函数具体的定义为:函数A作为参数(函数引用)传递到另一个函数B中,并且这个函数B执行...
    user_lu阅读 5,058评论 0 0
  • 原文:http://gold.xitu.io/entry/57e34d6bd2030900691e9ad7/pro...
    AiPuff阅读 2,520评论 0 3
  • 界面开发 使用自己的AppID在开发者工具中创建一个项目image.png    如果不打算上线,只是纯粹练练手,...
    枭龙gogogo阅读 606评论 0 0