小程序接口#

class wechatpy.client.api.WeChatWxa(client=None)[源代码]#
add_store(data: dict) dict[源代码]#

添加门店 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#12

参数

data – 具体请参考文档

返回

参考文档

add_template(template_short_id, keyword_id_list)[源代码]#

⚠️已废弃 组合模板,并将其添加至账号下的模板列表里 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1500465446_j4CgR

参数
  • template_short_id – 模板标题ID

  • keyword_id_list (list[int]) – 按照顺序排列的模板关键词列表,最多10个

返回

模板ID

apply_merchant(data: dict) dict[源代码]#

创建门店小程序 创建门店小程序提交后需要公众号管理员确认通过后才可进行审核。如果主管理员24小时超时未确认,才能再次提交。 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#6

参数

data – 门店数据,具体请参考文档

bind_open(appid, open_appid)[源代码]#

将公众号/小程序绑定到开放平台帐号下 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1498704199_1bcax

参数
  • appid – 授权公众号或小程序的 appid

  • open_appid – 开放平台帐号 appid

bind_tester(wechat_id)[源代码]#

绑定微信用户成为小程序体验者 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140588_nVUgx

参数

wechat_id – 微信号

change_visit_status(close=False)[源代码]#

修改小程序线上代码的可见状态 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

参数

close (bool) – close 为 True 时会关闭小程序线上代码的可见状态。

check_image_security(media)[源代码]#

校验一张图片是否含有违法违规内容。 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html

参数

media – 要检测的图片文件,格式支持PNG、JPEG、JPG、GIF,图片尺寸不超过 750px x 1334px

返回

check_media_async(media_url: str, media_type: int)[源代码]#

异步校验图片/音频是否含有违法违规内容。

https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html

应用场景举例: 1. 语音风险识别:社交类用户发表的语音内容检测; 2. 图片智能鉴黄:涉及拍照的工具类应用(如美拍,识图类应用)用户拍照上传检测;电商类商品上架图片检测;媒体类用户文章里的图片检测等; 3. 敏感人脸识别:用户头像;媒体类用户文章里的图片检测;社交类用户上传的图片检测等。 频率限制:单个 appId 调用上限为 2000 次/分钟,200,000 次/天;文件大小限制:单个文件大小不超过10M

参数
  • media_url – 要检测的多媒体url

  • media_type – 1:音频;2:图片

返回

返回的 JSON 数据包

check_text_security(content, open_id=None, scene=None, nickname=None, title=None, signature=None, version=2)[源代码]#

检查一段文本是否含有违法违规内容。 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html

参数
  • content – 需检测的文本内容,文本字数的上限为2500字,需使用UTF-8编码

  • open_id – 用户的openid(用户需在近两小时访问过小程序)不传openid使用v1接口,后面参数都忽略

  • scene – 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)

  • nickname – 用户昵称,需使用UTF-8编码

  • title – 文本标题,需使用UTF-8编码

  • signature – 个性签名,该参数仅在资料类场景有效(scene=1),需使用UTF-8编码

  • version – 接口版本号,2.0版本为固定值2

返回

code_to_session(js_code)[源代码]#

登录凭证校验。通过 wx.login() 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。更多使用方法详见 小程序登录 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api/code2Session.html https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html

参数

js_code

返回

commit(template_id, ext_json, version, description)[源代码]#

为授权的小程序账号上传小程序代码 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

参数
  • template_id – 代码库中的代码模板 ID

  • ext_json – 第三方自定义的配置

  • version – 代码版本号,开发者可自定义

  • description – 代码描述,开发者可自定义

create_map_poi(data: dict) dict[源代码]#

在腾讯地图中创建门店 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#11

参数

data – 具体请参考文档

返回

参考文档

create_open(appid)[源代码]#

创建开放平台账号,并绑定公众号/小程序 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1498704199_1bcax

参数

appid – 授权公众号或小程序的 appid

返回

开放平台的 appid

create_qrcode(path, width=430)[源代码]#

创建小程序二维码(接口C:适用于需要的码数量较少的业务场景) 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html

del_store(poi_id: str) dict[源代码]#

删除门店 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#16

参数

poi_id – 为门店小程序添加门店,审核成功后返回的门店id

返回

参考文档

del_template(template_id)[源代码]#

⚠️已废弃 删除本账号内某个模板 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1500465446_j4CgR

参数

template_id – 模板ID

get_audit_status(auditid)[源代码]#

查询某个指定版本的审核状态 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

参数

auditid (int) – 审核编号

返回

一个包含 status, reason 的 dict。status 0为审核成功,1为审核失败,2为审核中。

