# wx.addCard(Object object)
Start from base library version 2.5.0. Please remaining backward compatible.
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.
# Parameters
# Object object
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
cardList | Array.<Object> | Yes | The list of cards and offers to be added | |
success | function | No | The callback function for a successful API call | |
fail | function | No | Callback function for failed API call | |
complete | function | No | Callback function used when API call completed (always executed whether call succeeds or fails) |
object.cardList is composed as follows
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
cardId | string | Yes | The ID of the card or offer | |
cardExt | Object | Yes | The extended parameter of the card or offer. It must be passed as a JSON-serialized string. |
cardExt is composed as follows
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
code | string | No | The code of the card or offer claimed by the user. It is required only when the card or offer uses a custom code mode. Details | |
openid | string | No | The openid of the claimer. It can be claimed only by the current user. It is required when the bind_openid field is true, and cannot be specified when the bind_openid field is false. | |
timestamp | number | Yes | A timestamp. It adopts the Coordinated Universal Time (UTC)+8 in sec. | |
nonce_str | string | No | A random string. It is set and passed by the developer to enhance security. If it is not specified, the request may be resent. Its value is a random string that contains up to 32 characters comprised of uppercase and lowercase letters and numbers. The value of nonce_str must be dynamically generated for each addition request. Duplicate values may cause claim failure. | |
fixed_begintimestamp | number | No | The time when the card or offer is claimed from a third-party system, which is a UTC+8 timestamp in sec. It is specially used when the validity time of the card or offer is DATE_TYPE_FIX_TERM, to identify the actual effective time of the card or offer. Using this API can solve the inconsistency between the start time in a merchant's system and the time when the card or offer is claimed on WeChat. | |
outer_str | string | No | A parameter of a claiming channel. It identifies the value of the channel for the current claim. | |
signature | string | Yes | A signature. The merchant signs parameters in the API list as required using SHA-1. For details, see Cards and Offers Signing |
# object.success callback function
# Parameters
# Object res
Property | Type | Description |
---|---|---|
cardList | Array.<Object> | The list of added cards and offers |
res.cardList is composed as follows
Property | Type | Description |
---|---|---|
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 |
cardId | string | The ID of the card or offer claimed by the user |
cardExt | string | The extended parameter of the card or offer. See description above for the composition of this parameter. |
isSuccess | boolean | Indicates whether the card or offer is successfully claimed |
# Description of cardExt
cardExt
is the extended parameter of cards and offers. Its value is a JSON string.
# Sample Code
wx.addCard({
cardList: [
{
cardId: '',
cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
}, {
cardId: '',
cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
}
],
success (res) {
console.log(res.cardList) // The results of card and offer addition
}
})