AlipayResponse.py 779 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. class AlipayResponse(object):
  5. def __init__(self):
  6. self.code = None
  7. self.msg = None
  8. self.sub_code = None
  9. self.sub_msg = None
  10. self.body = None
  11. def is_success(self):
  12. return not self.sub_code
  13. def parse_response_content(self, response_content):
  14. response = json.loads(response_content)
  15. if 'code' in response:
  16. self.code = response['code']
  17. if 'msg' in response:
  18. self.msg = response['msg']
  19. if 'sub_code' in response:
  20. self.sub_code = response['sub_code']
  21. if 'sub_msg' in response:
  22. self.sub_msg = response['sub_msg']
  23. self.body = response_content
  24. return response