卡券接口#

class wechatpy.client.api.WeChatCard(client=None)[源代码]#
activate_membercard(membership_number, code, **kwargs)[源代码]#

激活会员卡 - 接口激活方式

详情请参见 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#14

参数示例: {

“init_bonus”: 100, “init_bonus_record”:”旧积分同步”, “init_balance”: 200, “membership_number”: “AAA00000001”, “code”: “12312313”, “card_id”: “xxxx_card_id”, “background_pic_url”: “https://mmbiz.qlogo.cn/mmbiz/0?wx_fmt=jpeg”, “init_custom_field_value1”: “xxxxx”, “init_custom_field_value2”: “xxxxx”, “init_custom_field_value3”: “xxxxx”

}

返回示例: {“errcode”:0, “errmsg”:”ok”}

参数
  • membership_number – 必填,会员卡编号,由开发者填入,作为序列号显示在用户的卡包里。可与Code码保持等值

  • code – 必填,领取会员卡用户获得的code

返回

参见返回示例

add_pay_giftcard(base_info, extra_info, is_membercard)[源代码]#

新增支付后投放卡券的规则,支持支付后领卡,支付后赠券

详情请参见 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Manage_Member_Card.html#4

参数
  • base_info (dict) – 营销规则结构体

  • extra_info (dict) – 支付规则结构体

  • is_membercard (bool) – 本次规则是否是领卡。(领卡传入 True, 赠券传入 False)

返回

规则 ID, 设置成功的列表,以及设置失败的列表

batch_add_locations(location_data)[源代码]#

⚠️已废弃 批量导入门店信息

参数

location_data – 门店信息

返回

门店 ID 列表,插入失败的门店元素值为 -1

batch_get(offset=0, count=50, status_list=None)[源代码]#

批量查询卡券信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#3

参数
  • offset – 查询卡列表的起始偏移量,从0开始,即offset: 5是指从从列表里的第六个开始读取。

  • count – 需要查询的卡片的数量(数量最大50)

  • status_list – 支持开发者拉出指定状态的卡券列表

batch_get_locations(offset=0, count=0)[源代码]#

⚠️已废弃 批量获取门店信息

batch_get_pay_giftcard(effective=True, offset=0, count=10)[源代码]#

批量查询支付后投放卡券的规则

详情请参见 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Manage_Member_Card.html#4

参数
  • effective (bool) – 是否仅查询生效的规则

  • offset (int) – 起始偏移量

  • count (int) – 查询的数量

返回

支付后投放卡券规则的总数,以及查询到的列表

check_code(card_id, codes)[源代码]#

核查code

checkin_boardingpass(code, passenger_name, seat_class, etkt_bnr, seat='', gate='', boarding_time=None, is_cancel=False, qrcode_data=None, card_id=None)[源代码]#

飞机票接口

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Special_ticket.html#3

consume_code(code, card_id=None)[源代码]#

消耗 code

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Redeeming_a_coupon_voucher_or_card.html#0

create(card_data)[源代码]#

创建卡券

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Create_a_Coupon_Voucher_or_Card.html#8

参数

card_data – 卡券信息

返回

创建的卡券 ID

create_landingpage(buffer_data)[源代码]#

创建货架

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Distributing_Coupons_Vouchers_and_Cards.html#3

create_qrcode(qrcode_data)[源代码]#

创建卡券二维码

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Distributing_Coupons_Vouchers_and_Cards.html#0

参数

qrcode_data – 二维码信息

返回

二维码 ticket,可使用 :func:show_qrcode 换取二维码文件

decrypt_code(encrypt_code)[源代码]#

解码加密的 code

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Redeeming_a_coupon_voucher_or_card.html#0

del_pay_giftcard(rule_id)[源代码]#

删除支付后投放卡券的规则

详情请参见 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Manage_Member_Card.html#4

参数

rule_id – 支付即会员的规则 ID

delete(card_id)[源代码]#

删除卡券

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#7

deposit_code(card_id, codes)[源代码]#

导入code

get(card_id)[源代码]#

查询卡券详情

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#2

get_activate_info(activate_ticket)[源代码]#

获取用户开卡时提交的信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#16

参数

activate_ticket – 跳转型开卡组件开卡后回调中的激活票据,可以用来获取用户开卡资料

返回

用户开卡时填写的字段值

get_activate_url(card_id, outer_str=None)[源代码]#

获取开卡插件 Url, 内含调用开卡插件所需的参数 详情请参考 https://mp.weixin.qq.com/wiki?id=mp1499332673_Unm7V

参数
  • card_id – 会员卡的card_id

  • outer_str – 渠道值,用于统计本次领取的渠道参数

返回

内含调用开卡插件所需的参数的 Url

get_card_list(openid, card_id=None)[源代码]#

用于获取用户卡包里的,属于该appid下的卡券。

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#1

get_code(code, card_id=None, check_consume=True)[源代码]#

查询 code 信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#0

get_colors()[源代码]#

获得卡券的最新颜色列表,用于创建卡券 目前微信提供包括十四种色值供开发者使用。

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Create_a_Coupon_Voucher_or_Card.html#7

返回

颜色列表

