complaint.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import datetime
  4. from ..api.base import BaseWeChatAPI
  5. from ...type import RequestType
  6. class Complaint(BaseWeChatAPI):
  7. def complaint_list_query(
  8. self, begin_date = None, end_date = None, limit = 10, offset = 0, complainted_mchid = None):
  9. """查询投诉单列表
  10. :param begin_date: 开始日期,投诉发生的开始日期,格式为YYYY-MM-DD。注意,查询日期跨度不超过30天,当前查询为实时查询。示例值:'2019-01-01'
  11. :param end_date: 结束日期,投诉发生的结束日期,格式为YYYY-MM-DD。注意,查询日期跨度不超过30天,当前查询为实时查询。示例值:'2019-01-01'
  12. :param limit: 分页大小,设置该次请求返回的最大投诉条数,范围【1,50】,商户自定义字段,不传默认为10。示例值:5
  13. :param offset: 分页开始位置,该次请求的分页开始位置,从0开始计数,例如offset=10,表示从第11条记录开始返回,不传默认为0 。示例值:10
  14. :param complainted_mchid: 被诉商户号,投诉单对应的被诉商户号。示例值:'1900012181'
  15. """
  16. if not begin_date:
  17. begin_date = datetime.datetime.now().strftime("%Y-%m-%d")
  18. if not end_date:
  19. end_date = begin_date
  20. path = '/v3/merchant-service/complaints-v2?limit={}&offset={}&begin_date={}&end_date={}'
  21. path = path.format(limit, offset, begin_date, end_date)
  22. if complainted_mchid:
  23. path = '{}&complainted_mchid={}'.format(path, complainted_mchid)
  24. return self.client.core.request(path)
  25. def complaint_detail_query(self, complaint_id):
  26. """查询投诉单详情
  27. :param complaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  28. """
  29. if not complaint_id:
  30. raise Exception('complaint_id is not assigned.')
  31. path = '/v3/merchant-service/complaints-v2/%s' % complaint_id
  32. return self.client.core.request(path)
  33. def complaint_history_query(self, complaint_id, limit = 100, offset = 0):
  34. """查询投诉协商历史
  35. :param complaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  36. :param limit: 分页大小,设置该次请求返回的最大协商历史条数,范围[1,300],不传默认为100。。示例值:5
  37. :param offset: 分页开始位置,该次请求的分页开始位置,从0开始计数,例如offset=10,表示从第11条记录开始返回,不传默认为0。示例值:10
  38. """
  39. if not complaint_id:
  40. raise Exception('complaint_id is not assigned.')
  41. if limit not in range(1, 301):
  42. limit = 100
  43. path = '/v3/merchant-service/complaints-v2/%s/negotiation-historys?limit=%s&offset=%s' % (
  44. complaint_id, limit, offset)
  45. return self.client.core.request(path)
  46. def complaint_notification_create(self, url):
  47. """创建投诉通知回调地址
  48. :param: url: 通知地址,仅支持https。示例值:'https://www.xxx.com/notify'
  49. """
  50. params = {}
  51. if url:
  52. params.update({'url': url})
  53. else:
  54. raise Exception('url is not assigned.')
  55. path = '/v3/merchant-service/complaint-notifications'
  56. return self.client.core.request(path, method = RequestType.POST, data = params)
  57. def complaint_notification_query(self):
  58. """查询投诉通知回调地址
  59. :param: url: 通知地址,仅支持https。示例值:'https://www.xxx.com/notify'
  60. """
  61. path = '/v3/merchant-service/complaint-notifications'
  62. return self.client.core.request(path)
  63. def complaint_notification_update(self, url):
  64. """更新投诉通知回调地址
  65. :param: url: 通知地址,仅支持https。示例值:'https://www.xxx.com/notify'
  66. """
  67. params = {}
  68. if url:
  69. params.update({'url': url})
  70. else:
  71. raise Exception('url is not assigned.')
  72. path = '/v3/merchant-service/complaint-notifications'
  73. return self.client.core.request(path, method = RequestType.PUT, data = params)
  74. def complaint_notification_delete(self):
  75. """删除投诉通知回调地址
  76. :param: url: 通知地址,仅支持https。示例值:'https://www.xxx.com/notify'
  77. """
  78. path = '/v3/merchant-service/complaint-notifications'
  79. return self.client.core.request(path, method = RequestType.DELETE)
  80. def complaint_response(self, complaint_id, complainted_mchid, response_content, response_images = None,
  81. jump_url = None,
  82. jump_url_text = None):
  83. """提交投诉回复
  84. :param complaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  85. :param response_content: 回复内容,具体的投诉处理方案,限制200个字符以内。示例值:'已与用户沟通解决'
  86. :param response_images: 回复图片,传入调用商户上传反馈图片接口返回的media_id,最多上传4张图片凭证。示例值:['file23578_21798531.jpg', 'file23578_21798532.jpg']
  87. :param jump_url: 跳转链接,附加跳转链接,引导用户跳转至商户客诉处理页面,链接需满足https格式。示例值:"https://www.xxx.com/notify"
  88. :param jump_url_text: 转链接文案,展示给用户的文案,附在回复内容之后。用户点击文案,即可进行跳转。示例值:"查看订单详情"
  89. """
  90. params = {}
  91. if not complaint_id:
  92. raise Exception('complaint_id is not assigned')
  93. if response_content:
  94. params.update({'response_content': response_content})
  95. else:
  96. raise Exception('response_content is not assigned')
  97. params.update({'complainted_mchid': complainted_mchid})
  98. if response_images:
  99. params.update({'response_images': response_images})
  100. if jump_url:
  101. params.update({'jump_url': jump_url})
  102. if jump_url_text:
  103. params.update({'jump_url_text': jump_url_text})
  104. path = '/v3/merchant-service/complaints-v2/%s/response' % complaint_id
  105. return self.client.core.request(path, method = RequestType.POST, data = params)
  106. def complaint_complete(self, complaint_id, complainted_mchid):
  107. """反馈投诉处理完成
  108. :param complaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  109. """
  110. params = {}
  111. if not complaint_id:
  112. raise Exception('complaint_id is not assigned')
  113. params.update({'complainted_mchid': complainted_mchid})
  114. path = '/v3/merchant-service/complaints-v2/%s/complete' % complaint_id
  115. return self.client.core.request(path, method = RequestType.POST, data = params)
  116. def complaint_image_download(self, media_url):
  117. """下载客户投诉图片
  118. :param media_url: 图片下载地址,示例值:'https://api.mch.weixin.qq.com/v3/merchant-service/images/xxxxx'
  119. """
  120. path = media_url[len(self.client.core._gate_way):] if media_url.startswith(
  121. self.client.core._gate_way) else media_url
  122. return self.client.core.request(path, skip_verify = True)
  123. def complaint_update_refund(self, complaint_id, action, launch_refund_day = None, reject_reason = None,
  124. reject_media_list = {}, remark = None):
  125. """更新退款审批结果
  126. :param compaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  127. :param action: 审批动作,同意 或 拒绝,REJECT:拒绝,拒绝退款;APPROVE:同意,同意退款;示例值:'APPROVE'
  128. :param launch_refund_day: 预计发起退款时间,预计将在多少个工作日内能发起退款, 0代表当天。示例值:3
  129. :param reject_reason: 拒绝退款原因,示例值:'拒绝退款'
  130. :param reject_media_list: 拒绝退款的举证图片列表,传入调用“商户上传反馈图片”接口返回的media_id,最多上传4张图片凭证,示例值:{'file23578_21798531.jpg'}
  131. :param remark: 备注,示例值:'已处理完成'
  132. """
  133. if complaint_id:
  134. path = '/v3/merchant-service/complaints-v2/%s/update-refund-progress' % complaint_id
  135. else:
  136. raise Exception('complaint_id is not assigned')
  137. params = {}
  138. if action:
  139. params.update({'action': action})
  140. else:
  141. raise Exception('action is not assigned')
  142. if isinstance(launch_refund_day, int):
  143. params.update({'launch_refund_day': launch_refund_day})
  144. if reject_reason:
  145. params.update({'reject_reason': reject_reason})
  146. if reject_media_list:
  147. params.update({'reject_media_list': reject_media_list})
  148. if remark:
  149. params.update({'remark': remark})
  150. return self.client.core.request(path, method = RequestType.POST, data = params)