minigram.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. PQSP4 = {
  6. "avatar": "https://rescdn.yishihui.com/0temp/pqsp.png",
  7. "id": "wxbdd2a2e93d9a6e25",
  8. "name": "票圈视频"
  9. }
  10. VLOG0 = {
  11. "avatar": "https://rescdn.yishihui.com/0temp/logo.png",
  12. "id": "wx89e7eb06478361d7",
  13. "name": "票圈 l 3亿人喜欢的视频平台"
  14. }
  15. class Minigram(object):
  16. """
  17. 小程序卡片
  18. """
  19. def __init__(self, params, config):
  20. self.gh_id = None
  21. self.params = params
  22. self.business_type = None
  23. self.mini_code = None
  24. self.trace_id = None
  25. self.config = config
  26. def check_params(self):
  27. """
  28. 校验参数
  29. :return:
  30. """
  31. try:
  32. self.business_type = self.params['businessType']
  33. self.mini_code = self.params['miniCode']
  34. self.trace_id = self.params['traceId']
  35. self.gh_id = self.params.get('ghId', None)
  36. return None
  37. except Exception as e:
  38. response = {
  39. "status": "fail",
  40. "code": 1,
  41. "message": str(e),
  42. "info": "params check error"
  43. }
  44. return response
  45. def choose_minigram(self):
  46. """
  47. 分配小程序卡片
  48. :return:
  49. """
  50. pq_gh_id_list = json.loads(self.config.get_config_value('ghIdInPqVideo'))
  51. if self.gh_id in set(pq_gh_id_list):
  52. minigram = PQSP4
  53. else:
  54. minigram = VLOG0
  55. response = {
  56. "programAvatar": minigram['avatar'],
  57. "programId": minigram['id'],
  58. "programName": minigram['name'],
  59. "trace_id": self.trace_id
  60. }
  61. return response
  62. async def deal(self):
  63. """
  64. :return:
  65. """
  66. return self.check_params() if self.check_params() else self.choose_minigram()