minigram.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. """
  2. @author: luojunhui
  3. """
  4. from applications.functions.forward import forward_requests
  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. PQSP_GHID = {
  16. "gh_2ad5072e7a76",
  17. "gh_57c9e8babea7",
  18. "gh_a61d7ae2e594",
  19. "gh_2fe4c2f7d571",
  20. "gh_d8c215687f02",
  21. "gh_749271f1ccd5",
  22. "gh_617684416aec",
  23. "gh_a221d1a952aa",
  24. "gh_ec42d1027ba5",
  25. "gh_e3a8e14013cd",
  26. "gh_9ee8fc75c07f",
  27. "gh_0e4fd9e88386",
  28. "gh_2e8ae0384787",
  29. "gh_7c66e0dbd2cf",
  30. "gh_755225d8ede5",
  31. "gh_92da3c574f82",
  32. "gh_31e523f45168",
  33. "gh_df59c5e42954",
  34. "gh_6d3aa9d13402",
  35. "gh_810a439f320a",
  36. "gh_2e0c4609839f",
  37. "gh_f1122b34f1f3",
  38. "gh_da44c409ec0f",
  39. "gh_2e615fa75ffb",
  40. "gh_d32fe439b098",
  41. "gh_d7fa1998b4e1",
  42. "gh_abc6794e6996",
  43. "gh_c43c01198e6a",
  44. "gh_a447c30961b7",
  45. "gh_dc2da0611278",
  46. "gh_156c66ac3e37",
  47. "gh_ddf6ec0104d0",
  48. "gh_39218d3a3ec1",
  49. "gh_98ec0ffe69b3",
  50. "gh_243829b5ff02",
  51. "gh_03d32e83122f",
  52. "gh_a1c2771f8020",
  53. "gh_4f6bfd731ac8",
  54. "gh_9360765baf6a",
  55. "gh_1686250f15b6",
  56. "gh_6e977e8cd40d",
  57. "gh_dfa7599c181f"
  58. }
  59. class Minigram(object):
  60. """
  61. 小程序卡片
  62. """
  63. NEW_STRATEGY = "strategy_v2"
  64. def __init__(self, params):
  65. self.gh_id = None
  66. self.strategy = None
  67. self.params = params
  68. self.business_type = None
  69. self.mini_code = None
  70. self.trace_id = None
  71. def check_params(self):
  72. """
  73. 校验参数
  74. :return:
  75. """
  76. try:
  77. self.business_type = self.params['businessType']
  78. self.mini_code = self.params['miniCode']
  79. self.trace_id = self.params['traceId']
  80. self.strategy = self.params.get('strategy')
  81. self.gh_id = self.params.get('ghId', None)
  82. if not self.strategy:
  83. self.strategy = "strategy_v1"
  84. return None
  85. except Exception as e:
  86. response = {
  87. "status": "fail",
  88. "code": 1,
  89. "message": str(e),
  90. "info": "params check error"
  91. }
  92. return response
  93. def choose_minigram(self):
  94. """
  95. 分配小程序卡片
  96. :return:
  97. """
  98. if self.gh_id in PQSP_GHID:
  99. minigram = PQSP4
  100. else:
  101. minigram = VLOG0
  102. response = {
  103. "programAvatar": minigram['avatar'],
  104. "programId": minigram['id'],
  105. "programName": minigram['name'],
  106. "trace_id": self.trace_id
  107. }
  108. return response
  109. async def deal(self):
  110. """
  111. :return:
  112. """
  113. params_error = self.check_params()
  114. if params_error:
  115. return params_error
  116. else:
  117. if self.strategy == self.NEW_STRATEGY:
  118. response = await forward_requests(
  119. params=self.params,
  120. api="choose_minigram"
  121. )
  122. return response
  123. else:
  124. return self.choose_minigram()