get_category()[源代码]#

获取授权小程序账号的可选类目 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

返回类型

list[dict]

get_district() dict[源代码]#

从腾讯地图拉取省市区信息 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#9 :return: 参考文档

get_latest_audit_status()[源代码]#

查询最近一次提交的审核状态 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

返回

一个包含 status, reason, auditid 的 dict。status 0为审核成功,1为审核失败,2为审核中。

get_library_template(template_short_id)[源代码]#

⚠️已废弃 获取小程序模板库里,某个模板的详细信息 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1500465446_j4CgR

参数

template_short_id – 模板标题ID

返回类型

dict

get_merchant_audit_info() dict[源代码]#

查询门店小程序审核结果 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#7

get_merchant_category() dict[源代码]#

拉取门店小程序类目

https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#5

get_open(appid)[源代码]#

获取公众号/小程序所绑定的开放平台账号 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1498704199_1bcax

参数

appid – 授权公众号或小程序的 appid

返回

开放平台的 appid

get_page()[源代码]#

获取小程序的第三方提交代码的页面配置 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

返回类型

list

get_paid_unionid(openid, transaction_id=None, mch_id=None, out_trade_no=None)[源代码]#

用户支付完成后,获取该用户的 UnionId,无需用户授权。

详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.getPaidUnionId.html

参数
  • openid – 支付用户唯一标识

  • transaction_id – 微信支付订单号,可选

  • mch_id – 微信支付分配的商户号,和商户订单号配合使用,可选

  • out_trade_no – 微信支付商户订单号,和商户号配合使用

返回

用户唯一标识 unionid

get_phone_number(code)[源代码]#

code换取用户手机号。 每个code只能使用一次,code的有效期为5min 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html

:param code :return:

get_qrcode()[源代码]#

获取体验小程序的体验二维码 返回 Response 类型,header 中带有 Content-Type 与 Content-disposition 类型 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

返回类型

requests.Response

get_store_info(poi_id: str) dict[源代码]#

获取单个门店信息 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#14

参数

poi_id – 为门店小程序添加门店,审核成功后返回的门店id

返回

门店信息

get_store_list(offset: int = 0, limit: int = 10) dict[源代码]#

获取门店信息列表 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#15

参数
  • offset – 获取门店列表的初始偏移位置,从0开始计数

  • limit – 获取门店个数

返回

参考文档

获取小程序 URL Link,适用于短信、邮件、网页、微信内等拉起小程序的业务场景。 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html

:param path, 通过 URL Link 进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query :param query, 通过 URL Link 进入小程序时的query,最大1024个字符,只支持数字,大小写英文以及部分特殊字符 :param is_expire, 到期失效:True,永久有效:False 默认False, 永久有效上限10万 :param expire_type, 失效时间:0,失效间隔天数:1 :param expire_time, 到期失效的 scheme 码的失效时间, Unix 时间戳, is_expire 为 true 且 expire_type 为 0 时必填 :param expire_interval, 到期失效的 scheme 码的失效间隔天数。生成的到期失效 scheme 码在该间隔时间到达前有效。

最长间隔天数为365天。is_expire 为 true 且 expire_type 为 1 时必填

:param cloud_base, 云开发静态网站自定义 H5 配置参数,可配置中转的云开发 H5 页面。不填默认用官方 H5 页面。

返回类型

requests.Response

get_url_scheme(is_expire=False, expire_type=0, expire_time=None, expire_interval=None, jump_wxa=())[源代码]#

获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html

:param is_expire, 到期失效:True,永久有效:False 默认False, 永久有效上限10万 :param expire_type, 失效时间:0,失效间隔天数:1 :param expire_time, 到期失效的 scheme 码的失效时间, Unix 时间戳, is_expire 为 true 且 expire_type 为 0 时必填 :param expire_interval, 到期失效的 scheme 码的失效间隔天数。生成的到期失效 scheme 码在该间隔时间到达前有效。最长间隔天数为365天。

is_expire 为 true 且 expire_type 为 1 时必填。

:param jump_wxa, 跳转到的目标小程序信息。

返回类型

requests.Response

get_wxa_code(path, width=430, auto_color=False, line_color=None, is_hyaline=False)[源代码]#

创建小程序码(接口A: 适用于需要的码数量较少的业务场景) 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.get.html

get_wxa_code_unlimited(scene, width=430, auto_color=False, line_color=None, page=None, is_hyaline=False)[源代码]#

创建小程序码(接口B:适用于需要的码数量极多,或仅临时使用的业务场景) 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html

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

