[Mini Program] Error when getting mobile phone number: getPhoneNumber:fail no permission

[getPhoneNumber cannot obtain the mobile phone number]

login.wxml

<!--登录按钮-->
<button type="primary" class='phone-text'   open-type="getPhoneNumber"  lang="zh_CN" bindgetphonenumber="getPhoneNumber">
  一键登录
</button>

 login.js

Page({
  getPhoneNumber(e){
    console.log(e)
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
  }
)}

After the operation, the console prompts no permission.

 

【reason】

To ensure the security of user privacy data, WeChat authentication is required when calling the getPhoneNumber method.

【Solution】

(1) WeChat authentication

A business account is required and a fee of 300 yuan is required.

Please refer to: getPhoneNumber:fail no permission_Blog of Struggle in a Foreign Land-CSDN Blog

(2) Open WeChat test account

It is convenient for us before we decide to officially register a mini program account, or if we just want to experience the various development capabilities of a mini program (or mini game), we can first apply for a test account of the mini program to experience it; we can use this account to Log in to the "Mini Program Developer Tool" officially launched by WeChat, and create and experience developing mini program projects.

Implementation steps:

Apply for a test account | WeChat open document (qq.com)

Click " Log in "  on the successful registration page , and scan the WeChat code to log in using the WeChat code used to register the mini program test account.

On the mobile phone interface, click "...'s Mini Program Test Account". If you are a mini-game developer, you can click: "...'s Mini Game Test Account" (such as the picture below)

 

 After clicking OK, the browser will automatically enter the "Mini Program Test Account" interface and obtain an AppID and an AppSecret.

 

【result】

おすすめ

転載: blog.csdn.net/qq_54639969/article/details/132077620