minigram.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """
  2. @author: luojunhui
  3. """
  4. minigram_map = {
  5. 1: {
  6. 25: {
  7. "avatar": "https://rescdn.yishihui.com/0temp/pqsp.png",
  8. "id": "wxbdd2a2e93d9a6e25",
  9. "name": "票圈视频",
  10. "index": 25
  11. },
  12. 29: {
  13. "avatar": "https://rescdn.yishihui.com/0temp/pqsp.png",
  14. "id": "wxbdd2a2e93d9a6e25",
  15. "name": "票圈视频",
  16. "index": 29
  17. },
  18. 31: {
  19. "avatar": "https://rescdn.yishihui.com/0temp/pqsp.png",
  20. "id": "wxbdd2a2e93d9a6e25",
  21. "name": "票圈视频",
  22. "index": 31
  23. }
  24. },
  25. 2: {
  26. 36: {
  27. "avatar": "https://rescdn.yishihui.com/0temp/pqsp.png",
  28. "id": "wxbdd2a2e93d9a6e25",
  29. "name": "票圈视频",
  30. "index": 36
  31. },
  32. 33: {
  33. "avatar": "https://rescdn.yishihui.com/0temp/pqsp.png",
  34. "id": "wxbdd2a2e93d9a6e25",
  35. "name": "票圈视频",
  36. "index": 33
  37. }
  38. },
  39. 3: {
  40. 27: {
  41. "avatar": "https://rescdn.yishihui.com/0temp/xymhfqdd.png",
  42. "id": "wx7187c217efef24a7",
  43. "name": "幸运美好福气多多",
  44. "index": 27
  45. }
  46. }
  47. }
  48. class Minigram(object):
  49. """
  50. 小程序卡片
  51. """
  52. def __init__(self, params):
  53. self.params = params
  54. self.business_type = None
  55. self.mini_code = None
  56. self.trace_id = None
  57. def check_params(self):
  58. """
  59. 校验参数
  60. :return:
  61. """
  62. try:
  63. self.business_type = self.params['businessType']
  64. self.mini_code = self.params['miniCode']
  65. self.trace_id = self.params['traceId']
  66. return None
  67. except Exception as e:
  68. response = {
  69. "status": "fail",
  70. "code": 1,
  71. "message": str(e),
  72. "info": "params check error"
  73. }
  74. return response
  75. def choose_minigram(self):
  76. """
  77. 分配小程序卡片
  78. :return:
  79. """
  80. try:
  81. minigram = minigram_map.get(self.business_type).get(self.mini_code)
  82. response = {
  83. "programAvatar": minigram['avatar'],
  84. "programId": minigram['id'],
  85. "programName": minigram['name'],
  86. "trace_id": self.trace_id
  87. }
  88. except Exception as e:
  89. response = {
  90. "error": "invalid params",
  91. "msg": str(e)
  92. }
  93. return response
  94. async def deal(self):
  95. """
  96. :return:
  97. """
  98. return self.check_params() if self.check_params() else self.choose_minigram()