Here the front end to get the encrypted phone number, decryption needs to end the wechat interface

view

There is an open-type value in the button of the small program, which can be set to getPhoneNumber to obtain the current wechat phone number or change the edge phone number

<button type="primary" class=" BTN "open-type="getPhoneNumber" @getphonenumber="getPhone">Copy the code

This button must be triggered by user action to get the encryptedData and iv values from data to pass to the back end

Js code
getPhone: function(data) { console.log(data); const { encryptedData,iv } = data.detail; If (encryptedData) {console.log(" Allow to get "); console.log("encryptedData==", encryptedData); Console. log("iv==", iv)} else {console.log(" refuse to get "); }}Copy the code

Now we need a code, and to get the code, we need to call wx.login to get the current code

wx.login({ success(res) { console.log("code==", res.code); }})Copy the code

Note: must first get the code to get the phone number decryption!! The backend will set code, encryptedData, iv to the decryption interface of wechat. Wechat developer tools can also see the effect, but with the effect of the real phone is not the same, the following is a successful phone number