ResponseObject.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import simplejson as json
  2. from django.shortcuts import HttpResponse
  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=None):
  8. if code == 0 and res is None:
  9. res = {}
  10. data_en = {
  11. 0: 'Success',
  12. 5: 'Please try again one minute later!',
  13. 10: res,
  14. 12: 'You are not the primary user of the device!',
  15. 13: 'Timestamp token verification failed',
  16. 14: 'Device is not belong to you',
  17. 15: 'Device has been bound',
  18. 16: 'WeChat has been bound, please log in and unbind using WeChat',
  19. 17: 'No email or mobile phone login',
  20. 18: 'User not logged in',
  21. 44: 'System error! Can not send email',
  22. 48: 'System object error!',
  23. 89: 'Already send the code, please check it or get it again after 10m',
  24. 90: 'please check code or get it again after 1m',
  25. 91: 'The mobile phone has reached the maximum limit for obtaining SMS verification codes today.',
  26. 92: 'Verification not obtained or verification code expired',
  27. 99: 'Mail doesn\'t exist!',
  28. 100: 'Phone format error!',
  29. 101: 'Phone already existed!',
  30. 102: 'Phone doesn\'t exist!',
  31. 103: 'Mail already existed!',
  32. 104: 'Account doesn\'t exist!',
  33. 105: 'Email format error!',
  34. 106: 'Illegal profile picture!',
  35. 107: 'The username not conform to the rules!',
  36. 108: 'Illegal nickname!',
  37. 109: 'Supports 6-16 numbers, English letters, and symbols',
  38. 110: 'user doesn\'t activated',
  39. 111: 'Error password',
  40. 112: 'Fingerprint login is not turned on',
  41. 119: 'The qr code has expired',
  42. 120: 'The code has expired',
  43. 121: 'The verification code is wrong!',
  44. 173: 'Data does not exists!',
  45. 174: 'Data already exists!',
  46. 176: 'Delete error',
  47. 177: 'Update error',
  48. 178: 'ADD error',
  49. 179: 'Nickname repeated',
  50. 180: 'Smart button scene trigger conditions cannot be repeated',
  51. 181: 'The gateway only bind 3 smart button at most',
  52. 182: 'Scene effective time conflict',
  53. 183: 'This user is not bound to an e-mail address',
  54. 184: 'Image Violations',
  55. 201: 'You can only add 3 custom voice at most',
  56. 306: 'The link has expired!',
  57. 309: 'Please ReLogin! errmsg token',
  58. 310: 'Your account is being logged in on another device, if it was not done by yourself, please change your password immediately!',
  59. 404: 'You don not have permission to access this!',
  60. 414: 'Please confirm the request url!',
  61. 424: 'Database Error !',
  62. 444: 'Wrong parameters!',
  63. 474: 'System Maintaining!',
  64. 475: 'App Version too low, please upgrade!',
  65. 500: 'Internal error!',
  66. 700: 'Upload file error',
  67. 701: 'The file does not exist!',
  68. 711: 'Do not downgrade',
  69. 712: 'Area needs to be consistent',
  70. 713: 'Storage rules cannot be changed during the validity period',
  71. 717: 'Authorization expires',
  72. 800: 'Order does not exist',
  73. 801: 'The refund amount cannot be greater than the order price',
  74. 802: 'The order has been completed and cannot be cancelled',
  75. 804: 'Refund, please do not repeat the operation',
  76. 805: 'Could not refund',
  77. 806: 'The push time is earlier than the current time',
  78. 900: 'There is no information about this version!',
  79. 901: 'Getting URL failure!',
  80. 902: 'No update!',
  81. 903: 'Error filename',
  82. 904: 'Version does not support this feature!',
  83. 906: 'Cause of file operation error',
  84. 907: 'The download file does not exist!',
  85. 910: 'Icloud Insufficient capacity!',
  86. 911: 'No opened Icloud',
  87. 10001: 'Customer number, customer confidentiality error',
  88. 10002: 'Check your configuration: no customer number, customer confidentiality',
  89. 10003: 'The authorization code does not exist. Please reauthorize',
  90. 10004: 'The request method is incorrect. Please contact the developer',
  91. 10005: 'Wrong configuration, wrong customer number',
  92. 10006: 'Configuration error. The path value is incorrect',
  93. 10007: 'This device is not an experience package and cannot be reset',
  94. 10008: 'The user does not have this device and cannot transfer',
  95. 10009: 'The user already owns the device and cannot transfer it',
  96. 10010: 'Devices that are not under the same account cannot be transferred',
  97. 10011: 'Receiving transfer device does not exist and cannot be transferred',
  98. 10012: 'Experience packages cannot be transferred',
  99. 10013: 'Original equipment package has expired and cannot be transferred',
  100. 10014: 'Accept transfer of equipment packages that have not expired and cannot be transferred',
  101. 10015: 'Shared devices cannot be transferred',
  102. 10016: 'The transfer device does not support the AI function and cannot be transferred',
  103. 10017: 'This order cannot be transferred, contact the administrator if needed',
  104. 10018: 'There are exceptions to this order, please contact the administrator',
  105. 10030: 'No purchase of cloud storage',
  106. 10031: 'The cloud storage has expired',
  107. 10032: 'The switched cloud storage package ID cannot be the same as the one in use',
  108. 10033: 'The primary user of the device cannot purchase it',
  109. 10034: 'Non device primary users cannot view cloud storage',
  110. 10035: 'Non device primary users cannot experience cloud storage',
  111. 10036: 'Non device primary users cannot exchange for cloud storage',
  112. 10037: 'Non device primary user cannot transfer device',
  113. 10038: 'Non device primary user cannot transfer packages',
  114. 10039: 'Activation code has been used',
  115. 10040: 'Invalid activation code',
  116. 10041: 'This device has purchased a domestic cloud storage package, '
  117. 'and cannot purchase a foreign cloud storage package',
  118. 10042: 'The device has registered a certificate',
  119. 10043: 'The device does not registered a certificate',
  120. 10044: 'Failed to publish MQTT message',
  121. 10045: 'Already the latest version',
  122. 10046: 'Sorry, users who have activated cloud storage packages do not support logout at the moment, '
  123. 'please contact customer service',
  124. 10047: 'Please delete all devices under your account first',
  125. 10048: 'Subscribe to the failure',
  126. 10049: 'The coupon is not available',
  127. 10050: 'You have subscribed to this package, please do not subscribe again',
  128. 10051: 'Unsubscribe successfully',
  129. 10052: 'Unsubscribe failed',
  130. 10053: 'The AI service is not purchased',
  131. 10054: 'The AI service has expired',
  132. 10055: 'The AI does not recognize any labels',
  133. 10056: 'The device has enabled automatic renewal of cloud storage package and cannot be transferred '
  134. 'for the time being',
  135. 10057: "Can't delete",
  136. 10058: 'Default family cannot be deleted',
  137. 10059: 'Order deactivation failure',
  138. 10060: 'This device has purchased foreign cloud storage package, so it cannot buy domestic '
  139. 'cloud storage package',
  140. 10061: 'Add the limit reached',
  141. 10062: 'This device has experienced the package',
  142. 10063: 'Failed to claim',
  143. 10064: 'If the claim fails, please contact customer service',
  144. 10065: 'The redemption is successful and can be viewed in Settings-4G-My Package',
  145. 10066: 'This code has been redeemed and can be viewed in Settings-4G-My Package',
  146. 10067: 'Invalid redemption code',
  147. 10068: 'This device does not support redemption, please contact customer service',
  148. 10069: 'If the traffic is abnormal, check the data plan or contact customer service',
  149. 10070: 'This device sharing limit has been reached',
  150. 503: 'The operation failed, please try again later',
  151. 10071: 'The successful collection can be viewed in Settings - 4G-My package',
  152. 10072: 'This function has been disabled. Please contact the administrator',
  153. 10073: 'The verification code has been sent, please pay attention to check',
  154. 10074: 'Task queue processing, please try again later',
  155. 10075: 'Email subscription failed',
  156. 10076: 'Failed to add, please contact customer service',
  157. 10077: 'Shopify account not exists!'
  158. }
  159. data_cn = {
  160. 0: '成功',
  161. 5: '请一分钟后再尝试',
  162. 10: res,
  163. 12: '非设备主用户',
  164. 13: '时间戳token校验失败',
  165. 14: '设备不属于您',
  166. 15: '设备已被绑定',
  167. 16: '微信已被绑定,请使用微信登录并解绑',
  168. 17: '未绑定邮箱或者手机登录方式',
  169. 18: '用户未登录',
  170. 44: '系统错误!无法发送电子邮件',
  171. 48: '系统对象错误',
  172. 89: '已发验证码,请检测或10分钟后重新获取。',
  173. 90: '请检测或1分钟后重新获取。',
  174. 91: '该手机今日获取短信验证码已达上限。',
  175. 92: '未获取验证或验证码过期。',
  176. 99: '邮箱不存在!',
  177. 100: '手机格式错误!',
  178. 101: '手机已存在!',
  179. 102: '手机不存在!',
  180. 103: '邮箱已存在!',
  181. 104: '账户不存在!',
  182. 105: '邮箱格式错误!',
  183. 106: '头像违规!',
  184. 107: '用户名格式不符合!',
  185. 108: '用户昵称违规!',
  186. 109: '支持6-16位的数字、英文字母、英文符号',
  187. 110: '用户未激活!',
  188. 111: '密码不正确!',
  189. 112: '未开通指纹登录',
  190. 119: '二维码过期',
  191. 120: '验证码过期',
  192. 121: '验证码错了!',
  193. 173: '数据不存在!',
  194. 174: '数据已存在!',
  195. 176: '删除错误',
  196. 177: '更新错误',
  197. 178: '增加错误',
  198. 179: '名称不能重复',
  199. 180: '智能按钮场景触发条件不能重复',
  200. 181: '该网关最多只能绑定3个智能按钮',
  201. 182: '场景生效时间冲突',
  202. 183: '该用户未绑定邮箱',
  203. 184: '图片违规',
  204. 201: '最多只能添加3条自定义语音',
  205. 306: '链接已超过有效期!',
  206. 309: '请重新登录!',
  207. 310: '检测到您的账号在另一台设备上登录,如非本人操作,请立即修改密码!',
  208. 404: '您没有访问的权限!',
  209. 414: '请确认请求url!',
  210. 424: '数据库错误!',
  211. 444: '参数错误!',
  212. 474: '系统维护中!',
  213. 475: '版本过低,请升级程序!',
  214. 500: '内部错误!',
  215. 700: '上传文件错误',
  216. 701: '文件不存在',
  217. 711: '不可降级',
  218. 712: '区域不一致',
  219. 713: '有效期内不可更改存储规则',
  220. 717: '授权过期',
  221. 800: '订单不存在',
  222. 801: '退款金额不能大于订单价格',
  223. 802: '订单已完成,不能撤销',
  224. 804: '订单已退款,请勿重复操作',
  225. 805: '无法退款',
  226. 806: '推送时间早于当前时间',
  227. 900: '版本信息不存在',
  228. 901: '获取链接失败',
  229. 902: '无更新!',
  230. 903: '文件名不符合!',
  231. 904: '版本不支持本功能!',
  232. 906: '文件操作错误',
  233. 907: '文件不存在!',
  234. 910: '云盘容量不足!',
  235. 911: '未开通云盘!',
  236. 10001: '客户编号,客户机密错误',
  237. 10002: '检查您的配置:没有客户编号,客户机密',
  238. 10003: '授权码不存在,请重新授权',
  239. 10004: '请求方法不正确。请联系开发者',
  240. 10005: '配置错误,客户编号这个值是错误的',
  241. 10006: '配置错误,路径这个值是错误的',
  242. 10007: '此设备不是体验套餐,无法重置',
  243. 10008: '用户没有此设备,无法转移',
  244. 10009: '用户已拥有此设备,无法转移',
  245. 10010: '不是同一账户下的设备,无法转移',
  246. 10011: '接受转移设备不存在,无法转移',
  247. 10012: '体验套餐无法转移',
  248. 10013: '原设备套餐已过期,无法转移',
  249. 10014: '接受转移设备套餐未过期,无法转移',
  250. 10015: '分享的设备无法转移',
  251. 10016: '转入设备不支持AI功能,无法转移',
  252. 10017: '此订单无法转移,有需要可联系管理员',
  253. 10018: '此订单有异常,请联系管理员',
  254. 10030: '未购买云存',
  255. 10031: '云存已过期',
  256. 10032: '切换的云存套餐ID不能与正在使用中的相同',
  257. 10033: '非设备主用户无法购买',
  258. 10034: '非设备主用户无法查看云存',
  259. 10035: '非设备主用户无法体验云存',
  260. 10036: '非设备主用户无法兑换云存',
  261. 10037: '非设备主用户无法转移设备',
  262. 10038: '非设备主用户无法转移套餐',
  263. 10039: '激活码已被使用过',
  264. 10040: '无效激活码',
  265. 10041: '此设备已购买过国内云存套餐,无法购买国外云存套餐',
  266. 10042: '此设备已注册证书',
  267. 10043: '此设备没有注册证书',
  268. 10044: '发布MQTT消息失败',
  269. 10045: '当前为最新版本',
  270. 10046: '已开通云存的用户,暂不支持注销,请联系客服',
  271. 10047: '请先删除您当前帐户下的所有设备',
  272. 10048: '订阅失败',
  273. 10049: '该优惠券不可用',
  274. 10050: '您已订阅过此套餐,请不要重复订阅',
  275. 10051: '已取消订阅',
  276. 10052: '订阅取消失败',
  277. 10053: '未购买AI服务',
  278. 10054: 'AI服务已过期',
  279. 10055: 'AI没有识别到任何标签',
  280. 10056: '该设备已开通云存套餐自动续费,暂时无法转移',
  281. 10057: '不能删除',
  282. 10058: '默认家庭不能删除',
  283. 10059: '订单停用失败',
  284. 10060: '此设备已购买过国外云存套餐,无法购买国内云存套餐',
  285. 10061: '添加已达到上限',
  286. 10062: '此设备已体验过套餐',
  287. 10063: '领取失败',
  288. 10064: '领取失败,请联系客服',
  289. 10065: '\t兑换成功\n可在设置-4G-我的套餐中查看',
  290. 10066: '\t此码已兑换\n可在设置-4G-我的套餐中查看',
  291. 10067: '无效兑换码',
  292. 10068: '兑换失败,请联系客服',
  293. 10069: '流量异常,请查看流量套餐情况或联系客服',
  294. 10070: '此设备分享已达上限',
  295. 503: '操作失败,请稍后重试',
  296. 10071: '\t领取成功\n可在设置-4G-我的套餐中查看',
  297. 10072: '该功能已停用,请联系管理员',
  298. 10073: '验证码已发送,请注意查收',
  299. 10074: '任务队列处理中,请稍后再试',
  300. 10075: '邮件订阅失败',
  301. 10076: '添加失败,请联系客服',
  302. 10077: 'shopify账号不存在'
  303. }
  304. msg = data_cn if self.lang == 'cn' or self.lang == 'zh-Hans' or self.lang == 'zh-Hant' else data_en
  305. reason = msg.get(code)
  306. if reason is None:
  307. reason = 'code不存在'
  308. if self.returntype == 'pc':
  309. return {'code': code, 'msg': reason, 'data': res, 'error_code': code}
  310. return {'result_code': code, 'reason': reason, 'result': res, 'error_code': code}
  311. def formal(self, code, res=None):
  312. formal_data = self.data(code, res)
  313. return json.dumps(formal_data, ensure_ascii=False)
  314. def json(self, code, res=None):
  315. result = self.formal(code, res)
  316. return HttpResponse(result)