minigram.py 3.8 KB

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