uniapp小程序微信登录违规解决

解决方法: 需要添加隐私协议配置,不得默认同意,新版隐私协议封装

1、封装

<template>
	<uni-popup ref="popup" type="center" :is-mask-click="false">
		<view class="popup-box">
			<view class="weui-half-screen-dialog__hd">
				{{title}}
			</view>
			<view class="weui-half-screen-dialog__bd">
				<text class="weui-half-screen-dialog__tips">{{desc1}}</text>
				<text class="weui-half-screen-dialog__tips color-8BC21F" @click="openPrivacyContract">
					{{urlTitle}}
				</text>
				<text class="weui-half-screen-dialog__tips">{{desc2}}</text>
			</view>
			<view class="weui-half-screen-dialog__ft">
				<button class="weui-btn" @click="handleDisagree">拒绝</button>
				<button id="agree-btn" type="default" open-type="agreePrivacyAuthorization" class="weui-btn agree"
					@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
			</view>
		</view>
	</uni-popup>
</template>
 
<script>
	export default {
		data() {
			return {
				title: "用户隐私保护提示",
				desc1: "感谢您使用本产品,您使用本产品前应当仔细阅读并同意",
				urlTitle: "《小程序隐私保护指引》",
				desc2: "当您点击同意并开始使用产品服务时,即表示你已理解并同意该条款内容,该条款将对您产生法律约束力。如您拒绝,将无法更好的体验产品。",
			};
		},
		methods: {
			openPrivacyContract() {
				uni.openPrivacyContract({});
			},
			handleAgreePrivacyAuthorization() {
				getApp().globalData.showPrivacy = false;
				this.$emit('confirm');
				this.$refs.popup.close();
			},
			handleDisagree() {
				this.$refs.popup.close();
			}
		}
	}
</script>
 
<style lang="scss" scoped>
	.popup-box {
		width: 80vw;
		// height: 40vh;
		overflow: hidden;
		background: #ffffff;
		padding: 30rpx;
		border-radius: 24rpx;
 
		.weui-half-screen-dialog__hd {
			font-size: 48rpx;
			font-family: Source Han Sans CN-Bold, Source Han Sans CN;
			font-weight: bold;
			color: #000000;
			line-height: 56rpx;
		}
 
		.weui-half-screen-dialog__bd {
			margin-top: 48rpx;
			text-indent: 2em;
			.weui-half-screen-dialog__tips {
				font-size: 28rpx;
				font-family: Source Han Sans CN-Normal, Source Han Sans CN;
				font-weight: 400;
				color: #000000;
				line-height: 33rpx;
			}
		}
 
		.weui-half-screen-dialog__ft {
			display: flex;
			justify-content: space-evenly;
			align-items: center;
			margin-top: 48rpx;
			.weui-btn {
				padding: 0 60rpx;
				margin: 0;
				background: none;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Normal, Source Han Sans CN;
				font-weight: 400;
				color: #000000;
				line-height: 80rpx;
				// border: 2rpx solid #8BC21F;
			}
 
			.agree {
				color: #ffffff;
				background: linear-gradient(90deg, #8BC21F 0%, #7AB30A 100%);
			}
		}
 
		.color-8BC21F {
			color: #8BC21F !important;
		}
	}
</style>

2、App.vue获取隐私状态

if (uni.getPrivacySetting) {
				uni.getPrivacySetting({
					success: res => {
						console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)
						if (res.needAuthorization) {
							getApp().globalData.showPrivacy = true;
						} else {
							getApp().globalData.showPrivacy = false;
						}
					},
					fail: () => {},
					complete: () => {},
				})
			}

3、登录页面调取微信登录时授权

getPrivacy() {
	if (getApp().globalData.showPrivacy) {
		this.$refs.privacyPopup.$refs.popup.open();
		return;
	} else {
		this.logincode()
	}
},

4、微信授权按钮必须使用open-type="getPhoneNumber"  @getphonenumber="xcxlogin"获取手机号

<button class="popup-btn" open-type="getPhoneNumber" @getphonenumber="xcxlogin">确定</button>

5、新版隐私协议需要配置manifest.json文件 "__usePrivacyCheck__": true,

/* 小程序特有相关 */
"mp-weixin": {
		"appid": "",
		"setting": {
			"urlCheck": false,
			"postcss": true,
			"minified": true,
			"es6": false
		},
		"usingComponents": true,
		"permission": {
			"scope.userLocation": {
				"desc": "小程序将使用定位功能"
			}
		},
		"__usePrivacyCheck__": true,
		"optimization": {
			"subPackages": true
		}
	},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值