微信小程序私密消息

江河/ 01月05日/ 小程序/ 浏览 608

小程序私密消息功能是这样一种能力:当分享者分享小程序卡片给其他用户或者微信群后,其他用户点击此小程序卡片时,开发者可以鉴别出点击卡片的用户是否被分享者分享过小程序卡片。


也就是说私密消息不可以被二次转发,即:A转发给B的消息,只有B能看;如果B再转发给他人,别的人是看不到的(验证失败)。


开发步骤


1. 通过后台接口 createActivityId 创建activityId,可参考文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-message-management/updatable-message/createActivityId.html


2. 通过 wx.updateShareMenu 接口声明本次分享的消息为私密消息。


wx.updateShareMenu({
  withShareTicket: true,
  isPrivateMessage: true,
  activityId: 'xxx',
})


3. 通过 wx.authPrivateMessage 接口可以验证当前用户是否是私密消息的接收者


wx.authPrivateMessage({
  shareTicket: 'xxxxxx',
  success(res) {
    console.log('authPrivateMessage success', res)
    // res
    // {
    //   errMsg: 'authPrivateMessage:ok'
    //   valid: true
    //   iv: 'xxxx',
    //   encryptedData: 'xxxxxx'
    // }
  },
  fail(res) {
    console.log('authPrivateMessage fail', res)
  }
})


发表评论

暂无评论,抢个沙发...

客服 工单