ResponseObject.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. class ResponseObject(object):
  4. def __init__(self, lang='cn'):
  5. self.lang = lang
  6. def data(self, code, res={}):
  7. data_cn = {
  8. 0: '成功',
  9. 5: '请一分钟后再尝试',
  10. 8: '用户账号已存在',
  11. 9: '用户账号不存在',
  12. 10: res,
  13. 42: '两次输入的新密码错误',
  14. 43: '客户端服务器已关闭,请下载新版本使用',
  15. 44: '系统错误,发送邮件失败',
  16. 45: '系统错误,生成令牌出错!',
  17. 46: '系统错误,发送短信失败!',
  18. 47: '旧密码不正确',
  19. 74: '关联旧用户失败!',
  20. 79: '您已经申请过重置密码,请到邮箱进行确认!',
  21. 89: '您已经获得了验证码,请在10分钟后检查或再次确认。',
  22. 99: '账户或密码错误',
  23. 101: '手机的用户账号已经存在!',
  24. 102: '手机的用户账号不存在!',
  25. 103: '邮箱用户帐户已经存在!',
  26. 104: '邮箱用户帐户不存在!',
  27. 107: '用户名格式不符合规则!',
  28. 108: '邮箱格式不符合规则!',
  29. 110: '因为用户未激活,用户是无效用户!',
  30. 111: '您输入的密码不正确!',
  31. 120: '验证码已过期或不存在、请重新获得验证码!',
  32. 121: '验证码错了!',
  33. 138: '手机格式不符合规则!',
  34. 173: '数据不存在!',
  35. 174: '数据已存在',
  36. 175: 'mac地址已用完',
  37. 305: '令牌格式是错误的,相关参数是不存在的!',
  38. 307: '令牌已过期!',
  39. 309: '你没有权限访问',
  40. 404: 'You don not have permission to access this!',
  41. 444: '请确认参数的正确性!',
  42. 1112: '您输入的两次密码不一致!',
  43. 208: '只能预定当天的或者以后的!',
  44. }
  45. data_en = {
  46. 0: 'Success',
  47. 5: 'Please try again one minute later!',
  48. 8: 'User accounts already exist',
  49. 9: 'User accounts is not exist',
  50. 10: res,
  51. 42: 'The new password entered twice is incorrect',
  52. 43: 'The client server is closed. Please download the new version for use',
  53. 44: 'System error,send email fail!',
  54. 45: 'System error,generate token fail!',
  55. 46: 'System error, sending SMS failed!',
  56. 47: 'Old password is incorrect',
  57. 74: 'Failed to connect old users!',
  58. 79: 'You have applied for reset password, please go to email for confirmation!',
  59. 89: 'You have already obtained the verification code, please check it or get it again after 10 minutes.',
  60. 99: ' ERROR Incorrect account or password',
  61. 101: 'The user account of the mobile phone has already existed!',
  62. 102: 'The user account of the mobile phone does not exist!',
  63. 103: 'The mailbox user account has already existed!',
  64. 104: 'The mailbox user account does not exist!',
  65. 107: 'The username format does not conform to the rules!',
  66. 108: 'The mailbox format does not conform to the rules! ',
  67. 110: 'Because the user is not activated, the user is an invalid user!',
  68. 111: 'The password you entered is incorrect!',
  69. 120: 'The captcha has expired or does not exist, please obtain the captcha again!',
  70. 121: 'The verification code is wrong!',
  71. 138: 'The phone format does not conform to the rules! ',
  72. 173: 'Data does not exists!',
  73. 174: 'Data already exists',
  74. 175: 'MAC address has been used up',
  75. 305: 'The Token format is wrong and the related parameter is None!',
  76. 307: 'The Token has expired!',
  77. 309: 'You have no access',
  78. 404: 'You don not have permission to access this!',
  79. 444: 'Please confirm the correctness of the parameters!',
  80. 1112: 'The two passwords you entered do not match!',
  81. }
  82. if self.lang == 'cn':
  83. msg = data_cn
  84. else:
  85. msg = data_en
  86. try:
  87. message = msg[code]
  88. except Exception as e:
  89. message = '系统错误,code不存在'
  90. return {'code': code, 'msg': message, 'res': res}
  91. def formal(self, code, res={}):
  92. formal_data = self.data(code, res)
  93. return json.dumps(formal_data,ensure_ascii=False)
  94. def json(self, code, res={}):
  95. result = self.formal(code, res)
  96. return HttpResponse(result)