前言:大家在写APP的时候少不了使用微信登录,那么该怎么写呢,下面我就分享一下个人的解决方法。
handleThirdLoginApp() {
console.log("App微信拉起授权")
var that = this
uni.getProvider({
service: 'oauth',
success: function(res) {
console.log(res.provider);
//支持微信、qq和微博等
if (~res.provider.indexOf('weixin')) {
uni.login({
provider: 'weixin',
success: function(loginRes) {
console.log("App微信获取用户信息成功", loginRes);
that.getApploginData(loginRes) //请求登录接口方法
},
fail: function(res) {
console.log("App微信获取用户信息失败", res);
}
})
}
}
});
},
1.首先是handleThirdLoginApp() ,不用多介绍,自定义的方法
2.console.log("App微信拉起授权") 打印一下,查看方法是否起作用
3.var that = this 把this赋值给that
4.uni.getProvider() 这是官方提供的api,大家可以去官网查看详细的参数