""" @author: luojunhui """ import json PQSP4 = { "avatar": "https://rescdn.yishihui.com/0temp/pqsp.png", "id": "wxbdd2a2e93d9a6e25", "name": "票圈视频" } VLOG0 = { "avatar": "https://rescdn.yishihui.com/0temp/logo.png", "id": "wx89e7eb06478361d7", "name": "票圈 l 3亿人喜欢的视频平台" } class Minigram(object): """ 小程序卡片 """ def __init__(self, params, config): self.gh_id = None self.params = params self.business_type = None self.mini_code = None self.trace_id = None self.config = config def check_params(self): """ 校验参数 :return: """ try: self.business_type = self.params['businessType'] self.mini_code = self.params['miniCode'] self.trace_id = self.params['traceId'] self.gh_id = self.params.get('ghId', None) return None except Exception as e: response = { "status": "fail", "code": 1, "message": str(e), "info": "params check error" } return response def choose_minigram(self): """ 分配小程序卡片 :return: """ pq_gh_id_list = json.loads(self.config.get_config_value('ghIdInPqVideo')) if self.gh_id in set(pq_gh_id_list): minigram = PQSP4 else: minigram = VLOG0 response = { "programAvatar": minigram['avatar'], "programId": minigram['id'], "programName": minigram['name'], "trace_id": self.trace_id } return response async def deal(self): """ :return: """ return self.check_params() if self.check_params() else self.choose_minigram()