INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
Set up log levels and split verbose logs to a file | def configure_logging(path=None):
"""
Set up log levels, and split verbose logs to a file
Configure the client-side environment logs to print
to stdout at "info" level, and also to print to a
verbose log file located at /tmp/universe-<pid>.log
or another path you specify at "deb... |
Set DOCKER_HOST ( and probably DOCKER_TLS_VERIFY and DOCKER_CERT_PATH ) to connect to a docker instance through TCP. Leave DOCKER_HOST unset and it will use the default typically unix:/ var/ run/ docker. sock | def get_client():
"""
Set DOCKER_HOST (and probably DOCKER_TLS_VERIFY and DOCKER_CERT_PATH) to connect to a docker instance through TCP.
Leave DOCKER_HOST unset and it will use the default, typically unix:/var/run/docker.sock
It also needs to know how to connect to ports on the docker container after c... |
Call from main thread. Returns the list of newly - available ( handle env ) pairs. | def pop(self, n=None):
"""Call from main thread. Returns the list of newly-available (handle, env) pairs."""
if self._popped:
assert n is None
return []
self._popped = True
envs = []
for i, instance in enumerate(self.instances):
env = remote.R... |
Returns a tuple of ( log_fn log_f bin_fn bin_f ) to be written to by vectorized env channel i Or all Nones if recording is inactive on that channel | def _get_writer(self, i):
"""
Returns a tuple of (log_fn, log_f, bin_fn, bin_f) to be written to by vectorized env channel i
Or all Nones if recording is inactive on that channel
"""
if self._recording_dir is None:
return None
if self._log_n is None:
... |
Return true if we are past our limit | def _past_limit(self):
"""Return true if we are past our limit"""
if self._max_episode_steps is not None and self._max_episode_steps <= self._elapsed_steps:
logger.debug("Env has passed the step limit defined by TimeLimit.")
return True
if self._max_episode_seconds is no... |
Write data to server | def recvProxyData(self, data):
"""Write data to server"""
if self.initialized:
self.sendData(data)
else:
self.queued_data.append(data) |
Write data to server | def sendData(self, data):
"""Write data to server"""
# Not set up yet
if self.client_log is None:
self.client_log_buffer.append(data)
else:
self.client_log.write(data)
self.transport.write(data) |
Crops the visual observations of an environment so that they only contain the game screen. Removes anything outside the game that usually belongs to universe ( browser borders and so on ). | def CropObservations(env):
""""
Crops the visual observations of an environment so that they only contain the game screen.
Removes anything outside the game that usually belongs to universe (browser borders and so on).
"""
if env.spec.tags.get('flashgames', False):
spec = runtime_spec('flash... |
Play a list of vnc_actions forward over the current keysyms state | def apply_vnc_actions(self, vnc_actions):
"""
Play a list of vnc_actions forward over the current keysyms state
NOTE: Since we are squashing a set of diffs into a single keyboard state, some information may be lost.
For example if the Z key is down, then we receive [(Z-up), (Z-down)], t... |
Call from any thread | def recv_rpc(self, context, payload):
"""Call from any thread"""
logger.debug("Adding RPC payload to ControlBuffer queue: %s", payload)
self.buf.put(('rpc', (context, payload)))
with self.cv:
self.cv.notifyAll() |
Call from main thread. | def get(self, *args, **kwargs):
"""Call from main thread."""
payload = self.buf.get(*args, **kwargs)
logger.debug("Removing RPC payload from ControlBuffer queue: %s", payload)
return payload |
text channel to communicate with the agent | def send_env_text(self, text, episode_id):
''' text channel to communicate with the agent '''
reactor.callFromThread(self._send_env_text, text, episode_id) |
Return an iterable of functions. | def build_log_presenters(service_names, monochrome):
"""Return an iterable of functions.
Each function can be used to format the logs output of a container.
"""
prefix_width = max_name_width(service_names)
def no_color(text):
return text
for color_func in cycle([no_color] if monochrom... |
Consume the queue by reading lines off of it and yielding them. | def consume_queue(queue, cascade_stop):
"""Consume the queue by reading lines off of it and yielding them."""
while True:
try:
item = queue.get(timeout=0.1)
except Empty:
yield None
continue
# See https://github.com/docker/compose/issues/189
ex... |
Will set the crypting key for this object. | def setKey(self, key):
"""Will set the crypting key for this object."""
key = self._guardAgainstUnicode(key)
self.__key = key |
setPadding () - > bytes of length 1. Padding character. | def setPadding(self, pad):
"""setPadding() -> bytes of length 1. Padding character."""
if pad is not None:
pad = self._guardAgainstUnicode(pad)
self._padding = pad |
Will set the Initial Value used in conjunction with CBC mode | def setIV(self, IV):
"""Will set the Initial Value, used in conjunction with CBC mode"""
if not IV or len(IV) != self.block_size:
raise ValueError("Invalid Initial Value (IV), must be a multiple of " + str(self.block_size) + " bytes")
IV = self._guardAgainstUnicode(IV)
self._iv = IV |
Turn the string data into a list of bits ( 1 0 ) s | def __String_to_BitList(self, data):
"""Turn the string data, into a list of bits (1, 0)'s"""
if _pythonMajorVersion < 3:
# Turn the strings into integers. Python 3 uses a bytes
# class, which already has this behaviour.
data = [ord(c) for c in data]
l = len(data) * 8
result = [0] * l
pos = 0
for c... |
Turn the list of bits - > data into a string | def __BitList_to_String(self, data):
"""Turn the list of bits -> data, into a string"""
result = []
pos = 0
c = 0
while pos < len(data):
c += data[pos] << (7 - (pos % 8))
if (pos % 8) == 7:
result.append(c)
c = 0
pos += 1
if _pythonMajorVersion < 3:
return ''.join([ chr(c) for c in resu... |
Permutate this block with the specified table | def __permutate(self, table, block):
"""Permutate this block with the specified table"""
return list(map(lambda x: block[x], table)) |
Create the 16 subkeys K [ 1 ] to K [ 16 ] from the given key | def __create_sub_keys(self):
"""Create the 16 subkeys K[1] to K[16] from the given key"""
key = self.__permutate(des.__pc1, self.__String_to_BitList(self.getKey()))
i = 0
# Split into Left and Right sections
self.L = key[:28]
self.R = key[28:]
while i < 16:
j = 0
# Perform circular left shifts
wh... |
encrypt ( data [ pad ] [ padmode ] ) - > bytes | def encrypt(self, data, pad=None, padmode=None):
"""encrypt(data, [pad], [padmode]) -> bytes
data : Bytes to be encrypted
pad : Optional argument for encryption padding. Must only be one byte
padmode : Optional argument for overriding the padding mode.
The data must be a multiple of 8 bytes and will be enc... |
decrypt ( data [ pad ] [ padmode ] ) - > bytes | def decrypt(self, data, pad=None, padmode=None):
"""decrypt(data, [pad], [padmode]) -> bytes
data : Bytes to be encrypted
pad : Optional argument for decryption padding. Must only be one byte
padmode : Optional argument for overriding the padding mode.
The data must be a multiple of 8 bytes and will be dec... |
Will set the crypting key for this object. Either 16 or 24 bytes long. | def setKey(self, key):
"""Will set the crypting key for this object. Either 16 or 24 bytes long."""
self.key_size = 24 # Use DES-EDE3 mode
if len(key) != self.key_size:
if len(key) == 16: # Use DES-EDE2 mode
self.key_size = 16
else:
raise ValueError("Invalid triple DES key size. Key must be either ... |
Sets the type of crypting mode pyDes. ECB or pyDes. CBC | def setMode(self, mode):
"""Sets the type of crypting mode, pyDes.ECB or pyDes.CBC"""
_baseDes.setMode(self, mode)
for key in (self.__key1, self.__key2, self.__key3):
key.setMode(mode) |
setPadding () - > bytes of length 1. Padding character. | def setPadding(self, pad):
"""setPadding() -> bytes of length 1. Padding character."""
_baseDes.setPadding(self, pad)
for key in (self.__key1, self.__key2, self.__key3):
key.setPadding(pad) |
Sets the type of padding mode pyDes. PAD_NORMAL or pyDes. PAD_PKCS5 | def setPadMode(self, mode):
"""Sets the type of padding mode, pyDes.PAD_NORMAL or pyDes.PAD_PKCS5"""
_baseDes.setPadMode(self, mode)
for key in (self.__key1, self.__key2, self.__key3):
key.setPadMode(mode) |
Will set the Initial Value used in conjunction with CBC mode | def setIV(self, IV):
"""Will set the Initial Value, used in conjunction with CBC mode"""
_baseDes.setIV(self, IV)
for key in (self.__key1, self.__key2, self.__key3):
key.setIV(IV) |
decrypt ( data [ pad ] [ padmode ] ) - > bytes | def decrypt(self, data, pad=None, padmode=None):
"""decrypt(data, [pad], [padmode]) -> bytes
data : bytes to be encrypted
pad : Optional argument for decryption padding. Must only be one byte
padmode : Optional argument for overriding the padding mode.
The data must be a multiple of 8 bytes and will be dec... |
解析微信支付结果通知 | def parse_payment_result(self, xml):
"""解析微信支付结果通知"""
try:
data = xmltodict.parse(xml)
except (xmltodict.ParsingInterrupted, ExpatError):
raise InvalidSignatureException()
if not data or 'xml' not in data:
raise InvalidSignatureException()
da... |
新增永久图文素材 详情请参考 https:// mp. weixin. qq. com/ wiki?id = mp1494572718_WzHIY | def add_articles(self, articles):
"""
新增永久图文素材
详情请参考
https://mp.weixin.qq.com/wiki?id=mp1494572718_WzHIY
:param articles: 图文素材数组
:type articles: list[dict]
:return: 返回的 JSON 数据包
"""
articles_data = []
for article in articles:
a... |
新增其它类型永久素材 详情请参考 http:// mp. weixin. qq. com/ wiki/ 14/ 7e6c03263063f4813141c3e17dd4350a. html | def add(self, media_type, media_file, title=None, introduction=None):
"""
新增其它类型永久素材
详情请参考
http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
:param media_type: 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
:param media_file: 要上传的文件,一个 File-object... |
获取永久素材 详情请参考 http:// mp. weixin. qq. com/ wiki/ 4/ b3546879f07623cb30df9ca0e420a5d0. html | def get(self, media_id):
"""
获取永久素材
详情请参考
http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
:param media_id: 素材的 media_id
:return: 图文素材返回图文列表,其它类型为素材的内容
"""
def _processor(res):
if isinstance(res, dict):
if '... |
修改永久图文素材 详情请参考 https:// mp. weixin. qq. com/ wiki?t = resource/ res_main&id = mp1444738732 | def update_article(self, media_id, index, article):
"""
修改永久图文素材
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738732
:param media_id: 要修改的图文消息的 id
:param index: 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为 0
:param article: 图文素材
:return: 返回的 J... |
修改永久图文素材 详情请参考 http:// mp. weixin. qq. com/ wiki/ 4/ 19a59cba020d506e767360ca1be29450. html | def update_articles(self, media_id, index, articles):
"""
修改永久图文素材
详情请参考
http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
:param media_id: 要修改的图文消息的 id
:param index: 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为 0
:param articles: 图文素材数组
:retur... |
查看指定文章的评论数据 | def list_comment(self, msg_data_id, index=1, begin=0, count=50, type=0):
"""
查看指定文章的评论数据
"""
return self._post(
'comment/list',
data={
'msg_data_id': msg_data_id,
'index': index,
'begin': begin,
'coun... |
将评论标记精选 | def markelect_comment(self, msg_data_id, index, user_comment_id):
"""
将评论标记精选
"""
return self._post(
'comment/markelect',
data={
'msg_data_id': msg_data_id,
'index': index,
'user_comment_id': user_comment_id,
... |
将评论取消精选 | def unmarkelect_comment(self, msg_data_id, index, user_comment_id):
"""
将评论取消精选
"""
return self._post(
'comment/unmarkelect',
data={
'msg_data_id': msg_data_id,
'index': index,
'user_comment_id': user_comment_id,
... |
删除评论 | def delete_comment(self, msg_data_id, index, user_comment_id):
"""
删除评论
"""
return self._post(
'comment/delete',
data={
'msg_data_id': msg_data_id,
'index': index,
'user_comment_id': user_comment_id,
}) |
回复评论 | def add_reply_comment(self, msg_data_id, index, user_comment_id, content):
"""
回复评论
"""
return self._post(
'comment/reply/add',
data={
'msg_data_id': msg_data_id,
'index': index,
'user_comment_id': user_comment_id,
... |
删除回复 | def delete_reply_comment(self, msg_data_id, index, user_comment_id):
"""
删除回复
"""
return self._post(
'comment/reply/delete',
data={
'msg_data_id': msg_data_id,
'index': index,
'user_comment_id': user_comment_id,
... |
获取服务商凭证 | def get_provider_token(self, provider_secret):
"""
获取服务商凭证
https://work.weixin.qq.com/api/doc#90001/90143/91200
:param provider_secret: 服务商的secret,在服务商管理后台可见
:return: 返回的 JSON 数据包
"""
return self._post(
'service/get_provider_token',
data=... |
获取第三方应用凭证 | def get_suite_token(self, suite_id, suite_secret, suite_ticket):
"""
获取第三方应用凭证
https://work.weixin.qq.com/api/doc#90001/90143/9060
:param suite_id: 以ww或wx开头应用id(对应于旧的以tj开头的套件id)
:param suite_secret: 应用secret
:param suite_ticket: 企业微信后台推送的ticket
:return: 返回的 JSO... |
获取企业号登录用户信息 | def get_login_info(self, auth_code, provider_access_token=None):
"""
获取企业号登录用户信息
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=获取企业号登录用户信息
:param provider_access_token: 服务提供商的 accesstoken
:param auth_code: OAuth 2.0 授权企业号管理员登录产生的 code
:return: 返回的 JSON ... |
获取登录企业号官网的url | def get_login_url(self, login_ticket, target, agentid=None, provider_access_token=None):
"""
获取登录企业号官网的url
详情请参考
https://qydev.weixin.qq.com/wiki/index.php?title=获取登录企业号官网的url
:param provider_access_token: 服务提供商的 accesstoken
:param login_ticket: 通过get_login_info得到的login... |
获取用户增减数据 详情请参考 http:// mp. weixin. qq. com/ wiki/ 3/ ecfed6e1a0a03b5f35e5efac98e864b7. html | def get_user_summary(self, begin_date, end_date):
"""
获取用户增减数据
详情请参考
http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
:param begin_date: 起始日期
:param end_date: 结束日期
:return: 统计数据列表
"""
res = self._post(
'getusersumma... |
获取累计用户数据 详情请参考 http:// mp. weixin. qq. com/ wiki/ 3/ ecfed6e1a0a03b5f35e5efac98e864b7. html | def get_user_cumulate(self, begin_date, end_date):
"""
获取累计用户数据
详情请参考
http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
:param begin_date: 起始日期
:param end_date: 结束日期
:return: 统计数据列表
"""
res = self._post(
'getusercumu... |
企业付款接口 | def transfer(self, user_id, amount, desc, client_ip=None,
check_name='OPTION_CHECK', real_name=None,
out_trade_no=None, device_info=None):
"""
企业付款接口
:param user_id: 接受收红包的用户在公众号下的 openid
:param amount: 付款金额,单位分
:param desc: 付款说明
:param ... |
企业付款到银行卡接口 | def transfer_bankcard(self, true_name, bank_card_no, bank_code, amount, desc=None, out_trade_no=None):
"""
企业付款到银行卡接口
:param true_name: 开户人名称
:param bank_card_no: 银行卡号
:param bank_code: 银行编号
:param amount: 付款金额,单位分
:param desc: 付款说明
:param out_trade_no: 可... |
企业付款查询接口 | def query_bankcard(self, out_trade_no):
"""
企业付款查询接口
:param out_trade_no: 商户调用企业付款API时使用的商户订单号
:return: 返回的结果数据
"""
data = {
'mch_id': self.mch_id,
'partner_trade_no': out_trade_no,
}
return self._post('mmpaysptrans/query_bank', da... |
获得模板ID 详情请参考 https:// mp. weixin. qq. com/ wiki?t = resource/ res_main&id = mp1433751277 | def get(self, template_id_short):
"""
获得模板ID
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
:param template_id_short: 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
:return: 模板 ID
"""
res = self._post(
'template/api_add_template',
... |
申请设备ID 详情请参考 http:// mp. weixin. qq. com/ wiki/ 15/ b9e012f917e3484b7ed02771156411f3. html | def apply_device_id(self, quantity, reason, poi_id=None, comment=None):
"""
申请设备ID
详情请参考
http://mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html
:param quantity: 申请的设备ID的数量,单次新增设备超过500个,需走人工审核流程
:param reason: 申请理由,不超过100个字
:param poi_id: 可选,设备关联的门店... |
更新设备信息 详情请参考 http:// mp. weixin. qq. com/ wiki/ 15/ b9e012f917e3484b7ed02771156411f3. html | def update_device(self, device_id=None, uuid=None, major=None,
minor=None, comment=None):
"""
更新设备信息
详情请参考
http://mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html
:param device_id: 设备编号,若填了UUID、major、minor,则可不填设备编号,若二者都填,则以设备编号为优先
:par... |
配置设备与门店的关联关系 详情请参考 http:// mp. weixin. qq. com/ wiki/ 15/ b9e012f917e3484b7ed02771156411f3. html | def bind_device_location(self, poi_id, device_id=None, uuid=None,
major=None, minor=None):
"""
配置设备与门店的关联关系
详情请参考
http://mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html
:param poi_id: 待关联的门店ID
:param device_id: 设备编号,若填了UUID、maj... |
查询设备列表 详情请参考 http:// mp. weixin. qq. com/ wiki/ 15/ b9e012f917e3484b7ed02771156411f3. html | def search_device(self, identifiers=None, apply_id=None,
begin=0, count=10):
"""
查询设备列表
详情请参考
http://mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html
:param identifiers: 设备 ID 信息列表
:param apply_id: 批次ID,申请设备ID超出500个时所返回批次ID
:pa... |
编辑页面信息 详情请参考 http:// mp. weixin. qq. com/ wiki/ 5/ 6626199ea8757c752046d8e46cf13251. html | def update_page(self, page_id, title, description,
icon_url, page_url, comment=None):
"""
编辑页面信息
详情请参考
http://mp.weixin.qq.com/wiki/5/6626199ea8757c752046d8e46cf13251.html
:param page_id: 摇周边页面唯一ID
:param title: 在摇一摇页面展示的主标题,不超过6个字
:param desc... |
查询页面列表 详情请参考 http:// mp. weixin. qq. com/ wiki/ 5/ 6626199ea8757c752046d8e46cf13251. html | def search_pages(self, page_ids=None, begin=0, count=10):
"""
查询页面列表
详情请参考
http://mp.weixin.qq.com/wiki/5/6626199ea8757c752046d8e46cf13251.html
:param page_ids: 指定页面的id列表
:param begin: 页面列表的起始索引值
:param count: 待查询的页面个数
:return: 页面查询结果信息
"""
... |
上传图片素材 详情请参考 http:// mp. weixin. qq. com/ wiki/ 5/ e997428269ff189d8f9a4b9e177be2d9. html | def add_material(self, media_file, media_type='icon'):
"""
上传图片素材
详情请参考
http://mp.weixin.qq.com/wiki/5/e997428269ff189d8f9a4b9e177be2d9.html
:param media_file: 要上传的文件,一个 File-object
:param media_type: 摇一摇素材类型, 取值为 icon或者 license, 默认 icon.
:return: 上传的素材信息
... |
配置设备与页面的关联关系 详情请参考 http:// mp. weixin. qq. com/ wiki/ 12/ c8120214ec0ba08af5dfcc0da1a11400. html | def bind_device_pages(self, page_ids, bind, append, device_id=None,
uuid=None, major=None, minor=None):
"""
配置设备与页面的关联关系
详情请参考
http://mp.weixin.qq.com/wiki/12/c8120214ec0ba08af5dfcc0da1a11400.html
:param page_ids: 待关联的页面列表
:param bind: 关联操作标志位, ... |
获取摇周边的设备及用户信息 详情请参考 http:// mp. weixin. qq. com/ wiki/ 3/ 34904a5db3d0ec7bb5306335b8da1faf. html | def get_shake_info(self, ticket):
"""
获取摇周边的设备及用户信息
详情请参考
http://mp.weixin.qq.com/wiki/3/34904a5db3d0ec7bb5306335b8da1faf.html
:param ticket: 摇周边业务的ticket,可在摇到的URL中得到,ticket生效时间为30分钟
:return: 设备及用户信息
"""
res = self._post(
'shakearound/user/get... |
以设备为维度的数据统计接口 http:// mp. weixin. qq. com/ wiki/ 0/ 8a24bcacad40fe7ee98d1573cb8a6764. html | def get_device_statistics(self, begin_date, end_date, device_id=None,
uuid=None, major=None, minor=None):
"""
以设备为维度的数据统计接口
http://mp.weixin.qq.com/wiki/0/8a24bcacad40fe7ee98d1573cb8a6764.html
:param begin_date: 起始时间,最长时间跨度为30天
:param end_date: 结束时间... |
以页面为维度的数据统计接口 详情请参考 http:// mp. weixin. qq. com/ wiki/ 0/ 8a24bcacad40fe7ee98d1573cb8a6764. html | def get_page_statistics(self, page_id, begin_date, end_date):
"""
以页面为维度的数据统计接口
详情请参考
http://mp.weixin.qq.com/wiki/0/8a24bcacad40fe7ee98d1573cb8a6764.html
:param page_id: 页面 ID
:param begin_date: 起始时间,最长时间跨度为30天
:param end_date: 结束时间,最长时间跨度为30天
:return: 统... |
查询设备ID申请审核状态 详情请参考 http:// mp. weixin. qq. com/ wiki/ 15/ b9e012f917e3484b7ed02771156411f3. html | def get_apply_status(self, apply_id):
"""
查询设备ID申请审核状态
详情请参考
http://mp.weixin.qq.com/wiki/15/b9e012f917e3484b7ed02771156411f3.html
:param apply_id: 批次ID,申请设备ID时所返回的批次ID
:return: 批次状态信息
"""
res = self._post(
'shakearound/device/applystatus',
... |
申请签约 api | def apply_signing(self, plan_id, contract_code, contract_display_account, notify_url,
version="1.0", clientip=None, deviceid=None, mobile=None, email=None, qq=None,
request_serial=None, openid=None, creid=None, outerid=None):
"""
申请签约 api
https://pay.... |
查询签约关系 api | def query_signing(self, contract_id=None, plan_id=None, contract_code=None, openid=None, version="1.0"):
"""
查询签约关系 api
:param contract_id: 可选 委托代扣协议id 委托代扣签约成功后由微信返回的委托代扣协议id,选择contract_id查询,则此参数必填
:param plan_id: 可选 模板id 商户在微信商户平台配置的代扣模板id,选择plan_id+contract_code查询,则此参数必填
:par... |
申请扣款 api | def apply_deduct(self, body, total_fee, contract_id, notify_url, out_trade_no=None,
detail=None, attach=None, fee_type='CNY', goods_tag=None, clientip=None, deviceid=None,
mobile=None, email=None, qq=None, openid=None, creid=None, outerid=None):
"""
申请扣款 api
... |
查询订单 api | def query_order(self, transaction_id=None, out_trade_no=None):
"""
查询订单 api
:param transaction_id: 二选一 微信订单号 微信的订单号,优先使用
:param out_trade_no: 二选一 商户订单号 商户系统内部的订单号,当没提供transaction_id时需要传这个。
:return: 返回的结果信息
"""
if not transaction_id and not out_trade_no:
... |
申请解约 | def apply_cancel_signing(self, contract_id=None, plan_id=None, contract_code=None,
contract_termination_remark=None, version="1.0"):
"""
申请解约
https://pay.weixin.qq.com/wiki/doc/api/pap.php?chapter=18_4&index=6
:param contract_id: 合同ID
:param plan_id... |
提交审核/ 取消发布商品 | def modify_product_status(self, standard, key, status):
"""
提交审核/取消发布商品
详情请参考
http://mp.weixin.qq.com/wiki/15/1007691d0f1c10a0588c6517f12ed70f.html
:param standard: 商品编码标准
:param key: 商品编码内容
:param status: 设置发布状态。on 为提交审核,off 为取消发布
:return: 返回的 JSON 数据包
... |
查询商品信息 | def get_product(self, standard, key):
"""
查询商品信息
详情请参考
http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
:param standard: 商品编码标准
:param key: 商品编码内容
:return: 返回的 JSON 数据包
"""
data = {
'keystandard': standard,
... |
批量查询商品信息 | def list_product(self, offset=0, limit=10, status=None, key=None):
"""
批量查询商品信息
详情请参考
http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
:param offset: 可选,批量查询的起始位置,从 0 开始,包含该起始位置
:param limit: 可选,批量查询的数量,默认为 10
:param status: 可选,支持按状态拉取。on为发布... |
清除商品信息 | def clear_product(self, standard, key):
"""
清除商品信息
详情请参考
http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
:param standard: 商品编码标准
:param key: 商品编码内容
:return: 返回的 JSON 数据包
"""
data = {
'keystandard': standard,
... |
主动发送消息给设备 详情请参考 https:// iot. weixin. qq. com/ wiki/ new/ index. html?page = 3 - 4 - 3 | def send_message(self, device_type, device_id, user_id, content):
"""
主动发送消息给设备
详情请参考
https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-3
:param device_type: 设备类型,目前为“公众账号原始ID”
:param device_id: 设备ID
:param user_id: 微信用户账号的openid
:param content: 消息内容... |
第三方主动发送设备状态消息给微信终端 详情请参考 https:// iot. weixin. qq. com/ wiki/ document - 2_10. html | def send_status_message(self, device_type, device_id, user_id, msg_type, device_status):
"""
第三方主动发送设备状态消息给微信终端
详情请参考
https://iot.weixin.qq.com/wiki/document-2_10.html
:param device_type: 设备类型,目前为“公众账号原始ID”
:param device_id: 设备ID
:param user_id: 微信用户账号的openid
... |
通过 ticket 换取二维码地址 详情请参考 https:// iot. weixin. qq. com/ wiki/ new/ index. html?page = 3 - 4 - 4 | def get_qrcode_url(self, ticket, data=None):
"""
通过 ticket 换取二维码地址
详情请参考
https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-4
:param ticket: 二维码 ticket
:param data: 额外数据
:return: 二维码地址
"""
url = 'https://we.qq.com/d/{ticket}'.format(ticket=tic... |
绑定设备 详情请参考 https:// iot. weixin. qq. com/ wiki/ new/ index. html?page = 3 - 4 - 7 | def bind(self, ticket, device_id, user_id):
"""
绑定设备
详情请参考
https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7
:param ticket: 绑定操作合法性的凭证(由微信后台生成,第三方H5通过客户端jsapi获得)
:param device_id: 设备id
:param user_id: 用户对应的openid
:return: 返回的 JSON 数据包
"""
... |
解绑设备 详情请参考 https:// iot. weixin. qq. com/ wiki/ new/ index. html?page = 3 - 4 - 7 | def unbind(self, ticket, device_id, user_id):
"""
解绑设备
详情请参考
https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7
:param ticket: 绑定操作合法性的凭证(由微信后台生成,第三方H5通过客户端jsapi获得)
:param device_id: 设备id
:param user_id: 用户对应的openid
:return: 返回的 JSON 数据包
"""... |
获取deviceid和二维码 详情请参考 https:// iot. weixin. qq. com/ wiki/ new/ index. html?page = 3 - 4 - 4 | def get_qrcode(self, product_id=1):
"""
获取deviceid和二维码
详情请参考
https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-4
:param product_id: 设备的产品编号
:return: 返回的 JSON 数据包
"""
if product_id == '1' or product_id == 1:
params = None
else:
... |
设备授权 详情请参考 https:// iot. weixin. qq. com/ wiki/ new/ index. html?page = 3 - 4 - 5 | def authorize(self, devices, op_type=1):
"""
设备授权
详情请参考
https://iot.weixin.qq.com/wiki/new/index.html?page=3-4-5
:param devices: 设备信息的列表
:param op_type: 请求操作的类型,限定取值为:0:设备授权 1:设备更新
:return: 返回的 JSON 数据包
"""
return self._post(
'authoriz... |
创建成员 | def create(self, user_id, name, department=None, position=None,
mobile=None, gender=0, tel=None, email=None,
weixin_id=None, extattr=None):
"""
创建成员
https://work.weixin.qq.com/api/doc#90000/90135/90195
"""
user_data = optionaldict()
user_dat... |
批量获取部门成员/ 批量获取部门成员详情 | def list(self, department_id, fetch_child=False, status=0, simple=False):
"""
批量获取部门成员 / 批量获取部门成员详情
https://work.weixin.qq.com/api/doc#90000/90135/90200
https://work.weixin.qq.com/api/doc#90000/90135/90201
此接口和 `WeChatDepartment.get_users` 是同一个接口,区别为 simple 的默认值不同。
"""
... |
user_id 转成 openid | def convert_to_openid(self, user_id, agent_id=None):
"""
user_id 转成 openid
https://work.weixin.qq.com/api/doc#90000/90135/90202
:param user_id: 企业微信内的成员 ID
:param agent_id: 可选,需要发送红包的应用ID,若只是使用微信支付和企业转账,则无需该参数
:return: 返回的 JSON 数据包
"""
data = optionaldic... |
创建群聊会话 | def create(self, chat_id=None, name=None, owner=None, user_list=None):
"""
创建群聊会话
详情请参考
https://work.weixin.qq.com/api/doc#90000/90135/90245
限制说明:
只允许企业自建应用调用,且应用的可见范围必须是根部门;
群成员人数不可超过管理端配置的“群成员人数上限”,且最大不可超过500人;
每企业创建群数不可超过1000/天;
:param chat_i... |
应用推送消息 | def send(self, chat_id, msg_type, **kwargs):
"""
应用推送消息
详情请参考:https://work.weixin.qq.com/api/doc#90000/90135/90248
:param chat_id: 群聊id
:param msg_type: 消息类型,可以为text/image/voice/video/file/textcard/news/mpnews/markdown
:param kwargs: 具体消息类型的扩展参数
:return:
... |
deprecated use send instead | def send_msg(self, chat_id, msg_type, **kwargs):
""" deprecated, use `send` instead """
return self.send(chat_id, msg_type, **kwargs) |
发送文本消息 | def send_text(self, chat_id, content, safe=0):
"""
发送文本消息
详情请参考:https://work.weixin.qq.com/api/doc#90000/90135/90248/文本消息/
:param chat_id: 群聊id
:param content: 消息内容
:param safe: 表示是否是保密消息,0表示否,1表示是,默认0
:return:
"""
return self.send(chat_id, 'text... |
构造消息内容 | def _build_msg_content(self, msgtype='text', **kwargs):
"""
构造消息内容
:param content: 消息内容,最长不超过2048个字节
:param msgtype: 消息类型,可以为text/image/voice/video/file/textcard/news/mpnews/markdown
:param kwargs: 具体消息类型的扩展参数
:return:
"""
data = {'msgtype': msgtype}
... |
通过ticket换取二维码 详情请参考 https:// mp. weixin. qq. com/ wiki?t = resource/ res_main&id = mp1443433542 | def show(self, ticket):
"""
通过ticket换取二维码
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433542
:param ticket: 二维码 ticket 。可以通过 :func:`create` 获取到
:return: 返回的 Request 对象
使用示例::
from wechatpy import WeChatClient
client... |
通过ticket换取二维码地址 详情请参考 https:// mp. weixin. qq. com/ wiki?t = resource/ res_main&id = mp1443433542 | def get_url(cls, ticket):
"""
通过ticket换取二维码地址
详情请参考
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433542
:param ticket: 二维码 ticket 。可以通过 :func:`create` 获取到
:return: 返回的二维码地址
使用示例::
from wechatpy import WeChatClient
client =... |
WeChat access token | def access_token(self):
""" WeChat access token """
access_token = self.session.get(self.access_token_key)
if access_token:
if not self.expires_at:
# user provided access_token, just return it
return access_token
timestamp = time.time()
... |
创建卡券 | def create(self, card_data):
"""
创建卡券
:param card_data: 卡券信息
:return: 创建的卡券 ID
"""
result = self._post(
'card/create',
data=card_data,
result_processor=lambda x: x['card_id']
)
return result |
批量导入门店信息 | def batch_add_locations(self, location_data):
"""
批量导入门店信息
:param location_data: 门店信息
:return: 门店 ID 列表,插入失败的门店元素值为 -1
"""
result = self._post(
'card/location/batchadd',
data=location_data,
result_processor=lambda x: x['location_id_lis... |
创建卡券二维码 | def create_qrcode(self, qrcode_data):
"""
创建卡券二维码
:param qrcode_data: 二维码信息
:return: 二维码 ticket,可使用 :func:show_qrcode 换取二维码文件
"""
result = self._post(
'card/qrcode/create',
data=qrcode_data,
result_processor=lambda x: x['ticket']
... |
图文消息群发卡券 | def get_html(self, card_id):
"""
图文消息群发卡券
"""
result = self._post(
'card/mpnews/gethtml',
data={
'card_id': card_id
},
result_processor=lambda x: x['content']
)
return result |
消耗 code | def consume_code(self, code, card_id=None):
"""
消耗 code
"""
card_data = {
'code': code
}
if card_id:
card_data['card_id'] = card_id
return self._post(
'card/code/consume',
data=card_data
) |
解码加密的 code | def decrypt_code(self, encrypt_code):
"""
解码加密的 code
"""
result = self._post(
'card/code/decrypt',
data={
'encrypt_code': encrypt_code
},
result_processor=lambda x: x['code']
)
return result |
查询 code 信息 | def get_code(self, code, card_id=None, check_consume=True):
"""
查询 code 信息
"""
card_data = {
'code': code
}
if card_id:
card_data['card_id'] = card_id
if not check_consume:
card_data['check_consume'] = check_consume
retu... |
用于获取用户卡包里的,属于该appid下的卡券。 | def get_card_list(self, openid, card_id=None):
"""
用于获取用户卡包里的,属于该appid下的卡券。
"""
card_data = {
'openid': openid
}
if card_id:
card_data['card_id'] = card_id
return self._post(
'card/user/getcardlist',
data=card_data
... |
批量查询卡券信息 | def batch_get(self, offset=0, count=50, status_list=None):
"""
批量查询卡券信息
"""
card_data = {
'offset': offset,
'count': count
}
if status_list:
card_data['status_list'] = status_list
return self._post(
'card/batchget',
... |
查询卡券详情 | def get(self, card_id):
"""
查询卡券详情
"""
result = self._post(
'card/get',
data={
'card_id': card_id
},
result_processor=lambda x: x['card']
)
return result |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.