@uni/subscribe-message
v1.0.0
Published
[![npm](https://img.shields.io/npm/v/@uni/subscribe-message.svg)](https://www.npmjs.com/package/@uni/subscribe-message)
Downloads
1
Readme
subscribeMessage
Bring up the client applet subscription message interface, and return the user's operation result of subscribing to the message. When the user selects "Always keep the above selections and do not ask again" in the subscription panel, the template message will be added to the user's applet settings page, and the user's subscription status to the relevant template message can be obtained through the wx.getSetting interface .
Supported
Precautions for WeChat Containers
- One-time template id and permanent template id cannot be used at the same time.
- The lower version of the basic library 2.4.4~2.8.3 already supports the call of the subscription message interface, and only supports the input of a one-time tmplId/permanent tmplId.
- Starting from version 2.8.2, after the user clicks or initiates a payment callback, the subscription message interface can be called up.
- Starting from version 2.10.0, the development version and the trial version of applets will prohibit the use of template message formId.
- In an authorization call, the template title corresponding to each tmplId cannot be the same. If there are the same, only one is kept.
- Starting from version 2.10.0, support for subscribing to voice message reminders, details
Install
$ npm install @uni/subscribeMessage --save
or
$ npm install @uni/apis --save
Usage
import subscribeMessage from '@uni/subscribeMessage';
subscribeMessage({
tmplIds: [''],
success: () => {
console.log('success');
},
fail: (res) => {
console.log('fail', res);
},
complete: (res) => {
console.log('complete', res);
}
});
subscribeMessage({
tmplIds: [''],
}).then((res?) => {
console.log('success');
});
你也可以从大包引入:
import { subscribeMessage } from '@uni/apis';
Parameters
| Property | Type | Description | Required | Default |
| --- | --- | --- | --- | --- |
| options | object
| | 是 | - |
| options.tmplIds | Array
| A collection of IDs of message templates that need to be subscribed. Up to 3 messages can be subscribed in one call | Yes | - |
| options.success | Function
| The callback function for a successful API call | No | - |
| options.fail | Function
| The callback function for a failed API call | No | - |
| options.complete | Function
| The callback function used when the API call completed (always executed whether the call succeeds or fails) | No | - |
object.success Callback returns
| Property | Type | Description |
| --- | --- | --- |
| errMsg | string
| When the interface call is successful, the errMsg value is'requestSubscribeMessage: ok' |
| [TEMPLATE_ID: string] | string
| [TEMPLATE_ID] is a dynamic key, the template id, and its values include'accept','reject','ban', and'filter'. 'accept' means that the user agrees to subscribe to the template message corresponding to this id,'reject' means that the user refuses to subscribe to the template message corresponding to this id,'ban' means it has been banned by the background, and'filter' means that the template has been banned because the template title has the same name. Background filtering. For example, {errMsg: "requestSubscribeMessage:ok", zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: "accept"} means that the user agrees to subscribe to this message zun-LzcQyW-edafCVvzPkK4de2RXllr1f |
object.fail Callback returns
| Property | Type | Description |
| --- | --- | --- |
| errMsg | string
| Interface call failure error message |
| errCode | string
| Interface call failure error code |