UNI-APP_APP微信授权登录

在App中要实现微信授权则需要在微信公众平台申请一个应用,获取相应的appid和appsecret
在填写申请时有2个地方需要注意:
在这里插入图片描述
应用包名:是app打包时候可以填写的如下图位置:
在这里插入图片描述
应用签名可以在:微信公众平台的头部导航 — 资源中心 —资源下载 中点击下载一个手机软件,输入应用包名后直接生成复制;
在这里插入图片描述
在uniapp项目中的manifest.json 进行APP模块配置;
在这里插入图片描述

getApploginData(data) {
    
    
	let that = this
	//这边是前端自己去调微信用户信息的接口,根据接口需要请求,如果不需要前端去获取的话就交给后端,可省去次操作
	uni.request({
    
    
		url: "https://api.weixin.qq.com/sns/userinfo?access_token=" + data.authResult.access_token + "&openid=" + data.authResult
			.openid,
		method: 'GET',
		dataType: 'json',
		header: {
    
    
			'content-type': 'application/x-www-form-urlencoded' // 默认值
		},
		success(res) {
    
    
			console.log('【登录回调啾啾啾】', res)
		},
		fail() {
    
    
			
		}
	})
},
handleThirdLoginApp() {
    
    
	console.log("App微信拉起授权")
	let that = this
	uni.getProvider({
    
    
		service: 'oauth',
		success: (res) =>{
    
    
			// console.log(res.provider);
			//支持微信、qq和微博等
			if (~res.provider.indexOf('weixin')) {
    
    
				uni.login({
    
    
					provider: 'weixin',
					success: (loginRes) =>{
    
    
						// console.log("App微信获取用户信息成功", loginRes);
						that.getApploginData(loginRes) //请求登录接口方法
					},
					fail: (res) =>{
    
    
						console.log("App微信获取用户信息失败", res);
					}
				})
			}
		}
	});
},

猜你喜欢

转载自blog.csdn.net/weixin_44599931/article/details/118486771