# wx.addCard(Object object)

> 基础库 1.1.0 开始支持，低版本需做[兼容处理](1003706)。

> __以 [Promise 风格](/miniprogram/dev/framework/app-service/api.md#异步-API-返回-Promise) 调用__：支持
> 
> __小程序插件__：不支持
> 
> __微信 鸿蒙 OS 版__：支持

## 功能描述

批量添加卡券。只有通过 [认证](/miniprogram/product/renzheng.md) 的小程序或文化互动类目的小游戏才能使用。更多文档请参考 [微信卡券接口文档](https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1490190158&version=1&lang=zh_CN&platform=2)。

## 参数

### Object object


```json
[
  {
    "属性": "cardList",
    "类型": "Array.<Object>",
    "默认值": "",
    "必填": "是",
    "说明": "需要添加的卡券列表",
    "子项": [
      {
        "结构属性": "cardId",
        "类型": "string",
        "默认值": "",
        "必填": "是",
        "说明": "卡券 ID"
      },
      {
        "结构属性": "cardExt",
        "类型": "string",
        "默认值": "",
        "必填": "是",
        "说明": "卡券的扩展参数。需将 CardExt 对象 JSON 序列化为**字符串**传入"
      }
    ]
  },
  {
    "属性": "success",
    "类型": "function",
    "默认值": "",
    "必填": "否",
    "说明": "接口调用成功的回调函数"
  },
  {
    "属性": "fail",
    "类型": "function",
    "默认值": "",
    "必填": "否",
    "说明": "接口调用失败的回调函数"
  },
  {
    "属性": "complete",
    "类型": "function",
    "默认值": "",
    "必填": "否",
    "说明": "接口调用结束的回调函数（调用成功、失败都会执行）"
  }
]
```

#### object.success 回调函数
##### 参数

###### Object res


```json
[
  {
    "属性": "cardList",
    "类型": "Array.<Object>",
    "说明": "卡券添加结果列表",
    "子项": [
      {
        "结构属性": "code",
        "类型": "string",
        "说明": "加密 code，为用户领取到卡券的code加密后的字符串，解密请参照：[code 解码接口](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1499332673_Unm7V)"
      },
      {
        "结构属性": "cardId",
        "类型": "string",
        "说明": "用户领取到卡券的 ID"
      },
      {
        "结构属性": "cardExt",
        "类型": "string",
        "说明": "卡券的扩展参数，结构请参考下文"
      },
      {
        "结构属性": "isSuccess",
        "类型": "boolean",
        "说明": "是否成功"
      }
    ]
  }
]
```

## cardExt 说明

cardExt 是卡券的扩展参数，其值是一个 JSON 字符串。

## 示例代码

```js
wx.addCard({
  cardList: [
    {
      cardId: '',
      cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
    }, {
      cardId: '',
      cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
    }
  ],
  success (res) {
    console.log(res.cardList) // 卡券添加结果
  }
})
```
