1***@qq.com
1***@qq.com
  • 发布:2023-08-24 09:35
  • 更新:2023-08-25 17:22
  • 阅读:2203

微信新的隐私保护接口,UNIAPP框架怎么使用啊,onNeedPrivacyAuthorization一直触发不了,服了,有没有教程呀

分类:uni小程序sdk

onNeedPrivacyAuthorization怎么用啊

2023-08-24 09:35 负责人:无 分享
已邀请:
9***@qq.com

9***@qq.com

<template>  
    <view class="content">  
    <button type="primary" class="page-body-button" open-type="getPhoneNumber"> 手机号</button>  
    <uni-popup :show="showPrivacy" msg="隐私协议声明" type="middle" auto_width_height="true">  
      <view style="padding: 5px; width: 75vw; text-align: center;">  
        <view class="name" @click="openPrivacyContract">  
          在使用前请仔细阅读<text style="color: #00a2d4;"> {{ privacyContractName }}</text>。如您同意,请点击“同意”继续使用。如您拒绝,将无法正常使用  
        </view>  
        <view style="display: flex; margin-top: 5vw;">  
          <button @click="handleDisagreePrivacyAuthorization" style="padding: 0 1.34em; font-size: 14px;">拒绝</button>  
          <!--TODO uni还没兼容,之后要替换回来-->  
          <!--        <button type="primary" id="agree-btn" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization" style="padding: 0 1.34em; font-size: 14px;">同意</button>-->  
          <button type="primary" id="agree-btn" open-type="agreePrivacyAuthorization" @click="handleAgreePrivacyAuthorization" style="padding: 0 1.34em; font-size: 14px;">同意</button>  
        </view>  
      </view>  
    </uni-popup>  
    </view>  
</template>  

<script>  
  import uniPopup from '@/components/uni-popup.vue';  
    export default {  
        data() {  
            return {  
                title: 'Hello World',  
        showPrivacy: false, // 弹框  
        privacyContractName: '《隐私协议的名称》',  
        resolvePrivacyAuthorization: '',  
            }  
        },  
        components: {  
      uniPopup  
        },  
        onLoad() {  
      if (wx.onNeedPrivacyAuthorization) {  
        wx.onNeedPrivacyAuthorization(resolve => {  
          console.log('触发的弹出授权页面');  
          this.showPrivacy = true;  
          this.resolvePrivacyAuthorization = resolve  
        });  
      }  
        },  
        methods: {  
      openPrivacyContract() {  
        wx.openPrivacyContract({  
          success: (res) => {  
          }  
        });  
      },  
      handleAgreePrivacyAuthorization() {  
        this.showPrivacy = false;  
        if (this.resolvePrivacyAuthorization) {  
          this.resolvePrivacyAuthorization({ buttonId: 'agree-btn', event: 'agree' });  
        }  
      },  
      handleDisagreePrivacyAuthorization() {  
        this.showPrivacy = false;  
        if (this.resolvePrivacyAuthorization) {  
          this.resolvePrivacyAuthorization({ event: 'disagree' });  
        }  
      }  
        }  
    }  
</script>  

<style>  

</style>  
  • 9***@qq.com

    写了个粗略的页面wx.onNeedPrivacyAuthorization,可以参考一下,我试着点击“手机号”按钮是会出现弹框的

    2023-08-25 17:23

  • 蓝天0730

    回复 9***@qq.com: 厉害了哥们,学习一下

    2023-08-25 17:26

  • 蓝天0730

    回复 9***@qq.com: 我这边wx.onNeedPrivacyAuthorization直接没反应,不知道什么原因

    2023-08-28 14:37

  • 9***@qq.com

    回复 1***@qq.com: 在manifest.json的"mp-weixin"处加上 "__usePrivacyCheck__" : true, 、开发者工具基础库设置成3.0.0

    2023-08-28 15:01

  • 蓝天0730

    回复 9***@qq.com: 设置了,还是没用,邪门了

    2023-08-28 16:34

  • 9***@qq.com

    回复 1***@qq.com: hhh隐私接口能调用吗?能调用成功的话,可能是已经同意过了,清除开发者工具的缓存试下呢

    2023-08-28 16:49

  • 2***@qq.com

    同意按钮不能使用@click,应该使用@agreeprivacyauthorization

    2023-09-01 14:05

  • 9***@qq.com

    回复 2***@qq.com: 对对

    2023-09-01 14:44

