Skip to content

手机号

获取手机号

html
<button class="bind-mobile-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">绑定手机</button>
js

//获取手机号
async getPhoneNumber(e){
    let encryptedData=e.detail.encryptedData;
    let iv=e.detail.iv;
    //解密获取手机号
    let pnRes=await this.getDewxbizdata({encrypteddata:encryptedData,iv:iv,session_key:this.sessionKey});
    if(pnRes.code==200){//获取手机号成功
        let phoneNumber=pnRes.data.phoneNumber;
        let bpRes=await this.bindWechatPhoneNumber({cellphone:phoneNumber});
        if(bpRes.code==200){//保存手机号成功
            this.$emit("close");
            uni.navigateBack({ delta: 1 })
        }else{
            uni.showToast({
                title:bpRes.data,
                icon:"none",
                duration:2000
            })
        }
    }else{//获取手机号失败
        uni.showToast({
            title:pnRes.data,
            icon:"none",
            duration:2000
        })
    }
}

绑定手机号

js
//绑定手机号
async submit(){
    if(this.isSubmit){
        if(this.cellphone.trim()==''){
            uni.showToast({
                title: '请输入手机号',
                icon: 'none',
                duration:2000
            })
            return;
        }
        if(!this.cellphone.match(/^1[0-9][0-9]\d{8}$/)){
            uni.showToast({
                title: '您输入的手机号格式不正确',
                icon: 'none',
                duration:2000
            })
            return;
        }
        let existCellphone=await this.existCellphone({cellphone:this.cellphone});
        if(existCellphone.data.exist=='1'){//手机号已存在
            uni.showToast({
                title: '手机号存在,请更换',
                icon: 'none',
                duration:2000
            });
            return;
        }
        if(this.msgCode.trim()==''){
            uni.showToast({
                title: '请输入短信验证码',
                icon: 'none',
                duration:2000
            })
            return;
        }
        this.isSubmit=false;
        let bcData=await this.bindCellhone({cellphone:this.cellphone,sms_code:this.msgCode});
        if(bcData.code==200){
            uni.showToast({
                title: '绑定手机号成功',
                icon: 'none',
                duration:2000
            });
            setTimeout(()=>{
                uni.navigateBack({ delta: 1 })
            },2000)
        }else{
               this.isSubmit=true;
            uni.showToast({
                title: bcData.data,
                icon: 'none',
                duration:2000
            })
        }
    }
},