def checkLoginForbid(): ''' 检查是否被禁止登陆 ''' from tyframework.context import TyContext try: userId = 0 try: if TyContext.RunHttp.is_current_http(): userId = TyContext.RunHttp.getRequestParamInt('userId', 0) else: msg = TyContext.getTasklet().getMsg() userId = msg.getParam('userId') except: pass clientId, _ = TyContext.BiUtils.getClientIdNum(None, None, 9998, userId) forbid = sdkconf.getFirstLoginForbid(clientId) if forbid: mo = MsgPack() mo.setResult('code', 10) mo.setResult('info', sdkconf.getFirstLoginForbidMsg()) return mo except: TyContext.ftlog.error() return False
def http_request(cls, url, params, ispost=False): from urllib import urlencode method = 'GET' params_data = '' if ispost: method = 'POST' params_data = urlencode(params) else: url = url + '?' + urlencode(params) TyContext.ftlog.debug('friend http_request params=', params_data, 'url=', url) try: from twisted.web import client result = TyContext.getTasklet().waitForPage( url, params_data, method) TyContext.ftlog.debug('friend http_request reuslt=', result) return result except Exception as e: TyContext.ftlog.error('friend http_request error', e, 'url', url)
def __handle_action_exec_hotfix_py__(self, mi, mo): """ 用 execfile 动态执行 udp 消息中指定的脚本文件,来实现动态的调试、 更新、 bug修复、数据调整等 """ pyfile = mi.getParam('pyfile') TyContext.ftlog.info('_server_hot_cmd_ exec_hotfix_py :', pyfile) execfile_result = {} execfile_globals = { 'TyContext': TyContext, 'exec_tasklet': TyContext.getTasklet(), 'exec_result': execfile_result, } try: execfile(pyfile, execfile_globals, execfile_globals) mo.setResult('execfile_result', execfile_result) mo.setResult('ok', 1) except: mo.setError(1, TyContext.ftlog.format_exc()) TyContext.ftlog.exception()
def queryHttpSsl(httpsurl, postdata, certificate_file, privatekey_file): ''' 示例: certfile = sslhttp.getResourcePath('./cacert_weixin/apiclient_cert.pem') keyfile = sslhttp.getResourcePath('./cacert_weixin/apiclient_key.pem') httpsurl = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack' postdata = ..... res = sslhttp.queryHttpSsl(httpsurl, postdata, certfile, keyfile) print res ''' contextFactory = WebClientContextFactory(certificate_file, privatekey_file) headers_ = {'Content-type': 'application/x-www-form-urlencoded'} tasklet = TyContext.getTasklet() tasklet._report_wait_prep_(httpsurl) d = client.getPage(httpsurl, method="POST", headers=headers_, postdata=postdata, contextFactory=contextFactory) r = tasklet._wait_for_deferred_(d, httpsurl[:60]) return r