Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import time
from wechatpy.client.api.base import BaseWeChatAPI
from wechatpy.utils import WeChatSigner
class WeChatJSAPI(BaseWeChatAPI):
"""
https://work.weixin.qq.com/api/doc#90001/90144/90539
"""
def get_ticket(self):
"""
获取企业的jsapi_ticket
https://work.weixin.qq.com/api/doc#90001/90144/90539/获取企业的jsapi_ticket/
:return: 返回的 JSON 数据包
"""
return self._get('get_jsapi_ticket')
def get_jsapi_signature(self, noncestr, ticket, timestamp, url):
"""
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from wechatpy.utils import to_text
from wechatpy.client.api.base import BaseWeChatAPI
class WeChatGroup(BaseWeChatAPI):
def create(self, name):
"""
创建分组
详情请参考
http://mp.weixin.qq.com/wiki/0/56d992c605a97245eb7e617854b169fc.html
:param name: 分组名字(30个字符以内)
:return: 返回的 JSON 数据包
"""
name = to_text(name)
return self._post(
'groups/create',
data={'group': {'name': name}}
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from wechatpy.client.api.base import BaseWeChatAPI
class MerchantExpress(BaseWeChatAPI):
API_BASE_URL = 'https://api.weixin.qq.com/'
def add(self, delivery_template):
return self._post(
'merchant/express/add',
data={
'delivery_template': delivery_template
}
)
def delete(self, template_id):
return self._post(
'merchant/express/del',
data={
'template_id': template_id
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from wechatpy.client.api.base import BaseWeChatAPI
class MerchantStock(BaseWeChatAPI):
API_BASE_URL = 'https://api.weixin.qq.com/'
def add(self, product_id, quantity, sku_info=''):
return self._post(
'merchant/stock/add',
data={
'product_id': product_id,
'quantity': quantity,
'sku_info': sku_info
}
)
def reduce(self, product_id, quantity, sku_info=''):
return self._post(
'merchant/stock/reduce',
# encoding: utf-8
from __future__ import absolute_import, unicode_literals
import six
from wechatpy.client.api.base import BaseWeChatAPI
class WeChatOAuth(BaseWeChatAPI):
OAUTH_BASE_URL = 'https://open.weixin.qq.com/connect/oauth2/authorize'
def authorize_url(self, redirect_uri, state=None):
"""
构造网页授权链接
详情请参考
https://work.weixin.qq.com/api/doc#90000/90135/91022
:param redirect_uri: 授权后重定向的回调链接地址
:param state: 重定向后会带上 state 参数
:return: 返回的 JSON 数据包
"""
redirect_uri = six.moves.urllib.parse.quote(redirect_uri, safe=b'')
url_list = [
self.OAUTH_BASE_URL,
'?appid=',
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import datetime
import six
from wechatpy.client.api.base import BaseWeChatAPI
class WeChatDataCube(BaseWeChatAPI):
API_BASE_URL = 'https://api.weixin.qq.com/datacube/'
@classmethod
def _to_date_str(cls, date):
if isinstance(date, (datetime.datetime, datetime.date)):
return date.strftime('%Y-%m-%d')
elif isinstance(date, six.string_types):
return date
else:
raise ValueError('Can not convert %s type to str', type(date))
def get_user_summary(self, begin_date, end_date):
"""
获取用户增减数据
详情请参考
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from wechatpy.client.api.base import BaseWeChatAPI
class WeChatMedia(BaseWeChatAPI):
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 数据包
"""
return self._post(
url='media/upload',
params={
'type': media_type
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from wechatpy.client.api.base import BaseWeChatAPI
class WeChatMenu(BaseWeChatAPI):
"""
自定义菜单
https://work.weixin.qq.com/api/doc#90000/90135/90230
"""
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',
#!/usr/bin/env python
# encoding: utf-8
from __future__ import absolute_import, unicode_literals
from wechatpy.client.api.base import BaseWeChatAPI
class WeChatShakeAround(BaseWeChatAPI):
def get_shake_info(self, ticket):
"""
获取摇周边的设备及用户信息
详情请参考
http://qydev.weixin.qq.com/wiki/index.php?title=获取设备及用户信息
:param ticket: 摇周边业务的ticket,可在摇到的 URL 中得到,ticket 生效时间为30分钟
:return: 设备及用户信息
"""
res = self._post(
'shakearound/getshakeinfo',
data={
'ticket': ticket
}
)
return res['data']
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import time
import datetime
from .base import BaseWeChatAPI
class WeChatMisc(BaseWeChatAPI):
def short_url(self, long_url):
"""
将一条长链接转成短链接
详情请参考
http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html
:param long_url: 长链接地址
:return: 返回的 JSON 数据包
"""
return self._post(
'shorturl',
data={
'action': 'long2short',
'long_url': long_url
}