INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
发送模板消息 | def send_template(self, user_id, template_id, data, url=None, mini_program=None):
"""
发送模板消息
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1445241432&lang=zh_CN
:param user_id: 用户 ID 。 就是你收到的 `Message` 的 source
:param template_id: 模板 ID。在公众平台线上模板库中选用模板获得
:param url: ... |
群发卡券消息 | def send_mass_card(self, group_or_users, card_id,
is_to_all=False, preview=False,
send_ignore_reprint=0, client_msg_id=None):
"""
群发卡券消息
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1481187827_i0l21
:param group_or_users: 值为整型数字时为按分组群发,... |
构造请求用户授权的url 详情请参阅: https:// mp. weixin. qq. com/ wiki?id = mp1500374289_66bvB | def get_subscribe_authorize_url(self, scene, template_id, redirect_url, reserved=None):
"""
构造请求用户授权的url
详情请参阅:
https://mp.weixin.qq.com/wiki?id=mp1500374289_66bvB
:param scene: 订阅场景值,开发者可以填0-10000的整形值,用来标识订阅场景值
:type scene: int
:param template_id: 订阅消息模板ID,登录公众平... |
一次性订阅消息,通过API推送订阅模板消息给到授权微信用户。 详情请参阅: https:// mp. weixin. qq. com/ wiki?id = mp1500374289_66bvB | def send_subscribe_template(self, openid, template_id, scene, title, data, url=None):
"""
一次性订阅消息,通过API推送订阅模板消息给到授权微信用户。
详情请参阅:
https://mp.weixin.qq.com/wiki?id=mp1500374289_66bvB
:param openid: 填接收消息的用户openid
:param template_id: 订阅消息模板ID
:param scene: 订阅场景值,开发者可... |
添加客服账号 详情请参考 http:// mp. weixin. qq. com/ wiki/ 1/ 70a29afed17f56d537c833f89be979c9. html | def add_account(self, account, nickname, password):
"""
添加客服账号
详情请参考
http://mp.weixin.qq.com/wiki/1/70a29afed17f56d537c833f89be979c9.html
:param account: 完整客服账号,格式为:账号前缀@公众号微信号
:param nickname: 客服昵称,最长6个汉字或12个英文字符
:param password: 客服账号登录密码
:return: 返回的 JS... |
删除客服账号 详情请参考 http:// mp. weixin. qq. com/ wiki/ 1/ 70a29afed17f56d537c833f89be979c9. html | def delete_account(self, account):
"""
删除客服账号
详情请参考
http://mp.weixin.qq.com/wiki/1/70a29afed17f56d537c833f89be979c9.html
:param account: 完整客服账号,格式为:账号前缀@公众号微信号
:return: 返回的 JSON 数据包
"""
params_data = [
'access_token={0}'.format(quote(self.acce... |
上传客服账号头像 详情请参考 http:// mp. weixin. qq. com/ wiki/ 1/ 70a29afed17f56d537c833f89be979c9. html | def upload_headimg(self, account, media_file):
"""
上传客服账号头像
详情请参考
http://mp.weixin.qq.com/wiki/1/70a29afed17f56d537c833f89be979c9.html
:param account: 完整客服账号
:param media_file: 要上传的头像文件,一个 File-Object
:return: 返回的 JSON 数据包
"""
return self._post(
... |
多客服创建会话 详情请参考 http:// mp. weixin. qq. com/ wiki/ 2/ 6c20f3e323bdf5986cfcb33cbd3b829a. html | def create_session(self, openid, account, text=None):
"""
多客服创建会话
详情请参考
http://mp.weixin.qq.com/wiki/2/6c20f3e323bdf5986cfcb33cbd3b829a.html
:param openid: 客户 openid
:param account: 完整客服账号
:param text: 附加信息,可选
:return: 返回的 JSON 数据包
"""
dat... |
获取客服的会话列表 详情请参考 http:// mp. weixin. qq. com/ wiki/ 2/ 6c20f3e323bdf5986cfcb33cbd3b829a. html | def get_session_list(self, account):
"""
获取客服的会话列表
详情请参考
http://mp.weixin.qq.com/wiki/2/6c20f3e323bdf5986cfcb33cbd3b829a.html
:param account: 完整客服账号
:return: 客服的会话列表
"""
res = self._get(
'https://api.weixin.qq.com/customservice/kfsession/getse... |
获取客服聊天记录 | def get_records(self, start_time, end_time, msgid=1,
number=10000):
"""
获取客服聊天记录
:param start_time: 查询开始时间,UNIX 时间戳
:param end_time: 查询结束时间,UNIX 时间戳,每次查询不能跨日查询
:param msgid: 消息id顺序从小到大,从1开始
:param number: 每次获取条数,最多10000条
:return: 返回的 JSON 数据包... |
Create a reply quickly | def create_reply(reply, message=None, render=False):
"""
Create a reply quickly
"""
r = None
if not reply:
r = EmptyReply()
elif isinstance(reply, BaseReply):
r = reply
if message:
r.source = message.target
r.target = message.source
elif isinst... |
反序列化被动回复: param xml: 待反序列化的xml: param update_time: 是否用当前时间替换xml中的时间: raises ValueError: 不能辨识的reply xml: rtype: wechatpy. replies. BaseReply | def deserialize_reply(xml, update_time=False):
"""
反序列化被动回复
:param xml: 待反序列化的xml
:param update_time: 是否用当前时间替换xml中的时间
:raises ValueError: 不能辨识的reply xml
:rtype: wechatpy.replies.BaseReply
"""
if not xml:
return EmptyReply()
try:
reply_dict = xmltodict.parse(xml)["xm... |
Render reply from Python object to XML string | def render(self):
"""Render reply from Python object to XML string"""
tpl = '<xml>\n{data}\n</xml>'
nodes = []
msg_type = '<MsgType><![CDATA[{msg_type}]]></MsgType>'.format(
msg_type=self.type
)
nodes.append(msg_type)
for name, field in self._fields.it... |
获取 component_access_token 详情请参考 https:// open. weixin. qq. com/ cgi - bin/ showdocument?action = dir_list \ &t = resource/ res_list&verify = 1&id = open1419318587&token = &lang = zh_CN | def fetch_access_token(self):
"""
获取 component_access_token
详情请参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list\
&t=resource/res_list&verify=1&id=open1419318587&token=&lang=zh_CN
:return: 返回的 JSON 数据包
"""
url = '{0}{1}'.format(
self.... |
The real fetch access token | def _fetch_access_token(self, url, data):
""" The real fetch access token """
logger.info('Fetching component access token')
res = self._http.post(
url=url,
data=data
)
try:
res.raise_for_status()
except requests.RequestException as req... |
快速获取pre auth url,可以直接微信中发送该链接,直接授权 | def get_pre_auth_url_m(self, redirect_uri):
"""
快速获取pre auth url,可以直接微信中发送该链接,直接授权
"""
url = "https://mp.weixin.qq.com/safe/bindcomponent?action=bindcomponent&auth_type=3&no_scan=1&"
redirect_uri = quote(redirect_uri, safe='')
return "{0}component_appid={1}&pre_auth_code=... |
使用授权码换取公众号的授权信息 同时储存token信息 | def query_auth(self, authorization_code):
"""
使用授权码换取公众号的授权信息,同时储存token信息
:params authorization_code: 授权code,会在授权成功时返回给第三方平台,详见第三方平台授权流程说明
"""
result = self._query_auth(authorization_code)
assert result is not None \
and 'authorization_info' in result \
... |
获取(刷新)授权公众号的令牌 | def refresh_authorizer_token(
self, authorizer_appid, authorizer_refresh_token):
"""
获取(刷新)授权公众号的令牌
:params authorizer_appid: 授权方appid
:params authorizer_refresh_token: 授权方的刷新令牌
"""
return self.post(
'/component/api_authorizer_token',
... |
获取授权方的选项设置信息 | def get_authorizer_option(self, authorizer_appid, option_name):
"""
获取授权方的选项设置信息
:params authorizer_appid: 授权公众号appid
:params option_name: 选项名称
"""
return self.post(
'/component/api_get_authorizer_option',
data={
'component_appid':... |
设置授权方的选项信息 | def set_authorizer_option(
self, authorizer_appid, option_name, option_value):
"""
设置授权方的选项信息
:params authorizer_appid: 授权公众号appid
:params option_name: 选项名称
:params option_value: 设置的选项值
"""
return self.post(
'/component/api_set_authorizer_... |
通过授权码直接获取 Client 对象 | def get_client_by_authorization_code(self, authorization_code):
"""
通过授权码直接获取 Client 对象
:params authorization_code: 授权code,会在授权成功时返回给第三方平台,详见第三方平台授权流程说明
"""
warnings.warn('`get_client_by_authorization_code` method of `WeChatComponent` is deprecated,'
'Use `... |
通过 authorizer_appid 获取 Client 对象 | def get_client_by_appid(self, authorizer_appid):
"""
通过 authorizer_appid 获取 Client 对象
:params authorizer_appid: 授权公众号appid
"""
access_token_key = '{0}_access_token'.format(authorizer_appid)
refresh_token_key = '{0}_refresh_token'.format(authorizer_appid)
access_t... |
处理 wechat server 推送消息 | def parse_message(self, msg, msg_signature, timestamp, nonce):
"""
处理 wechat server 推送消息
:params msg: 加密内容
:params msg_signature: 消息签名
:params timestamp: 时间戳
:params nonce: 随机数
"""
content = self.crypto.decrypt_message(msg, msg_signature, timestamp, nonce... |
处理 wechat server 推送的 component_verify_ticket消息 | def cache_component_verify_ticket(self, msg, signature, timestamp, nonce):
"""
处理 wechat server 推送的 component_verify_ticket消息
:params msg: 加密内容
:params signature: 消息签名
:params timestamp: 时间戳
:params nonce: 随机数
"""
warnings.warn('`cache_component_verify_ti... |
处理取消授权通知 | def get_unauthorized(self, msg, signature, timestamp, nonce):
"""
处理取消授权通知
:params msg: 加密内容
:params signature: 消息签名
:params timestamp: 时间戳
:params nonce: 随机数
"""
warnings.warn('`get_unauthorized` method of `WeChatComponent` is deprecated,'
... |
获取 access_token | def fetch_access_token(self, code):
"""获取 access_token
:param code: 授权完成跳转回来后 URL 中的 code 参数
:return: JSON 数据包
"""
res = self._get(
'sns/oauth2/component/access_token',
params={
'appid': self.app_id,
'component_appid': self... |
获取用户基本信息(需授权作用域为snsapi_userinfo) | def get_user_info(self, openid=None, access_token=None, lang='zh_CN'):
""" 获取用户基本信息(需授权作用域为snsapi_userinfo)
如果网页授权作用域为snsapi_userinfo,则此时开发者可以通过access_token和openid拉取用户信息了。
:param openid: 可选,微信 openid,默认获取当前授权用户信息
:param access_token: 可选,access_token,默认使用当前授权用户的 access_token
:pa... |
获取授权跳转地址 | def authorize_url(self):
"""获取授权跳转地址
:return: URL 地址
"""
redirect_uri = quote(self.redirect_uri, safe=b'')
url_list = [
self.OAUTH_BASE_URL,
'oauth2/authorize?appid=',
self.app_id,
'&redirect_uri=',
redirect_uri,
... |
获取 access_token | def fetch_access_token(self, code):
"""获取 access_token
:param code: 授权完成跳转回来后 URL 中的 code 参数
:return: JSON 数据包
"""
res = self._get(
'sns/oauth2/access_token',
params={
'appid': self.app_id,
'secret': self.secret,
... |
刷新 access token | def refresh_access_token(self, refresh_token):
"""刷新 access token
:param refresh_token: OAuth2 refresh token
:return: JSON 数据包
"""
res = self._get(
'sns/oauth2/refresh_token',
params={
'appid': self.app_id,
'grant_type': 'r... |
检查 access_token 有效性 | def check_access_token(self, openid=None, access_token=None):
"""检查 access_token 有效性
:param openid: 可选,微信 openid,默认获取当前授权用户信息
:param access_token: 可选,access_token,默认使用当前授权用户的 access_token
:return: 有效返回 True,否则 False
"""
openid = openid or self.open_id
access_toke... |
新增其它类型永久素材 详情请参考 https:// qydev. weixin. qq. com/ wiki/ index. php?title = %E4%B8%8A%E4%BC%A0%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90 | def add(self, agent_id, media_type, media_file):
"""
新增其它类型永久素材
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90
:param agent_id: 企业应用的id
:param media_type: 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)普通文件(file)
... |
获取永久素材下载地址 详情请参考 https:// qydev. weixin. qq. com/ wiki/ index. php?title = %E8%8E%B7%E5%8F%96%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90 | def get_url(self, agent_id, media_id):
"""
获取永久素材下载地址
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90
:param agent_id: 企业应用的id
:param media_id: 媒体文件 ID
:return: 临时素材下载地址
"""
parts = (
... |
获取永久素材 详情请参考 https:// qydev. weixin. qq. com/ wiki/ index. php?title = %E8%8E%B7%E5%8F%96%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90 | def get(self, agent_id, media_id):
"""
获取永久素材
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90
:param agent_id: 企业应用的id
:param media_id: 媒体文件 ID
:return: requests 的 Response 实例
"""
retur... |
修改永久图文素材 详情请参考 https:// qydev. weixin. qq. com/ wiki/ index. php?title = %E4%BF%AE%E6%94%B9%E6%B0%B8%E4%B9%85%E5%9B%BE%E6%96%87%E7%B4%A0%E6%9D%90 | def update_articles(self, agent_id, media_id, articles):
"""
修改永久图文素材
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=%E4%BF%AE%E6%94%B9%E6%B0%B8%E4%B9%85%E5%9B%BE%E6%96%87%E7%B4%A0%E6%9D%90
:param media_id: 要修改的图文消息的 id
:param index: 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意... |
批量获取永久素材列表 详情请参考 https:// qydev. weixin. qq. com/ wiki/ index. php?title = %E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8 | def batchget(self, agent_id, media_type, offset=0, count=20):
"""
批量获取永久素材列表
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8
:param agent_id: 企业应用的id
:param media_type: 媒体文件类型,分别有图文(mpnews)、图片(image)、
... |
创建菜单 | def create(self, agent_id, menu_data):
"""
创建菜单
https://work.weixin.qq.com/api/doc#90000/90135/90231
:param agent_id: 应用id
"""
return self._post(
'menu/create',
params={
'agentid': agent_id
},
data=menu_dat... |
获取微信 JS - SDK ticket | def get_jsapi_ticket(self):
"""
获取微信 JS-SDK ticket
该方法会通过 session 对象自动缓存管理 ticket
:return: ticket
"""
ticket_key = '{0}_jsapi_ticket'.format(self.appid)
expires_at_key = '{0}_jsapi_ticket_expires_at'.format(self.appid)
ticket = self.session.get(ticket_ke... |
获取 api_ticket:是用于调用微信卡券JS API的临时票据,有效期为7200 秒,通过access_token 来获取。 微信文档地址:http:// mp. weixin. qq. com/ wiki/ 7/ aaa137b55fb2e0456bf8dd9148dd613f. html 该方法会通过 session 对象自动缓存管理 ticket | def get_jsapi_card_ticket(self):
"""
获取 api_ticket:是用于调用微信卡券JS API的临时票据,有效期为7200 秒,通过access_token 来获取。
微信文档地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
该方法会通过 session 对象自动缓存管理 ticket
:return: ticket
"""
jsapi_card_ticket_key = '{0}_jsap... |
参数意义见微信文档地址:http:// mp. weixin. qq. com/ wiki/ 7/ aaa137b55fb2e0456bf8dd9148dd613f. html: param card_ticket: 用于卡券的微信 api_ticket: param card_type:: param kwargs: 非必须参数:noncestr timestamp code openid fixed_begintimestamp outer_str: return: 包含调用jssdk所有所需参数的 dict | def get_jsapi_card_params(self, card_ticket, card_type, **kwargs):
"""
参数意义见微信文档地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
:param card_ticket: 用于卡券的微信 api_ticket
:param card_type:
:param kwargs: 非必须参数:noncestr, timestamp, code, openid, fixed_begintim... |
创建发票卡券模板 注意这里的对象和会员卡有类似之处,但是含义有不同。创建发票卡券模板是创建发票卡券的基础。 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1496561481_1TyO7 | def create_card(self, base_info, payee, invoice_type, detail=None):
"""
创建发票卡券模板
注意这里的对象和会员卡有类似之处,但是含义有不同。创建发票卡券模板是创建发票卡券的基础。
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1496561481_1TyO7
:param base_info:发票卡券模板基础信息
:type base_info: dict
:param payee: 收款方(开票方... |
获取授权页链接 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1497082828_r1cI2 | def get_auth_url(self, s_pappid, order_id, money, timestamp, source, ticket, auth_type, redirect_url=None):
"""
获取授权页链接
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1497082828_r1cI2
:param s_pappid: 开票平台在微信的标识号,商户需要找开票平台提供
:param order_id: 订单id,在商户内单笔开票请求的唯一识别号
:para... |
设置授权页字段信息 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1497082828_r1cI2 | def set_auth_field(self, user_field, biz_field):
"""
设置授权页字段信息
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1497082828_r1cI2
:param user_field: 授权页个人发票字段
:type user_field: dict
:param biz_field: 授权页单位发票字段
:type biz_field: dict
"""
return self.... |
拒绝用户的开发票请求 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1497082828_r1cI2 | def reject_insert(self, s_pappid, order_id, reason, redirect_url=None):
"""
拒绝用户的开发票请求
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1497082828_r1cI2
:param s_pappid: 开票平台在微信的标识号,商户需要找开票平台提供
:param order_id: 订单id,在商户内单笔开票请求的唯一识别号
:param reason: 拒绝原因
:param red... |
制作发票卡券,并放入用户卡包 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1497082828_r1cI2 | def insert(self, order_id, card_id, appid, card_ext):
"""
制作发票卡券,并放入用户卡包
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1497082828_r1cI2
:param order_id: 订单id,在商户内单笔开票请求的唯一识别号
:param card_id: 发票卡券模板的编号
:param appid: 商户 AppID
:param card_ext: 发票具体内容
:typ... |
上传电子发票中的消费凭证 PDF 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1497082828_r1cI2 | def upload_pdf(self, pdf):
"""
上传电子发票中的消费凭证 PDF
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1497082828_r1cI2
:param pdf: 要上传的 PDF 文件,一个 File-object
:return: 64位整数,在将发票卡券插入用户卡包时使用用于关联pdf和发票卡券。有效期为3天。
"""
return self._post(
'platform/setpdf',
... |
更新发票卡券的状态 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1497082828_r1cI2 | def update_status(self, card_id, code, reimburse_status):
"""
更新发票卡券的状态
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1497082828_r1cI2
:param card_id: 发票卡券模板的编号
:param code: 发票卡券的编号
:param reimburse_status: 发票报销状态
"""
return self._post(
'pl... |
关联商户号与开票平台,设置支付后开票 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1496561731_2Z55U | def set_pay_mch(self, mchid, s_pappid):
"""
关联商户号与开票平台,设置支付后开票
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1496561731_2Z55U
:param mchid: 微信支付商户号
:param s_pappid: 开票平台在微信的标识号,商户需要找开票平台提供
"""
return self._post(
'setbizattr',
params={
... |
报销方更新发票信息 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1496561749_f7T6D | def update_reimburse(self, card_id, encrypt_code, reimburse_status):
"""
报销方更新发票信息
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1496561749_f7T6D
:param card_id: 发票卡券的 Card ID
:param encrypt_code: 发票卡券的加密 Code
:param reimburse_status: 发票报销状态
"""
return... |
报销方批量更新发票信息 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1496561749_f7T6D | def batch_update_reimburse(self, openid, reimburse_status, invoice_list):
"""
报销方批量更新发票信息
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1496561749_f7T6D
:param openid: 用户的 Open ID
:param reimburse_status: 发票报销状态
:param invoice_list: 发票列表
:type invoice_list: li... |
获取添加发票链接 获取链接,发送给用户。用户同意以后,发票抬头信息将会录入到用户微信中 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1496554912_vfWU0 | def get_user_title_url(
self, user_fill, title=None, phone=None, tax_no=None, addr=None, bank_type=None, bank_no=None,
out_title_id=None):
"""
获取添加发票链接
获取链接,发送给用户。用户同意以后,发票抬头信息将会录入到用户微信中
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1496554912_vfWU0
:p... |
获取商户专属开票链接 商户调用接口,获取链接。用户扫码,可以选择抬头发给商户。可以将链接转成二维码,立在收银台。 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1496554912_vfWU0 | def get_select_title_url(self, attach=None):
"""
获取商户专属开票链接
商户调用接口,获取链接。用户扫码,可以选择抬头发给商户。可以将链接转成二维码,立在收银台。
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1496554912_vfWU0
:param attach: 附加字段,用户提交发票时会发送给商户
:return: 商户专属开票链接
"""
return self._post(
... |
上传临时素材 详情请参考 http:// mp. weixin. qq. com/ wiki/ 5/ 963fc70b80dc75483a271298a76a8d59. html | def upload(self, media_type, media_file):
"""
上传临时素材
详情请参考
http://mp.weixin.qq.com/wiki/5/963fc70b80dc75483a271298a76a8d59.html
:param media_type: 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
:param media_file: 要上传的文件,一个 File-object
:return: 返回的 JSON 数据包
... |
群发视频消息时获取视频 media_id 详情请参考 http:// mp. weixin. qq. com/ wiki/ 15/ 5380a4e6f02f2ffdc7981a8ed7a40753. html | def upload_video(self, media_id, title, description):
"""
群发视频消息时获取视频 media_id
详情请参考
http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
:param media_id: 需通过基础支持中的上传下载多媒体文件 :func:`upload` 来得到
:param title: 视频标题
:param description: 视频描述
... |
上传群发消息内的图片 详情请参考 http:// mp. weixin. qq. com/ wiki/ 15/ 5380a4e6f02f2ffdc7981a8ed7a40753. html | def upload_image(self, media_file):
"""
上传群发消息内的图片
详情请参考
http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
:param media_file: 要上传的文件,一个 File-object
:return: 上传成功时返回图片 URL
"""
res = self._post(
url='media/uploadimg',
... |
rsa 加密: param data: 待加密字符串/ binary: param pem: RSA public key 内容/ binary: param b64_encode: 是否对输出进行 base64 encode: return: 如果 b64_encode = True 的话,返回加密并 base64 处理后的 string;否则返回加密后的 binary | def rsa_encrypt(data, pem, b64_encode=True):
"""
rsa 加密
:param data: 待加密字符串/binary
:param pem: RSA public key 内容/binary
:param b64_encode: 是否对输出进行 base64 encode
:return: 如果 b64_encode=True 的话,返回加密并 base64 处理后的 string;否则返回加密后的 binary
"""
from cryptography.hazmat.backends import default_ba... |
rsa 解密: param encrypted_data: 待解密 bytes: param pem: RSA private key 内容/ binary: param password: RSA private key pass phrase: return: 解密后的 binary | def rsa_decrypt(encrypted_data, pem, password=None):
"""
rsa 解密
:param encrypted_data: 待解密 bytes
:param pem: RSA private key 内容/binary
:param password: RSA private key pass phrase
:return: 解密后的 binary
"""
from cryptography.hazmat.backends import default_backend
from cryptography.hazm... |
发送现金红包 | def send(self, user_id, total_amount, send_name, act_name,
wishing, remark, total_num=1, client_ip=None,
out_trade_no=None, scene_id=None, consume_mch_id=None):
"""
发送现金红包
:param user_id: 接收红包的用户在公众号下的 openid
:param total_amount: 红包金额,单位分
:param send_na... |
查询红包发放记录 | def query(self, out_trade_no, bill_type='MCHT'):
"""
查询红包发放记录
:param out_trade_no: 商户订单号
:param bill_type: 可选,订单类型,目前固定为 MCHT
:return: 返回的红包发放记录信息
"""
data = {
'mch_billno': out_trade_no,
'bill_type': bill_type,
'appid': self.a... |
创建会话 | def create(self, chat_id, name, owner, user_list):
"""
创建会话
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=企业会话接口说明
:param chat_id: 会话id。字符串类型,最长32个字符。只允许字符0-9及字母a-zA-Z,
如果值内容为64bit无符号整型:要求值范围在[1, 2^63)之间,
[2^63, 2^64)为系统分... |
修改会话 | def update(self, chat_id, op_user, name=None, owner=None,
add_user_list=None, del_user_list=None):
"""
修改会话
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=企业会话接口说明
:param chat_id: 会话 ID
:param op_user: 操作人 userid
:param name: 会话标题
... |
清除会话未读状态 | def clear_notify(self, op_user, type, id):
"""
清除会话未读状态
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=企业会话接口说明
:param op_user: 会话所有者的userid
:param type: 会话类型:single|group,分别表示:单聊|群聊
:param id: 会话值,为userid|chatid,分别表示:成员id|会话id
:return: 返回的 JSON ... |
发送文本消息 | def send_text(self, sender, receiver_type, receiver_id, content):
"""
发送文本消息
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=企业会话接口说明
:param sender: 发送人
:param receiver_type: 接收人类型:single|group,分别表示:单聊|群聊
:param receiver_id: 接收人的值,为userid|chatid,分别表示:成员id... |
发送单聊文本消息 | def send_single_text(self, sender, receiver, content):
"""
发送单聊文本消息
:param sender: 发送人
:param receiver: 接收人成员 ID
:param content: 消息内容
:return: 返回的 JSON 数据包
"""
return self.send_text(sender, 'single', receiver, content) |
发送群聊文本消息 | def send_group_text(self, sender, receiver, content):
"""
发送群聊文本消息
:param sender: 发送人
:param receiver: 会话 ID
:param content: 消息内容
:return: 返回的 JSON 数据包
"""
return self.send_text(sender, 'group', receiver, content) |
发送图片消息 | def send_image(self, sender, receiver_type, receiver_id, media_id):
"""
发送图片消息
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=企业会话接口说明
:param sender: 发送人
:param receiver_type: 接收人类型:single|group,分别表示:单聊|群聊
:param receiver_id: 接收人的值,为userid|chatid,分别表示:成员... |
发送单聊图片消息 | def send_single_image(self, sender, receiver, media_id):
"""
发送单聊图片消息
:param sender: 发送人
:param receiver: 接收人成员 ID
:param media_id: 图片媒体文件id,可以调用上传素材文件接口获取
:return: 返回的 JSON 数据包
"""
return self.send_image(sender, 'single', receiver, media_id) |
发送群聊图片消息 | def send_group_image(self, sender, receiver, media_id):
"""
发送群聊图片消息
:param sender: 发送人
:param receiver: 会话 ID
:param media_id: 图片媒体文件id,可以调用上传素材文件接口获取
:return: 返回的 JSON 数据包
"""
return self.send_image(sender, 'group', receiver, media_id) |
发送文件消息 | def send_file(self, sender, receiver_type, receiver_id, media_id):
"""
发送文件消息
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=企业会话接口说明
:param sender: 发送人
:param receiver_type: 接收人类型:single|group,分别表示:单聊|群聊
:param receiver_id: 接收人的值,为userid|chatid,分别表示:成员i... |
发送单聊文件消息 | def send_single_file(self, sender, receiver, media_id):
"""
发送单聊文件消息
:param sender: 发送人
:param receiver: 接收人成员 ID
:param media_id: 文件id,可以调用上传素材文件接口获取, 文件须大于4字节
:return: 返回的 JSON 数据包
"""
return self.send_file(sender, 'single', receiver, media_id) |
发送群聊文件消息 | def send_group_file(self, sender, receiver, media_id):
"""
发送群聊文件消息
:param sender: 发送人
:param receiver: 会话 ID
:param media_id: 文件id,可以调用上传素材文件接口获取, 文件须大于4字节
:return: 返回的 JSON 数据包
"""
return self.send_file(sender, 'group', receiver, media_id) |
发放代金券 | def send(self, user_id, stock_id, op_user_id=None, device_info=None,
out_trade_no=None):
"""
发放代金券
:param user_id: 用户在公众号下的 openid
:param stock_id: 代金券批次 ID
:param op_user_id: 可选,操作员账号,默认为商户号
:param device_info: 可选,微信支付分配的终端设备号
:param out_trade_no: 可... |
查询代金券批次 | def query_stock(self, stock_id, op_user_id=None, device_info=None):
"""
查询代金券批次
:param stock_id: 代金券批次 ID
:param op_user_id: 可选,操作员账号,默认为商户号
:param device_info: 可选,微信支付分配的终端设备号
:return: 返回的结果信息
"""
data = {
'appid': self.appid,
'co... |
查询代金券信息 | def query_coupon(self, coupon_id, user_id,
op_user_id=None, device_info=None):
"""
查询代金券信息
:param coupon_id: 代金券 ID
:param user_id: 用户在公众号下的 openid
:param op_user_id: 可选,操作员账号,默认为商户号
:param device_info: 可选,微信支付分配的终端设备号
:return: 返回的结果信息
... |
创建数据源 https:// wximg. qq. com/ wxp/ pdftool/ get. html?id = rkalQXDBM&pa = 39 | def add_user_action_sets(self, _type, name, description, version='v1.0'):
"""
创建数据源
https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
:param _type: 用户行为源类型
:param name: 用户行为源名称 必填
:param description: 用户行为源描述,字段长度最小 1 字节,长度最大 128 字节
:param version: 版本号 ... |
获取数据源信息 | def get_user_action_sets(self, user_action_set_id, version='v1.0'):
"""
获取数据源信息
:param user_action_set_id: 数据源唯一ID
:param version: 版本号 v1.0
"""
return self._get(
'user_action_sets/get',
params={'version': version, 'user_action_set_id': user_action... |
回传数据 | def add_user_actions(self, actions=(), version='v1.0'):
"""
回传数据
https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
:param actions: 用户行为源类型
:param version: 版本号 v1.0
"""
return self._post(
'user_actions/add',
params={'version': v... |
获取朋友圈销售线索数据接口 | def get_ad_leads(self, start_date=None, end_date=None, filtering=(), page=1, page_size=100, version='v1.0'):
"""
获取朋友圈销售线索数据接口
:param start_date: 开始日期 默认今天
:param end_date: 结束日期 默认今天
:param filtering: 过滤条件 [{field: 过滤字段, operator: 操作符, values: 字段取值}]
:param page: 页码,获取指... |
统一下单接口 | def create(self, trade_type, body, total_fee, notify_url, client_ip=None,
user_id=None, out_trade_no=None, detail=None, attach=None,
fee_type='CNY', time_start=None, time_expire=None, goods_tag=None,
product_id=None, device_info=None, limit_pay=None, scene_info=None, sub_use... |
关闭订单 | def close(self, out_trade_no):
"""
关闭订单
:param out_trade_no: 商户系统内部的订单号
:return: 返回的结果数据
"""
data = {
'appid': self.appid,
'out_trade_no': out_trade_no,
}
return self._post('pay/closeorder', data=data) |
获取 APP 支付参数 | def get_appapi_params(self, prepay_id, timestamp=None, nonce_str=None):
"""
获取 APP 支付参数
:param prepay_id: 统一下单接口返回的 prepay_id 参数值
:param timestamp: 可选,时间戳,默认为当前时间戳
:param nonce_str: 可选,随机字符串,默认自动生成
:return: 签名
"""
data = {
'appid': self.appid,... |
撤销订单 | def reverse(self, transaction_id=None, out_trade_no=None):
"""
撤销订单
:param transaction_id: 可选,微信的订单号,优先使用
:param out_trade_no: 可选,商户系统内部的订单号,
transaction_id、out_trade_no二选一,
如果同时存在优先级:transaction_id> out_trade_no
:return: 返... |
获取用户基本信息(包括UnionID机制) 详情请参考 https:// mp. weixin. qq. com/ wiki?t = resource/ res_main&id = mp1421140839 | def get(self, user_id, lang='zh_CN'):
"""
获取用户基本信息(包括UnionID机制)
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839
:param user_id: 普通用户的标识,对当前公众号唯一
:param lang: 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
:return: 返回的 JSON 数据包
使用示例::
... |
获取一页用户列表 ( 当关注用户过多的情况下,这个接口只会返回一部分用户 ) | def get_followers(self, first_user_id=None):
"""
获取一页用户列表(当关注用户过多的情况下,这个接口只会返回一部分用户)
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140840
:param first_user_id: 可选。第一个拉取的 OPENID,不填默认从头开始拉取
:return: 返回的 JSON 数据包
使用示例::
from wechatp... |
获取所有的用户openid列表 | def iter_followers(self, first_user_id=None):
"""
获取所有的用户openid列表
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140840
:return: 返回一个迭代器,可以用for进行循环,得到openid
使用示例::
from wechatpy import WeChatClient
client = WeChatClient('appi... |
获取用户所在分组 ID | def get_group_id(self, user_id):
"""
获取用户所在分组 ID
详情请参考
http://mp.weixin.qq.com/wiki/0/56d992c605a97245eb7e617854b169fc.html
:param user_id: 用户 ID
:return: 用户所在分组 ID
使用示例::
from wechatpy import WeChatClient
client = WeChatClient('appid'... |
批量获取用户基本信息 开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。 | def get_batch(self, user_list):
"""
批量获取用户基本信息
开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140839
:param user_list: user_list,支持“使用示例”中两种输入格式
:return: 用户信息的 list
使用示例::
from wechatpy i... |
微信公众号主体变更迁移用户 openid | def change_openid(self, from_appid, openid_list):
'''微信公众号主体变更迁移用户 openid
详情请参考
http://kf.qq.com/faq/170221aUnmmU170221eUZJNf.html
:param from_appid: 原公众号的 appid
:param openid_list: 需要转换的openid,这些必须是旧账号目前关注的才行,否则会出错;一次最多100个
:return: 转换后的 openid 信息列表
'''
... |
通用的消息发送接口。msg 内需要指定 msgtype 和对应类型消息必须的字段。 如果部分接收人无权限或不存在,发送仍然执行,但会返回无效的部分(即invaliduser或invalidparty或invalidtag),常见的原因是接收人不在应用的可见范围内。 user_ids、party_ids、tag_ids 不能同时为空,后面不再强调。 | def send(self, agent_id, user_ids, party_ids='',
tag_ids='', msg=None):
"""
通用的消息发送接口。msg 内需要指定 msgtype 和对应类型消息必须的字段。
如果部分接收人无权限或不存在,发送仍然执行,但会返回无效的部分(即invaliduser或invalidparty或invalidtag),常见的原因是接收人不在应用的可见范围内。
user_ids、party_ids、tag_ids 不能同时为空,后面不再强调。
:param agent_id... |
文本卡片消息 | def send_text_card(self, agent_id, user_ids, title, description, url, btntxt='详情',
party_ids='', tag_ids=''):
""" 文本卡片消息
https://work.weixin.qq.com/api/doc#90000/90135/90236/文本卡片消息
请求示例:
{
"touser" : "UserID1|UserID2|UserID3",
"toparty" : "P... |
markdown消息 | def send_markdown(self, agent_id, user_ids, content, party_ids='', tag_ids=''):
"""markdown消息
https://work.weixin.qq.com/api/doc#90000/90135/90236/markdown%E6%B6%88%E6%81%AF
> 目前仅支持markdown语法的子集
> 微工作台(原企业号)不支持展示markdown消息
:param agent_id: 企业应用的id,整型。可在应用的设置页面查看
:type ... |
Computes the log - density of a multivariate normal.: param x: Dx1 or DxN sample ( s ) for which we want the density: param mu: Dx1 or DxN mean ( s ) of the normal distribution: param L: DxD Cholesky decomposition of the covariance matrix: return p: ( 1 ) or ( N ) vector of log densities for each of the N x s and/ or m... | def multivariate_normal(x, mu, L):
"""
Computes the log-density of a multivariate normal.
:param x : Dx1 or DxN sample(s) for which we want the density
:param mu : Dx1 or DxN mean(s) of the normal distribution
:param L : DxD Cholesky decomposition of the covariance matrix
:return p : (1,) or (... |
Make Tensorflow optimization tensor. This method builds optimization tensor and initializes all necessary variables created by optimizer. | def make_optimize_tensor(self, model, session=None, var_list=None, **kwargs):
"""
Make Tensorflow optimization tensor.
This method builds optimization tensor and initializes all necessary variables
created by optimizer.
:param model: GPflow model.
:param session:... |
Build Optimization action task with Tensorflow optimizer. | def make_optimize_action(self, model, session=None, var_list=None, **kwargs):
"""
Build Optimization action task with Tensorflow optimizer.
:param model: GPflow model.
:param session: Tensorflow session.
:param var_list: List of Tensorflow variables to train.
... |
Minimizes objective function of the model. | def minimize(self, model, session=None, var_list=None, feed_dict=None,
maxiter=1000, initialize=False, anchor=True, step_callback=None, **kwargs):
"""
Minimizes objective function of the model.
:param model: GPflow model with objective tensor.
:param session: Session wh... |
Pass session configuration options | def get_session(*args, **kwargs):
"""
Pass session configuration options
"""
if 'config' not in kwargs:
kwargs['config'] = tf.ConfigProto(**settings.session)
if settings.profiling.dump_timeline:
def fill_kwargs(key, value):
"""
Internal function for filling de... |
Creates trace filename. | def _trace_filename(self):
"""
Creates trace filename.
"""
dir_stub = ''
if self.output_directory is not None:
dir_stub = self.output_directory
if self.each_time:
filename = '{0}_{1}.json'.format(
self.output_file_name, self.counter... |
Make SciPy optimization tensor. The make_optimize_tensor method builds optimization tensor and initializes all necessary variables created by optimizer. | def make_optimize_tensor(self, model, session=None, var_list=None, **kwargs):
"""
Make SciPy optimization tensor.
The `make_optimize_tensor` method builds optimization tensor and initializes
all necessary variables created by optimizer.
:param model: GPflow model.
... |
Minimizes objective function of the model. | def minimize(self, model, session=None, var_list=None, feed_dict=None, maxiter=1000,
disp=False, initialize=False, anchor=True, step_callback=None, **kwargs):
"""
Minimizes objective function of the model.
:param model: GPflow model with objective tensor.
:param session... |
Before calling the standard compile function check to see if the size of the data has changed and add parameters appropriately. | def compile(self, session=None):
"""
Before calling the standard compile function, check to see if the size
of the data has changed and add parameters appropriately.
This is necessary because the shape of the parameters depends on the
shape of the data.
"""
if no... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.