当前位置:   article > 正文

uniapp微信小程序隐私协议/授权登录-通用组件_微信小程序,授权隐私,界面,勾选

微信小程序,授权隐私,界面,勾选

一、前言

微信小程序官方公告《关于小程序隐私保护指引设置的公告》

需要处理的隐私接口《插件用户隐私保护说明内容介绍》

二、注意事项
1.2023 年 9 月 15 号之前,默认不会启用隐私相关功能,所以检测不到需要弹窗的情况,可以在 manifest.json 中配置 "__usePrivacyCheck__": true 之后,接口才可以检测到是否需要弹窗。

2.自动打开隐私保护指引界面需在「小程序管理后台」配置《小程序用户隐私保护指引》https://developers.weixin.qq.com/miniprogram/dev/framework/user-privacy/,官方《用户隐私保护指引填写说明》。注:每个用到的隐私接口(同一类型)都需要在后台声明,仅有声明所处理的用户信息,才可以调用平台提供的对应接口或组件。若未声明,对应接口或组件将直接禁用

3.微信开发者工具的调试基础库,最好大于2.33.0,推荐最新版本

三、解决方案

 1.manifest.json配置 ,源码视图 里面

  1. "mp-weixin" : {
  2. "appid" : "***************",
  3. "__usePrivacyCheck__" : true, //这个选择为true (粘贴使用时将注释删掉)
  4. "setting" : {
  5. "urlCheck" : true,
  6. "minified" : true,
  7. "es6" : false
  8. },
  9. .......
  10. },
2.app.vue中验证
  1. // app.vue
  2. globalData: {
  3. privacyContractName: '', //隐私协议的名字
  4. showPrivacy: false //控制隐私弹窗显隐
  5. },
  6. onLaunch(){
  7. const that = this;
  8. wx.getPrivacySetting({
  9. success(res) {
  10. console.log('是否需要授权:', res.needAuthorization, '隐私协议的名称为:', res.privacyContractName);
  11. if (res.needAuthorization) {
  12. that.globalData.privacyContractName = res.privacyContractName;
  13. that.globalData.showPrivacy = true;
  14. } else {
  15. that.globalData.showPrivacy = false;
  16. }
  17. }
  18. });
  19. }
3.创建组件
  1. // 组件privacyPopup.vue
  2. <template>
  3. <view class="privacy" v-if="showPrivacy">
  4. <view class="content">
  5. <view class="title">隐私保护指引</view>
  6. <view class="des">
  7. 在使用当前小程序服务之前,请仔细阅读
  8. <text class="link" @click="openPrivacyContract">{{ privacyContractName }}</text>
  9. 。如果你同意{{ privacyContractName }},请点击“同意”开始使用。
  10. </view>
  11. <view class="btns">
  12. <button class="item reject" @click="exitMiniProgram">拒绝</button>
  13. <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'privacyPopup',
  21. data() {
  22. return {
  23. privacyContractName: '',
  24. showPrivacy: false
  25. };
  26. },
  27. created() {
  28. setTimeout(() => {
  29. this.showPrivacy = getApp().globalData.showPrivacy;
  30. this.privacyContractName = getApp().globalData.privacyContractName;
  31. }, 500);
  32. },
  33. methods: {
  34. // 同意隐私协议
  35. handleAgreePrivacyAuthorization() {
  36. const that = this;
  37. wx.requirePrivacyAuthorize({
  38. success: res => {
  39. that.showPrivacy = false;
  40. getApp().globalData.showPrivacy = false;
  41. }
  42. });
  43. },
  44. // 拒绝隐私协议
  45. exitMiniProgram() {
  46. const that = this;
  47. uni.showModal({
  48. content: '如果拒绝,我们将无法获取您的信息, 包括手机号、位置信息、相册等该小程序十分重要的功能,您确定要拒绝吗?',
  49. success: res => {
  50. if (res.confirm) {
  51. that.showPrivacy = false;
  52. uni.exitMiniProgram({
  53. success: () => {
  54. console.log('退出小程序成功');
  55. }
  56. });
  57. }
  58. }
  59. });
  60. },
  61. // 跳转协议页面
  62. // 在真机上点击高亮的协议名字会自动跳转页面 微信封装好的不用操作
  63. openPrivacyContract() {
  64. wx.openPrivacyContract({
  65. fail: () => {
  66. uni.showToast({
  67. title: '网络错误',
  68. icon: 'error'
  69. });
  70. }
  71. });
  72. }
  73. }
  74. };
  75. </script>
  76. <style lang="scss" scoped>
  77. .privacy {
  78. position: fixed;
  79. top: 0;
  80. right: 0;
  81. bottom: 0;
  82. left: 0;
  83. background: rgba(0, 0, 0, 0.5);
  84. z-index: 9999999;
  85. display: flex;
  86. align-items: center;
  87. justify-content: center;
  88. .content {
  89. width: 85vw;
  90. padding: 50rpx;
  91. box-sizing: border-box;
  92. background: #fff;
  93. border-radius: 16rpx;
  94. .title {
  95. text-align: center;
  96. color: #333;
  97. font-weight: bold;
  98. font-size: 34rpx;
  99. }
  100. .des {
  101. font-size: 26rpx;
  102. color: #666;
  103. margin-top: 40rpx;
  104. text-align: justify;
  105. line-height: 1.6;
  106. .link {
  107. color: #07c160;
  108. text-decoration: underline;
  109. }
  110. }
  111. .btns {
  112. margin-top: 60rpx;
  113. display: flex;
  114. justify-content: space-between;
  115. .item {
  116. justify-content: space-between;
  117. width: 244rpx;
  118. height: 80rpx;
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. border-radius: 16rpx;
  123. box-sizing: border-box;
  124. border: none;
  125. }
  126. .reject {
  127. background: #f4f4f5;
  128. color: #909399;
  129. }
  130. .agree {
  131. background: #07c160;
  132. color: #fff;
  133. }
  134. }
  135. }
  136. }
  137. </style>

4、使用

  1. // index.vue
  2. // 在页面中直接引入使用就行 不需要任何多余操作
  3. <template>
  4. <view class="content">
  5. <privacyPopup></privacyPopup>
  6. <view>......</view>
  7. </view>
  8. </template>
  9. <script>
  10. import privacyPopup from '@/components/privacyPopup/privacyPopup.vue';
  11. export default {
  12. components: {
  13. privacyPopup
  14. },
  15. }
  16. </script>

5、效果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/292237
推荐阅读
相关标签
  

闽ICP备14008679号