piaoyi_UI

piaoyi_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序

现在好像没有强制这个吧,再等等,等他更成熟

  • 1***@qq.com (作者)

    9月15号不弄这个你就用不了隐私API了,例如打开相册那些根本用不了

    2023-08-24 10:20

  • 1***@qq.com (作者)

    隐私保护授权的这个9月15号就实施了

    2023-08-24 10:21

9***@qq.com

9***@qq.com

我试着是可以触发的。在manifest.json的"mp-weixin"处加上"usePrivacyCheck" : true,
同意按钮暂时这样实现的<button type="primary" id="agree-btn" open-type="agreePrivacyAuthorization" @click="handleAgreePrivacyAuthorization">同意</button>

  • 9***@qq.com

    开发者工具基础库设置成3.0的

    2023-08-24 14:40

  • 9***@qq.com

    "__usePrivacyCheck__" : true,

    2023-08-25 09:13

  • 蓝天0730

    方便看一下代码吗,我这边调试调这个api没反应

    2023-08-25 15:31

  • 9***@qq.com

    回复 1***@qq.com: 我把wx.onNeedPrivacyAuthorization写在协议弹框组件中了,返回页面的时候,有问题,还在调试中…

    2023-08-25 16:21

  • 9***@qq.com

    回复 9***@qq.com: https://ask.dcloud.net.cn/article/40700 你看下这个文章,他有晒出代码

    2023-08-25 16:23

蓝天0730

蓝天0730

请问你调通了吗,我这边设置了"usePrivacyCheck" : true,在登录页onload里直接调用uni.onNeedPrivacyAuthorization没反应

  • 9***@qq.com

    你打印下wx.getPrivacySetting返回的结果呢,如果needAuthorization是false的话,清除一下开发者工具的缓存吧;

    还有在onload中设置wx.onNeedPrivacyAuthorization监听后,要调用隐私接口,才会触发onNeedPrivacyAuthorization的resolve。

    2023-08-25 16:20

  • 蓝天0730

    回复 9***@qq.com: wx.getPrivacySetting调通了,我这边根据needAuthorization判断是否弹框,然后隐私弹框下的确认按钮<button id="agree-btn" class="ok-btn" @click="handleAgreePrivacyAuthorization" open-type="agreePrivacyAuthorization" >同意并继续</button >

    2023-08-25 16:41

  • 9***@qq.com

    回复 1***@qq.com: 我的理解是:wx.onNeedPrivacyAuthorization是在页面onload时注册一个监听,再调用微信的隐私接口会触发onNeedPrivacyAuthorization的resolve,也就是得调用隐私接口才有响应。(文档中的一堆隐私接口都能触发,还有就是要在小程序微信后台隐私协议添加响应接口https://developers.weixin.qq.com/miniprogram/dev/framework/user-privacy/miniprogram-intro.html)

    2023-08-25 16:48

  • 蓝天0730

    回复 9***@qq.com: 我添加了获取手机号和获取地址,onload里onNeedPrivacyAuthorization这个方法还是没有响应,而且后续的确认按钮里this.resolvePrivacyAuthorization is not a function,好愁人

    2023-08-25 17:01

2***@qq.com

2***@qq.com

问下,这个隐私协议,是只要在登录时判断并同意就可以了,还是在每个调用隐私接口的api都要判断一下啊

  • 2***@qq.com

    调用每个隐私接口都要把这个组件加上,不过只要同意了,就不会再触发onNeedPrivacyAuthorization了,除非后续你使用的隐私接口增加了。

    2023-08-25 17:53

要回复问题请先登录注册