get_deposit_count(card_id)[源代码]#

查询导入code数目

get_html(card_id)[源代码]#

图文消息群发卡券

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Distributing_Coupons_Vouchers_and_Cards.html#6

get_membercard_user_info(card_id, code)[源代码]#

查询会员卡的会员信息

详情请参见 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#16

参数
  • card_id – 查询会员卡的 Card ID

  • code – 所查询用户领取到的 code 值

返回

会员信息,包括激活资料、积分信息以及余额等信息

get_pay_giftcard(rule_id)[源代码]#

查询支付后投放卡券的规则

详情请参见 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Manage_Member_Card.html#4

参数

rule_id – 支付即会员的规则 ID

返回

支付后投放卡券的规则

返回类型

dict

get_redirect_url(url, encrypt_code, card_id)[源代码]#

获取卡券跳转外链

invalid_code(code, card_id=None)[源代码]#

设置卡券失效

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#8

modify_stock(card_id, n)[源代码]#

修改库存

set_activate_user_form(card_id, **kwargs)[源代码]#

设置开卡字段接口

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#16

“6 激活会员卡” -> “6.2 一键激活” -> “步骤二:设置开卡字段接口”

参数示例: {

“card_id”: “pbLatjnrwUUdZI641gKdTMJzHGfc”, “service_statement”: {

“name”: “会员守则”, “url”: “https://www.qq.com

}, “bind_old_card”: {

“name”: “老会员绑定”, “url”: “https://www.qq.com

}, “required_form”: {

“can_modify”:false, “rich_field_list”: [

{

“type”: “FORM_FIELD_RADIO”, “name”: “兴趣”, “values”: [

“钢琴”, “舞蹈”, “足球”

]

}, {

“type”: “FORM_FIELD_SELECT”, “name”: “喜好”, “values”: [

“郭敬明”, “韩寒”, “南派三叔”

]

}, {

“type”: “FORM_FIELD_CHECK_BOX”, “name”: “职业”, “values”: [

“赛车手”, “旅行家”

]

}

], “common_field_id_list”: [

“USER_FORM_INFO_FLAG_MOBILE”

]

}, “optional_form”: {

“can_modify”:false, “common_field_id_list”: [

“USER_FORM_INFO_FLAG_LOCATION”, “USER_FORM_INFO_FLAG_BIRTHDAY”

], “custom_field_list”: [

“喜欢的电影”

]

}

} common_field_id_list 值见常量 wechatpy.constants.UserFormInfoFlag

参数
  • card_id – 卡券ID

  • kwargs – 其他非必填参数,见微信文档

set_paycell(card_id, is_open)[源代码]#

设置买单接口

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Create_a_Coupon_Voucher_or_Card.html#12

set_test_whitelist(openids=None, usernames=None)[源代码]#

设置卡券测试用户白名单

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Distributing_Coupons_Vouchers_and_Cards.html#12

update(card_data)[源代码]#

更新卡券信息

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#4

update_code(card_id, old_code, new_code)[源代码]#

更新卡券 code

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#6

参数
  • card_id – 卡券ID。自定义 Code 码卡券为必填

  • old_code – 需变更的 Code 码

  • new_code – 变更后的有效 Code 码

update_luckymoney_balance(code, balance, card_id=None)[源代码]#

⚠️已废弃 更新红包余额

update_membercard(code, card_id, **kwargs)[源代码]#

更新会员信息

详情请参见 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Membership_Cards/Create_a_membership_card.html#18

注意事项: 1.开发者可以同时传入add_bonus和bonus解决由于同步失败带来的幂等性问题。同时传入add_bonus和bonus时

add_bonus作为积分变动消息中的变量值,而bonus作为卡面上的总积分额度显示。余额变动同理。

2.开发者可以传入is_notify_bonus控制特殊的积分对账变动不发送消息,余额变动同理。

参数示例: {

“code”: “179011264953”, “card_id”: “p1Pj9jr90_SQRaVqYI239Ka1erkI”, “background_pic_url”: “https://mmbiz.qlogo.cn/mmbiz/0?wx_fmt=jpeg”, “record_bonus”: “消费30元,获得3积分”, “bonus”: 3000, “add_bonus”: 30, “balance”: 3000, “add_balance”: -30, “record_balance”: “购买焦糖玛琪朵一杯,扣除金额30元。”, “custom_field_value1”: “xxxxx”, “custom_field_value2”: “xxxxx”, “notify_optional”: {

“is_notify_bonus”: true, “is_notify_balance”: true, “is_notify_custom_field1”:true

}

}

返回示例: {

“errcode”: 0, “errmsg”: “ok”, “result_bonus”: 100, “result_balance”: 200, “openid”: “oFS7Fjl0WsZ9AMZqrI80nbIq8xrA”

}

参数
  • code – 必填,卡券Code码

  • card_id – 必填,卡券ID

  • kwargs – 其他非必填字段,包含则更新对应字段。详情参见微信文档 “7 更新会员信息” 部分

返回

参见返回示例

update_movie_ticket(code, ticket_class, show_time, duration, screening_room, seat_number, card_id=None)[源代码]#

更新电影票

详情请参考 https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Special_ticket.html#7