ResponseObject.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. class ResponseObject(object):
  4. def __init__(self, lang='en', returntype='currency'):
  5. self.lang = lang
  6. self.returntype = returntype
  7. def data(self, code, res={}):
  8. data_en = {
  9. 0: 'Success',
  10. 5: 'Please try again one minute later!',
  11. 10: res,
  12. 12: 'You are not the primary user of the device!',
  13. 14: 'Device is not belong to you',
  14. 15: 'Device has been bound',
  15. 16: 'WeChat has been bound, please log in and unbind using WeChat',
  16. 17: 'No email or mobile phone login',
  17. 44: 'System error! Can not send email',
  18. 48: 'System object error!',
  19. 89: 'Already send the code, please check it or get it again after 10m',
  20. 90: 'please check code or get it again after 1m',
  21. 99: 'Mail doesn\'t exist!',
  22. 100: 'Phone format error!',
  23. 101: 'Phone already existed!',
  24. 102: 'Phone doesn\'t exist!',
  25. 103: 'Mail already existed!',
  26. 104: 'Account doesn\'t exist!',
  27. 105: 'Email format error!',
  28. 107: 'The username not conform to the rules!',
  29. 109: 'The password not conform to the rules!',
  30. 110: 'user doesn\'t activated',
  31. 111: 'Error password',
  32. 112: 'Fingerprint login is not turned on',
  33. 119: 'The qr code has expired',
  34. 120: 'The code has expired',
  35. 121: 'The verification code is wrong!',
  36. 173: 'Data does not exists!',
  37. 174: 'Data already exists!',
  38. 176: 'Delete error',
  39. 177: 'Update error',
  40. 178: 'ADD error',
  41. 179: 'Nickname repeated',
  42. 201: 'You can only add 3 custom voice at most',
  43. 306: 'The link has expired!',
  44. 309: 'Please ReLogin! errmsg token',
  45. 404: 'You don not have permission to access this!',
  46. 414: 'Please confirm the request url!',
  47. 424: 'Database Error !',
  48. 444: 'Wrong parameters!',
  49. 474: 'System Maintaining!',
  50. 475: 'App Version too low, please upgrade!',
  51. 500: 'Query Database Error:',
  52. 700: 'Upload file error',
  53. 701: 'The file does not exist!',
  54. 711: 'Do not downgrade',
  55. 712: 'Area needs to be consistent',
  56. 713: 'Storage rules cannot be changed during the validity period',
  57. 717: 'Authorization expires',
  58. 800: 'Order does not exist',
  59. 801: 'The refund amount cannot be greater than the order price',
  60. 802: 'The order has been completed and cannot be cancelled',
  61. 804: 'Refund, please do not repeat the operation',
  62. 805: 'No refund',
  63. 900: 'There is no information about this version!',
  64. 901: 'Getting URL failure!',
  65. 902: 'No update!',
  66. 903: 'Error filename',
  67. 904: 'Version does not support this feature!',
  68. 906: 'Cause of file operation error',
  69. 907: 'The download file does not exist!',
  70. 10001: 'Customer number, customer confidentiality error',
  71. 10002: 'Check your configuration: no customer number, customer confidentiality',
  72. 10003: 'The authorization code does not exist. Please reauthorize',
  73. 10004: 'The request method is incorrect. Please contact the developer',
  74. 10005: 'Wrong configuration, wrong customer number',
  75. 10006: 'Configuration error. The path value is incorrect',
  76. 10007: 'This device is not an experience package and cannot be reset',
  77. 10008: 'The user does not have this device and cannot transfer',
  78. 10009: 'The user already owns the device and cannot transfer it',
  79. 10010: 'Devices that are not under the same account cannot be transferred',
  80. 10011: 'Receiving transfer device does not exist and cannot be transferred',
  81. 10012: 'Experience packages cannot be transferred',
  82. 10013: 'Original equipment package has expired and cannot be transferred',
  83. 10014: 'Accept transfer of equipment packages that have not expired and cannot be transferred',
  84. 10015: 'Shared devices cannot be transferred',
  85. 10030: 'No purchase of cloud storage',
  86. 10031: 'The cloud storage has expired',
  87. 10032: 'The switched cloud storage package ID cannot be the same as the one in use',
  88. 10033: 'The primary user of the device cannot purchase it',
  89. 10034: 'Non device primary users cannot view cloud storage',
  90. 10035: 'Non device primary users cannot experience cloud storage',
  91. 10036: 'Non device primary users cannot exchange for cloud storage',
  92. 10037: 'Non device primary user cannot transfer device',
  93. 10038: 'Non device primary user cannot transfer packages',
  94. 10039: 'Activation code has been used',
  95. 10040: 'Invalid activation code',
  96. 10041: 'This device has purchased a domestic cloud storage package, and cannot purchase a foreign cloud storage package',
  97. 10042: 'The device has registered a certificate',
  98. 10043: 'The device does not registered a certificate',
  99. 10044: 'Request to publish MQTT topic message failed',
  100. 10045: 'Already the latest version',
  101. }
  102. data_cn = {
  103. 0: '成功',
  104. 5: '请一分钟后再尝试',
  105. 10: res,
  106. 12: '非设备主用户',
  107. 14: '设备不属于您',
  108. 15: '设备已被绑定',
  109. 16: '微信已被绑定,请使用微信登录并解绑',
  110. 17: '未绑定邮箱或者手机登录方式',
  111. 44: '系统错误!无法发送电子邮件',
  112. 48: '系统对象错误',
  113. 89: '已发验证码,请检测或10分钟后重新获取。',
  114. 90: '请检测或1分钟后重新获取。',
  115. 99: '邮箱不存在!',
  116. 100: '手机格式错误!',
  117. 101: '手机已存在!',
  118. 102: '手机不存在!',
  119. 103: '邮箱已存在!',
  120. 104: '账户不存在!',
  121. 105: '邮箱格式错误!',
  122. 107: '用户名格式不符合!',
  123. 109: '密码格式不符合!',
  124. 110: '用户未激活!',
  125. 111: '密码不正确!',
  126. 112: '未开通指纹登录',
  127. 119: '二维码过期',
  128. 120: '验证码过期',
  129. 121: '验证码错了!',
  130. 173: '数据不存在!',
  131. 174: '数据已存在!',
  132. 176: '删除错误',
  133. 177: '更新错误',
  134. 178: '增加错误',
  135. 179: '名称不能重复',
  136. 201: '最多只能添加3条自定义语音',
  137. 306: '链接已超过有效期!',
  138. 309: '请重新登录!',
  139. 404: '您没有访问的权限!',
  140. 414: '请确认请求url!',
  141. 424: '数据库错误!',
  142. 444: '参数错误!',
  143. 474: '系统维护中!',
  144. 475: '版本过低,请升级程序!',
  145. 500: '查询数据库错误!',
  146. 700: '上传文件错误',
  147. 701: '文件不存在',
  148. 711: '不可降级',
  149. 712: '区域不一致',
  150. 713: '有效期内不可更改存储规则',
  151. 717: '授权过期',
  152. 800: '订单不存在',
  153. 801: '退款金额不能大于订单价格',
  154. 802: '订单已完成,不能撤销',
  155. 804: '订单已退款,请勿重复操作',
  156. 805: '无法退款',
  157. 900: '版本信息不存在',
  158. 901: '获取链接失败',
  159. 902: '无更新!',
  160. 903: '文件名不符合!',
  161. 904: '版本不支持本功能!',
  162. 906: '文件操作错误',
  163. 907: '文件不存在!',
  164. 10001: '客户编号,客户机密错误',
  165. 10002: '检查您的配置:没有客户编号,客户机密',
  166. 10003: '授权码不存在,请重新授权',
  167. 10004: '请求方法不正确。请联系开发者',
  168. 10005: '配置错误,客户编号这个值是错误的',
  169. 10006: '配置错误,路径这个值是错误的',
  170. 10007: '此设备不是体验套餐,无法重置',
  171. 10008: '用户没有此设备,无法转移',
  172. 10009: '用户已拥有此设备,无法转移',
  173. 10010: '不是同一账户下的设备,无法转移',
  174. 10011: '接受转移设备不存在,无法转移',
  175. 10012: '体验套餐无法转移',
  176. 10013: '原设备套餐已过期,无法转移',
  177. 10014: '接受转移设备套餐未过期,无法转移',
  178. 10015: '分享的设备无法转移',
  179. 10030: '未购买云存',
  180. 10031: '云存已过期',
  181. 10032: '切换的云存套餐ID不能与正在使用中的相同',
  182. 10033: '非设备主用户无法购买',
  183. 10034: '非设备主用户无法查看云存',
  184. 10035: '非设备主用户无法体验云存',
  185. 10036: '非设备主用户无法兑换云存',
  186. 10037: '非设备主用户无法转移设备',
  187. 10038: '非设备主用户无法转移套餐',
  188. 10039: '激活码已被使用过',
  189. 10040: '无效激活码',
  190. 10041: '此设备已购买过国内云存套餐,无法购买国外云存套餐',
  191. 10042: '此设备已注册证书',
  192. 10043: '此设备没有注册证书',
  193. 10044: '请求发布MQTT主题消息失败',
  194. 10045: '当前为最新版本',
  195. }
  196. if self.lang == 'cn':
  197. msg = data_cn
  198. elif self.lang == 'zh-Hans':
  199. msg = data_cn
  200. elif self.lang == 'zh-Hant':
  201. msg = data_cn
  202. else:
  203. msg = data_en
  204. try:
  205. message = msg[code]
  206. except Exception as e:
  207. message = '系统错误,code不存在'
  208. print(self.lang == 'cn')
  209. print(msg)
  210. if self.returntype=='pc':
  211. return {'code': code, 'msg': message, 'data': res, 'error_code': code}
  212. return {'result_code': code, 'reason': message, 'result': res, 'error_code': code}
  213. def formal(self, code, res={}):
  214. formal_data = self.data(code, res)
  215. return json.dumps(formal_data, ensure_ascii=False)
  216. def json(self, code, res={}):
  217. result = self.formal(code, res)
  218. return HttpResponse(result)