]; 2. Use openSetting to guide the user to open the corresponding permissions."/> ]; 2. Use openSetting to guide the user to open the corresponding permissions.">

Home >Web Front-end >uni-app >How does uniapp call WeChat authorization?

How does uniapp call WeChat authorization?

coldplay.xixi
coldplay.xixiOriginal
2020-12-09 16:54:166251browse

Uniapp calls WeChat authorization method: 1. Use the button component, the code is [831fecd201ff12d80e83cfce1325eed265281c5ac262bf6d81768915a4a77ac0]; 2. Use openSetting guides users to open corresponding permissions.

How does uniapp call WeChat authorization?

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, Dell G3 computer.

Recommended (free): uni-app development tutorial

Uniapp calls WeChat authorization method:

Method one

**使用button组件(open-type属性)**
<button open-type="getUserInfo"@click="loginMP"></button>
uni.getUserInfo({
provider:"weixin",
success(userInfo) {
loginMP().then(res=>{
uni.setStorageSync(&#39;token&#39;, res.result.token)
uni.getUserInfo({
provider:"weixin",
success(res) {
console.log(res);
},
fail(err) {
console.log(err);
}
})
uni.showToast({
title: &#39;登录成功&#39;
});
}).catch(err=>{
uni.showModal({
title: "提示",
content: &#39;稍后重试&#39;+err.message,
showCancel: false,
});
})
}

Method two

**使用openSetting引导用户打开相应的权限,相关的API还有getSetting **
uni.authorize({
scope:"scope.scope.userInfo",
success(res) {
console.log(res);
},
fail() {
uni.openSetting({
success(authSetting) {
console.log(authSetting);
}
})
}
})

Related free recommendations: Programming Video course

The above is the detailed content of How does uniapp call WeChat authorization?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn