Taro.addCard(option)
Adds cards and offers in batch. It can be used only in Mini Programs or cultural interaction Mini Games that complete verification. For more documents, see API Documentation for WeChat Cards & Offers.
cardExt Description The extended parameter of the card or offer. It must be passed as a JSON-serialized string.
Type
(option: Option) => Promise<SuccessCallbackResult>
Parameters
Option
| Property | Type | Required | Description |
|---|---|---|---|
| cardList | RequestInfo[] | Yes | The list of cards and offers to be added |
| complete | (res: any) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
| fail | (res: any) => void | No | The callback function for a failed API call |
| success | (res: Result) => void | No | The callback function for a successful API call |
RequestInfo
| Property | Type | Description |
|---|---|---|
| cardExt | string | The extended parameter of the card or offer. It must be passed as a JSON-serialized string. |
| cardId | string | The ID of the card or offer |
SuccessCallbackResult
| Property | Type | Description |
|---|---|---|
| cardList | AddCardResponseInfo[] | The list of cards and offers to be added |
| errMsg | string | Call result |
AddCardResponseInfo
| Property | Type | Description |
|---|---|---|
| cardExt | string | The extended parameter of the card or offer. See description above for the composition of this parameter. |
| cardId | string | The ID of the card or offer claimed by the user |
| code | string | Encrypted code. It is a string obtained after the code of the card or offer claimed by the user is encrypted. To decrypt the code, see Code Decryption API. |
| isSuccess | boolean | Indicates whether the card or offer is successfully claimed |
Sample Code
Taro.addCard({
cardList: [
{
cardId: '',
cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
}, {
cardId: '',
cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
}
],
success: function (res) {
console.log(res.cardList) // The results of card and offer addition
}
})
API Support
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.addCard | ✔️ |