⚠️已废弃 获取小程序模板库里,所有模板的ID与标题 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1500465446_j4CgR

参数
  • offset (int) – 用于分页,表示起始量,最小值为0

  • count (int) – 用于分页,表示拉取数量,最大值为20

返回

带有 total_count 与 list 的数据

返回类型

dict

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

⚠️已废弃 获取本账号内所有模板 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1500465446_j4CgR

参数
  • offset (int) – 用于分页,表示起始量,最小值为0

  • count (int) – 用于分页,表示拉取数量,最大值为20

返回

模板列表

返回类型

list[dict]

modify_domain(action, request_domain=(), wsrequest_domain=(), upload_domain=(), download_domain=())[源代码]#

修改小程序服务器授权域名 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489138143_WPbOO

参数
  • action – 增删改查的操作类型,仅支持 ‘add’, ‘delete’, ‘set’, ‘get’

  • request_domain – request 合法域名

  • wsrequest_domain – socket 合法域名

  • upload_domain – upload file 合法域名

  • download_domain – download file 合法域名

modify_merchant(data: dict) dict[源代码]#

修改门店小程序信息 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#8

参数

data – 具体请参考文档

返回

参考文档

ocr_biz_license(img_url: Optional[str] = None, filename: Optional[str] = None, file_bytes: Optional[bytes] = None, mime_type: Optional[str] = None) dict[源代码]#

基于小程序的营业执照 OCR 识别 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/ocr/ocr.businessLicense.html

参数
  • img_url – 要检测的图片 url,传这个则不用传 img 参数。

  • filename – 要检测的图片文件名。

  • file_bytes – 要检测的图片二进制数据。

  • mime_type – 要检测的图片格式。

返回

参考文档

ocr_idcard(mode: str = 'photo', img_url: Optional[str] = None, filename: Optional[str] = None, file_bytes: Optional[bytes] = None, mime_type: Optional[str] = None) dict[源代码]#

基于小程序的身份证 OCR 识别

https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/ocr/ocr.idcard.html

参数
  • img_url – 要检测的图片 url,传这个则不用传 img 参数。

  • mode – photo:拍照模型,带背景的图片, scan:扫描模式,不带背景的图片

  • filename – 要检测的图片文件名。

  • file_bytes – 要检测的图片二进制数据。

  • mime_type – 要检测的图片格式。

返回

参考文档

query_quota()[源代码]#

查询服务商的当月提审限额(quota)和加急次数 服务商可以调用该接口,查询当月平台分配的提审限额和剩余可提审次数,以及当月分配的审核加急次数和剩余加急次数。(所有旗下小程序共用该额度) https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/query_quota.html

release()[源代码]#

发布已通过审核的小程序 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140610_Uavc4

revert_code_release()[源代码]#

调用本接口可以将小程序的线上版本进行回退 注意: 1. 如果没有上一个线上版本,将无法回退 2. 只能向上回退一个版本,即当前版本回退后,不能再调用版本回退接口 https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/revertcoderelease.html

search_map_poi(data: dict) dict[源代码]#

在腾讯地图中搜索门店 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#10

参数

data – 具体请参考文档

返回

参考文档

send_subscribe_message(user_id, template_id, data, page=None)[源代码]#

发送小程序订阅消息 详情请参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html

send_template_message(user_id, template_id, data, form_id, page=None, color=None, emphasis_keyword=None)[源代码]#

⚠️已废弃 发送模板消息 详情请参考 https://mp.weixin.qq.com/debug/wxadoc/dev/api/notice.html

speed_up_audit(auditid)[源代码]#

加急审核申请 有加急次数的第三方可以通过该接口,对已经提审的小程序进行加急操作,加急后的小程序预计2-12小时内审完。 https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/speedup_audit.html

submit_audit(data)[源代码]#

将第三方提交的代码包提交审核 详情请参考 https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/submit_audit.html

unbind_open(appid, open_appid)[源代码]#

将公众号/小程序绑定到开放平台帐号下 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1498704199_1bcax

参数
  • appid – 授权公众号或小程序的 appid

  • open_appid – 开放平台帐号 appid

unbind_tester(wechat_id)[源代码]#

解除绑定小程序的体验者 详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&id=open1489140588_nVUgx

参数

wechat_id – 微信号

undo_code_audit()[源代码]#

调用本接口可以撤回当前的代码审核单 注意: 单个帐号每天审核撤回次数最多不超过 1 次,一个月不超过 10 次。 https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/undocodeaudit.html

update_store(data: dict) dict[源代码]#

更新门店信息 https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html#13

参数

data – 具体请参考文档

返回

参考文档