complaint.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. if not complainted_mchid:
  21. complainted_mchid = self.client.mchid
  22. path = '/v3/merchant-service/complaints-v2?limit=%s&offset=%s&begin_date=%s&end_date=%s&complainted_mchid=%s'
  23. path = path % (limit, offset, begin_date, end_date, 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, response_content, response_images = None, jump_url = None,
  81. jump_url_text = None):
  82. """提交投诉回复
  83. :param complaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  84. :param response_content: 回复内容,具体的投诉处理方案,限制200个字符以内。示例值:'已与用户沟通解决'
  85. :param response_images: 回复图片,传入调用商户上传反馈图片接口返回的media_id,最多上传4张图片凭证。示例值:['file23578_21798531.jpg', 'file23578_21798532.jpg']
  86. :param jump_url: 跳转链接,附加跳转链接,引导用户跳转至商户客诉处理页面,链接需满足https格式。示例值:"https://www.xxx.com/notify"
  87. :param jump_url_text: 转链接文案,展示给用户的文案,附在回复内容之后。用户点击文案,即可进行跳转。示例值:"查看订单详情"
  88. """
  89. params = {}
  90. if not complaint_id:
  91. raise Exception('complaint_id is not assigned')
  92. if response_content:
  93. params.update({'response_content': response_content})
  94. else:
  95. raise Exception('response_content is not assigned')
  96. params.update({'complainted_mchid': self.client.core._mchid})
  97. if response_images:
  98. params.update({'response_images': response_images})
  99. if jump_url:
  100. params.update({'jump_url': jump_url})
  101. if jump_url_text:
  102. params.update({'jump_url_text': jump_url_text})
  103. path = '/v3/merchant-service/complaints-v2/%s/response' % complaint_id
  104. return self.client.core.request(path, method = RequestType.POST, data = params)
  105. def complaint_complete(self, complaint_id):
  106. """反馈投诉处理完成
  107. :param complaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  108. """
  109. params = {}
  110. if not complaint_id:
  111. raise Exception('complaint_id is not assigned')
  112. params.update({'complainted_mchid': self.client.core._mchid})
  113. path = '/v3/merchant-service/complaints-v2/%s/complete' % complaint_id
  114. return self.client.core.request(path, method = RequestType.POST, data = params)
  115. def complaint_image_download(self, media_url):
  116. """下载客户投诉图片
  117. :param media_url: 图片下载地址,示例值:'https://api.mch.weixin.qq.com/v3/merchant-service/images/xxxxx'
  118. """
  119. path = media_url[len(self.client.core._gate_way):] if media_url.startswith(
  120. self.client.core._gate_way) else media_url
  121. return self.client.core.request(path, skip_verify = True)
  122. def complaint_update_refund(self, complaint_id, action, launch_refund_day = None, reject_reason = None,
  123. reject_media_list = {}, remark = None):
  124. """更新退款审批结果
  125. :param compaint_id: 投诉单对应的投诉单号。示例值:'200201820200101080076610000'
  126. :param action: 审批动作,同意 或 拒绝,REJECT:拒绝,拒绝退款;APPROVE:同意,同意退款;示例值:'APPROVE'
  127. :param launch_refund_day: 预计发起退款时间,预计将在多少个工作日内能发起退款, 0代表当天。示例值:3
  128. :param reject_reason: 拒绝退款原因,示例值:'拒绝退款'
  129. :param reject_media_list: 拒绝退款的举证图片列表,传入调用“商户上传反馈图片”接口返回的media_id,最多上传4张图片凭证,示例值:{'file23578_21798531.jpg'}
  130. :param remark: 备注,示例值:'已处理完成'
  131. """
  132. if complaint_id:
  133. path = '/v3/merchant-service/complaints-v2/%s/update-refund-progress' % complaint_id
  134. else:
  135. raise Exception('complaint_id is not assigned')
  136. params = {}
  137. if action:
  138. params.update({'action': action})
  139. else:
  140. raise Exception('action is not assigned')
  141. if isinstance(launch_refund_day, int):
  142. params.update({'launch_refund_day': launch_refund_day})
  143. if reject_reason:
  144. params.update({'reject_reason': reject_reason})
  145. if reject_media_list:
  146. params.update({'reject_media_list': reject_media_list})
  147. if remark:
  148. params.update({'remark': remark})
  149. return self.client.core.request(path, method = RequestType.POST, data = params)