Share a text message to WeChat
Note:
-
This API is only applicable to multi-end applications and is not supported within Mini Program.
-
This API does not support debugging in the "Mobile App Assistant." Developers must build an APK or IPA and install it on a mobile device to perform debugging.
-
This API is now supported on HarmonyOS devices.
Pre-integration Notes
- This feature relies on the WeChat Open SDK. You must follow the guidelines to create a mobile application account on the WeChat Open Platform to complete the relevant initialization configuration. For details, please refer to the WeChat Mobile Application Capability Initialization Guide.
Parameters
For developer convenience, the parameters of wx.miniapp.shareImageMessage are consistent with those of the WeChat Open Platform Open SDK Share API.
| Attribute | Type | Default Value | Required | Description |
|---|---|---|---|---|
| text | string | - | Yes | The text to be shared |
| scene | number | - | Yes | The target scenario for sending. 0 = Share to chat, 1 = Share to Moments, 2 = Share to Favorites |
JSAPI Code Example
wx.miniapp.shareTextMessage({
text: 'Share a moment',
scene: 0, // Share to conversation
success(res) {
wx.showToast({
title: 'Success: Share text',
})
},
fail() {
wx.showToast({
title: 'Failure: Share text',
})
}
})