# Mini Program Private Message

# Function introduction

The private messaging feature of the Mini Program is the ability for developers to identify whether the user who clicked on the Mini Program has been shared with the Mini Program when a shareholder shares the Mini Program card to other users or to a group of people.

# Instructions

# 1. share

After creating a business activity and before sharing Mini Program messages, you need to use the backend interface createActivityId createactivityId, Build AactivityIdUniquely associated with a business activity id.

And then by wx.updateShareMenu The interface declares that the shared message is a private message, and the private message has the property of non-reforwarding.

After the declaration is completed, you can share private messages to individuals and group chats through the upper-right menu, the share button component, wx.shareAppMessage (small game only).

# Scene 1: Personal Share to Personal

A --> B

# Scene 2: Individuals to share with the group

A --> [B, C, D, E]

sample code

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

# 2. Verification

From the group chat, single chat message card into the Mini Program, through the wx.authPrivateMessage Interface can verify that the current user is the recipient of a private message, that is, that the message isA forwarded directly to BorForward A to the group where B is

Before the interface is used, it is necessary to pass the wx.login() Interface login Mini Program.

# Interface parameters

parameter type Introductions
shareTicket string shareTicket

# Success callback

parameter type Introductions
valid Boolean Verify that it is passed
iv String The initial vector of the encryption algorithm, see in detailEncryption data decryption algorithm
encryptedData String After encryption activityId, decryption can get the original activityId. If the activityId obtained after decryption can be verified with the activity id of the developer background, otherwise the valid field is unreliable (tampered) See detailsEncryption data decryption algorithm

# Note

  • If returned.validFields arefalse"This verification is not approved.
  • If returned.validFields aretrue, indicates that the verification is passed. But to be on the safe side, preventionvalidThe possibility that the field has been tampered with, you can putencryptedDataandivSend it to the developer to decrypt it. If the decryption results inactivityIdIs what the current activity corresponds to.activityId The validation passes, otherwise the validation does not pass.
  • When a private message is shared with a group, it is judged by whether the user is in the group at the time of identification.
  • activityIdValid for sharing within 7 days of creation and valid for verification within 120 days.

# sample code

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)
  }
})