def POST(self): try: tid_value = web.input()['tid'] except KeyError: return web.BadRequest() try: team_id = cfg['TEAM_ID_DICT'][tid_value.upper()] except KeyError: return web.Unauthorized() if len(web.data()) == 0: return web.BadRequest() data = simplejson.loads(web.data()) # json validation good, errors = IssueValidator().validate(data) if not good: return errors r = requests.post(''.join(['http://', cfg['REMOTE_HOST'], '/pp']), data=simplejson.dumps({'tid': str(team_id), 'iid': data['ID']})) if r.status_code != 200: print 'Call remote server failed...' print r.text api = WxApi(cfg['CORP_ID'], cfg['SECRET']) api.send_text(self.build_msg(data), team_id, 0, '@all') return web.OK('ok')
def POST(self): try: tid_value = web.input()['tid'] except KeyError: return web.BadRequest() try: team_id = cfg['TEAM_ID_DICT'][tid_value.upper()] except KeyError: return web.Unauthorized() if len(web.data()) == 0: return web.BadRequest() api = WxApi(cfg['CORP_ID'], cfg['SECRET']) api.send_text(web.data(), team_id, 0, '@all') return web.OK('ok')
def send_message(touser=None, content=None, safe="0", msg_type='text', toparty=None, totag=None, qy=False, **kwargs): if qy: secret = get_config('wework') safe = None else: secret = get_config('wechat') CORPID, CORPSECRET, APPID = secret.split(':') agentid = int(APPID) api = WxApi(CORPID, CORPSECRET) ret, api_error = api.send_message( msg_type=msg_type, content=content, agentid=agentid, # APP ID safe=safe, # 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送 touser=touser, # 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 toparty=toparty, # 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数 totag=totag, ) if api_error: logger.error( ('send_message({touser}, {content}) get {err_code}, {err_msg}'. format(touser=touser, content=content, err_code=api_error.code, err_msg=api_error.message))) return ret, api_error
def send_to_all(req, msg): api = WxApi(cfg["CORP_ID"], cfg["SECRET"]) api.send_text(msg, req.AgentID, "0", "@all") return WxEmptyResponse()
def send_to_all(req, msg): api = WxApi(cfg['CORP_ID'], cfg['SECRET']) api.send_text(msg, req.AgentID, '0', '@all') return WxEmptyResponse()