ResponseObject.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. class ResponseObject(object):
  4. def __init__(self, lang='en'):
  5. self.lang = lang
  6. def data(self, code, res={}):
  7. data_en = {
  8. 0: 'Success',
  9. 5: 'Please try again one minute later!',
  10. 10: res,
  11. 12: 'You are not the primary user of the device!',
  12. 14: 'Device is not belong to you',
  13. 15: 'Device has been bound',
  14. 16: 'WeChat has been bound, please log in and unbind using WeChat',
  15. 17: 'No email or mobile phone login',
  16. 44: 'System error! Can not send email',
  17. 48: 'System object error!',
  18. 89: 'Already send the code, please check it or get it again after 10m',
  19. 90: 'please check code or get it again after 1m',
  20. 99: 'Mail doesn\'t exist!',
  21. 100: 'Phone format error!',
  22. 101: 'Phone already existed!',
  23. 102: 'Phone doesn\'t exist!',
  24. 103: 'Mail already existed!',
  25. 104: 'Account doesn\'t exist!',
  26. 105: 'Email format error!',
  27. 107: 'The username not conform to the rules!',
  28. 109: 'The password not conform to the rules!',
  29. 110: 'user doesn\'t activated',
  30. 111: 'Error password',
  31. 112: 'Fingerprint login is not turned on',
  32. 119: 'The qr code has expired',
  33. 120: 'The code has expired',
  34. 121: 'The verification code is wrong!',
  35. 173: 'Data does not exists!',
  36. 174: 'Data already exists!',
  37. 176: 'Delete error',
  38. 177: 'Update error',
  39. 178: 'ADD error',
  40. 179: 'Nickname repeated',
  41. 306: 'The link has expired!',
  42. 309: 'Please ReLogin! errmsg token',
  43. 404: 'You don not have permission to access this!',
  44. 414: 'Please confirm the request url!',
  45. 424: 'Database Error !',
  46. 444: 'Wrong parameters!',
  47. 474: 'System Maintaining!',
  48. 475: 'App Version too low, please upgrade!',
  49. 500: 'Query Database Error:',
  50. 700: 'Upload file error',
  51. 701: 'The file does not exist!',
  52. 711: 'Do not downgrade',
  53. 712: 'Area needs to be consistent',
  54. 713: 'Storage rules cannot be changed during the validity period',
  55. 717: 'Authorization expires',
  56. 900: 'There is no information about this version!',
  57. 901: 'Getting URL failure!',
  58. 902: 'No update!',
  59. 903: 'Error filename',
  60. 904: 'Version does not support this feature!',
  61. 906: 'Cause of file operation error',
  62. 907: 'The download file does not exist!',
  63. 10001: 'Customer number, customer confidentiality error',
  64. 10002: 'Check your configuration: no customer number, customer confidentiality',
  65. 10003: 'The authorization code does not exist. Please reauthorize',
  66. 10004: 'The request method is incorrect. Please contact the developer',
  67. 10005: 'Wrong configuration, wrong customer number',
  68. 10006: 'Configuration error. The path value is incorrect',
  69. }
  70. data_cn = {
  71. 0: '成功',
  72. 5: '请一分钟后再尝试',
  73. 10: res,
  74. 12: '非设备主用户',
  75. 14: '设备不属于您',
  76. 15: '设备已被绑定',
  77. 16: '微信已被绑定,请使用微信登录并解绑',
  78. 17: '未绑定邮箱或者手机登录方式',
  79. 44: '系统错误!无法发送电子邮件',
  80. 48: '系统对象错误',
  81. 89: '已发验证码,请检测或10分钟后重新获取。',
  82. 90: '请检测或1分钟后重新获取。',
  83. 99: '邮箱不存在!',
  84. 100: '手机格式错误!',
  85. 101: '手机已存在!',
  86. 102: '手机不存在!',
  87. 103: '邮箱已存在!',
  88. 104: '账户不存在!',
  89. 105: '邮箱格式错误!',
  90. 107: '用户名格式不符合!',
  91. 109: '密码格式不符合!',
  92. 110: '用户未激活!',
  93. 111: '密码不正确!',
  94. 112: '未开通指纹登录',
  95. 119: '二维码过期',
  96. 120: '验证码过期',
  97. 121: '验证码错了!',
  98. 173: '数据不存在!',
  99. 174: '数据已存在!',
  100. 176: '删除错误',
  101. 177: '更新错误',
  102. 178: '增加错误',
  103. 179: '名称不能重复',
  104. 306: '链接已超过有效期!',
  105. 309: '请重新登录!',
  106. 404: '您没有访问的权限!',
  107. 414: '请确认请求url!',
  108. 424: '数据库错误!',
  109. 444: '参数错误!',
  110. 474: '系统维护中!',
  111. 475: '版本过低,请升级程序!',
  112. 500: '查询数据库错误!',
  113. 700: '上传文件错误',
  114. 701: '文件不存在',
  115. 711: '不可降级',
  116. 712: '区域不一致',
  117. 713: '有效期内不可更改存储规则',
  118. 717: '授权过期',
  119. 900: '版本信息不存在',
  120. 901: '获取链接失败',
  121. 902: '无更新!',
  122. 903: '文件名不符合!',
  123. 904: '版本不支持本功能!',
  124. 906: '文件操作错误',
  125. 907: '文件不存在!',
  126. 10001: '客户编号,客户机密错误',
  127. 10002: '检查您的配置:没有客户编号,客户机密',
  128. 10003: '授权码不存在,请重新授权',
  129. 10004: '请求方法不正确。请联系开发者',
  130. 10005: '配置错误,客户编号这个值是错误的',
  131. 10006: '配置错误,路径这个值是错误的',
  132. }
  133. if self.lang == 'cn':
  134. msg = data_cn
  135. elif self.lang == 'zh-Hans':
  136. msg = data_cn
  137. elif self.lang == 'zh-Hant':
  138. msg = data_cn
  139. else:
  140. msg = data_en
  141. try:
  142. message = msg[code]
  143. except Exception as e:
  144. message = '系统错误,code不存在'
  145. print(self.lang == 'cn')
  146. print(msg)
  147. return {'result_code': code, 'reason': message, 'result': res, 'error_code': code}
  148. def formal(self, code, res={}):
  149. formal_data = self.data(code, res)
  150. return json.dumps(formal_data, ensure_ascii=False)
  151. def json(self, code, res={}):
  152. result = self.formal(code, res)
  153. return HttpResponse(result)