minigram.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. XYMHFQDD_27 = {
  16. "avatar": "https://rescdn.yishihui.com/0temp/xymhfqdd.png",
  17. "id": "wx7187c217efef24a7",
  18. "name": "幸运美好福气多多"
  19. }
  20. # 27小程序候选账号 id
  21. 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'}
  22. class Minigram(object):
  23. """
  24. 小程序卡片
  25. """
  26. def __init__(self, params, config):
  27. self.gh_id = None
  28. self.params = params
  29. self.business_type = None
  30. self.mini_code = None
  31. self.trace_id = None
  32. self.config = config
  33. def check_params(self):
  34. """
  35. 校验参数
  36. :return:
  37. """
  38. try:
  39. self.business_type = self.params['businessType']
  40. self.mini_code = self.params['miniCode']
  41. self.trace_id = self.params['traceId']
  42. self.gh_id = self.params.get('ghId', None)
  43. return None
  44. except Exception as e:
  45. response = {
  46. "status": "fail",
  47. "code": 1,
  48. "message": str(e),
  49. "info": "params check error"
  50. }
  51. return response
  52. def choose_minigram(self):
  53. """
  54. 分配小程序卡片
  55. :return:
  56. """
  57. pq_gh_id_list = json.loads(self.config.get_config_value('ghIdInPqVideo'))
  58. # if self.gh_id in EXPERIMENT_27_GH_ID_SET:
  59. # minigram = XYMHFQDD_27
  60. if self.gh_id in set(pq_gh_id_list):
  61. minigram = PQSP4
  62. else:
  63. minigram = VLOG0
  64. response = {
  65. "programAvatar": minigram['avatar'],
  66. "programId": minigram['id'],
  67. "programName": minigram['name'],
  68. "trace_id": self.trace_id
  69. }
  70. return response
  71. async def deal(self):
  72. """
  73. :return:
  74. """
  75. return self.check_params() if self.check_params() else self.choose_minigram()