# Weixin Mini Program Private message

# Features Description

Weixin Mini Program Private messaging is the ability to share Mini Program cards with other users or WeChat After a group, when other users click on the Mini Program card, the developer can identify whether the user who clicks on the card has been shared by the sharer.

# Instructions

# 1. share

After the business activity is created and before the message is shared, the createActivityId is created through the background interface ](/miniprogram/dev/api-backend/open-api/updatable-message/updatableMessage.createActivityId.html) .activityId, establish aactivityIDunique association with a business activity id.

Then through the wx.updateShareMenu interface to declare the shared message as private message, private message can not be re-forwarded.

Once the declaration is complete, private messages can be shared to individuals and groups via the upper-right menu, the share button component, wx.shareAppMessage (MiniGame only).

# Scenario 1: Individuals Share to Individuals

A --> B

# Scenario 2: Individuals share to groups

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

sample code

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

# 2. Verification

When entering Weixin Mini Program from a group chat or a single chat message card, use wx.authPrivateMessage The interface can verify whether the current user is the recipient of a private message, that is, whether the message is either A forwarded directly to B or A sent to the group where B is located .

Before using this interface, you need to log in to Weixin Mini Program via wx.login () .

# Interface parameters

parameter type Introductions
shareTicket string shareTicket

# Success callback

parameter type Introductions
valid Boolean Whether the verification passed
iv String The initial vector of the encryption algorithm, see encryption data decryption algorithm
encryptedData String After encryption activityId, decryption can get the original activityId.If the activityId obtained after decryption can be matched to the activityid in the developer background, then the valid field is not reliable (has been tampered with) See Algorithm for Encrypting Data Decryption

# Note

  • If the returnedvalidfield isfalse, the validation failed.
  • If the returnedvalidfield istrue, the validation passed.But to be on the safe side, preventionvalidIn case thefield is tampered with, you can passencryptedDataandivto the developer background to decrypt.If theactivityIdis theactivityidcorresponding to the current activity, the verification is successful, otherwise the verification does not.
  • When a private message is shared to a group, it is judged by whether or not the user is in the group at the given moment.
  • AcvityIdis valid for 7 days after creation and valid for 120 days after validation.

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