scan.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from optionaldict import optionaldict
  4. from library.wechatpy.client.api.base import BaseWeChatAPI
  5. class WeChatScan(BaseWeChatAPI):
  6. API_BASE_URL = 'https://api.weixin.qq.com/scan/'
  7. def get_merchant_info(self):
  8. """
  9. 获取商户信息
  10. 详情请参考
  11. http://mp.weixin.qq.com/wiki/6/c61604ff6890d386d6227945ad4a68d2.html
  12. :return: 返回的 JSON 数据包
  13. 使用示例::
  14. from wechatpy import WeChatClient
  15. client = WeChatClient('appid', 'secret')
  16. info = client.scan.get_merchant_info()
  17. """
  18. return self._get('merchantinfo/get')
  19. def create_product(self, product_data):
  20. """
  21. 创建商品
  22. 详情请参考
  23. http://mp.weixin.qq.com/wiki/6/c61604ff6890d386d6227945ad4a68d2.html
  24. :return: 返回的 JSON 数据包
  25. """
  26. return self._post('product/create', data=product_data)
  27. def modify_product_status(self, standard, key, status):
  28. """
  29. 提交审核/取消发布商品
  30. 详情请参考
  31. http://mp.weixin.qq.com/wiki/15/1007691d0f1c10a0588c6517f12ed70f.html
  32. :param standard: 商品编码标准
  33. :param key: 商品编码内容
  34. :param status: 设置发布状态。on 为提交审核,off 为取消发布
  35. :return: 返回的 JSON 数据包
  36. """
  37. data = {
  38. 'keystandard': standard,
  39. 'keystr': key,
  40. 'status': status,
  41. }
  42. return self._post('product/modstatus', data=data)
  43. def publish_product(self, standard, key):
  44. """
  45. 提交审核商品 shortcut 接口
  46. 等同于调用 ``modify_product_status(standard, key, 'on')``
  47. """
  48. return self.modify_product_status(standard, key, 'on')
  49. def unpublish_product(self, standard, key):
  50. """
  51. 取消发布商品 shortcut 接口
  52. 等同于调用 ``modify_product_status(standard, key, 'off')``
  53. """
  54. return self.modify_product_status(standard, key, 'off')
  55. def set_test_whitelist(self, userids=None, usernames=None):
  56. """
  57. 设置测试人员白名单
  58. 注意:每次设置均被视为一次重置,而非增量设置。openid、微信号合计最多设置10个。
  59. 详情请参考
  60. http://mp.weixin.qq.com/wiki/15/1007691d0f1c10a0588c6517f12ed70f.html
  61. :param userids: 可选,测试人员的 openid 列表
  62. :param usernames: 可选,测试人员的微信号列表
  63. :return: 返回的 JSON 数据包
  64. """
  65. data = optionaldict(
  66. openid=userids,
  67. username=usernames
  68. )
  69. return self._post('testwhitelist/set', data=data)
  70. def get_product(self, standard, key):
  71. """
  72. 查询商品信息
  73. 详情请参考
  74. http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
  75. :param standard: 商品编码标准
  76. :param key: 商品编码内容
  77. :return: 返回的 JSON 数据包
  78. """
  79. data = {
  80. 'keystandard': standard,
  81. 'keystr': key,
  82. }
  83. return self._post('product/get', data=data)
  84. def list_product(self, offset=0, limit=10, status=None, key=None):
  85. """
  86. 批量查询商品信息
  87. 详情请参考
  88. http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
  89. :param offset: 可选,批量查询的起始位置,从 0 开始,包含该起始位置
  90. :param limit: 可选,批量查询的数量,默认为 10
  91. :param status: 可选,支持按状态拉取。on为发布状态,off为未发布状态,
  92. check为审核中状态,reject为审核未通过状态,all为所有状态
  93. :param key: 支持按部分编码内容拉取。填写该参数后,可将编码内容中包含所传参数的商品信息拉出
  94. :return: 返回的 JSON 数据包
  95. """
  96. data = optionaldict(
  97. offset=offset,
  98. limit=limit,
  99. status=status,
  100. keystr=key,
  101. )
  102. return self._post('product/getlist', data=data)
  103. def update_product(self, product_data):
  104. """
  105. 更新商品信息
  106. 详情请参考
  107. http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
  108. :return: 返回的 JSON 数据包
  109. """
  110. return self._post('product/update', data=product_data)
  111. def clear_product(self, standard, key):
  112. """
  113. 清除商品信息
  114. 详情请参考
  115. http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
  116. :param standard: 商品编码标准
  117. :param key: 商品编码内容
  118. :return: 返回的 JSON 数据包
  119. """
  120. data = {
  121. 'keystandard': standard,
  122. 'keystr': key,
  123. }
  124. return self._post('product/clear', data=data)
  125. def check_ticket(self, ticket):
  126. """
  127. 检查 wxticket 参数有效性
  128. 详情请参考
  129. http://mp.weixin.qq.com/wiki/15/7fa787701295b884410b5163e13313af.html
  130. :param ticket: 请求 URL 中带上的 wxticket 参数
  131. :return: 返回的 JSON 数据包
  132. """
  133. return self._post('scanticket/check', data={'ticket': ticket})