def get(self, access_token, user_name_ls=None): """ http get 请求 :param access_token:访问码 :param user_name_ls: 用户名列表 :return:[user_dic,,,,] """ user_name_ls = ujson.loads(user_name_ls) if not access_token\ or not user_name_ls: return {'result': error_code.ERROR_PARAMS_ERROR} if not TokenMgr.check_expire_access_token(access_token): return {'result': error_code.ERROR_ACCESS_TOKEN_ERROR} result = {'result': error_code.ERROR_SUCCESS} connects = ServiceMgrCacher().get_connections(US_REGISTER_DA, RT_HASH_RING, user_name_ls) for connect, name_ls in connects.items(): params = {"user_name_ls": name_ls} user_info_ls = user_select(connect, **params) [user_dic.__setitem__('device_type', get_device_type(ParamCacher().sm_rpc, user_dic['device_type'])) for user_dic in user_info_ls if user_dic['device_type']] result.setdefault('user_info_ls', []).extend(user_info_ls) return result
def get(self, verify_code, user_name, password, type, device_type="", des="", param_sign=None, proxy_sign=None): """ http get 请求 :param verify_code: 验证码 :param user_name: 用户名 :param password: 密码 :param type: 用户类型 :param device_type: 设备类型,对应设备用户 :param des: 描述 :param param_sign:程序签名 :param proxy_sign: 代理签名 :return: {} """ if not user_name\ or not password\ or not type\ or not int(type) in enum.USER_TYPE_LS\ or not device_type in get_device_type(ParamCacher().sm_rpc).keys() if int(type) == enum.DEVICE_USER else False: return {'result': error_code.ERROR_PARAMS_ERROR} # 如果有param_sign,可使用验证param_sign越过验证码 is_privilege = Signer().check_sign(param_sign, verify_code, user_name, password, type, des) \ if param_sign \ else False # 不使用验证码判斷 if type and int(type) in enum.NOT_VERIFY_CODE_USER_LS: is_privilege = True if not is_privilege: if not cookie.check_cookie(self, "register_verify_code", verify_code): logger.error("RegisterHandle check_cookie failed!!!, verify_code:%s\n,param_sign:%s\n, HTTP_SGIN:%s" % (verify_code, param_sign, HTTP_SIGN)) return {'result': error_code.ERROR_VERIFY_CODE_ERROR} rgst_da_tcp = ServiceMgrCacher().get_connection(US_REGISTER_DA, RT_HASH_RING, [user_name]) if get_user_info(rgst_da_tcp, user_name): return {'result': error_code.ERROR_USER_NAME_EXIST} new_jid_dic = UserService().new_jid(user_name, password) params = {"user_name": user_name, "password": password, "des": des, "jid": new_jid_dic['jid'], "jid_pwd": new_jid_dic['password'], "type": type, "device_type": device_type} result = rgst_da_tcp.fetch_async("user_insert", ujson.dumps(params)) if ArgumentParser().args.use_sign: result['sign'] = proxy_sign if proxy_sign else HTTP_SIGN return result
def bridge_jid(): """ get bridge service jid :return: """ bridge_setting = ServiceMgrCacher.find_service(US_BRIDGE) return bridge_setting['jid']
def get(self, verify_code, user_name, password, type, param_sign=None, proxy_sign=None): """ http 请求接口 :param verify_code: 验证码 :param user_name: 用户名 :param password: 密码 :param type: 用户类型 :param param_sign: 程序签名 :param proxy_sign: 代理提供签名 :return:{} """ if not user_name\ or not password: return {'result': error_code.ERROR_PARAMS_ERROR} is_privilege = Signer().check_sign(param_sign, verify_code, user_name, password) \ if param_sign \ else False # 不使用验证码判斷 if type and int(type) in enum.NOT_VERIFY_CODE_USER_LS: is_privilege = True if not is_privilege: if not cookie.check_cookie(self, "verify_code", verify_code): logger.error("CancelHandle check_cookie failed!!!, verify_code:%s\n,param_sign:%s\n, HTTP_SGIN:%s" % (verify_code, param_sign, HTTP_SIGN)) return {'result': error_code.ERROR_VERIFY_CODE_ERROR} rgst_da_tcp = ServiceMgrCacher().get_connection(US_REGISTER_DA, RT_HASH_RING, user_name) user_info = get_user_info(rgst_da_tcp, user_name) if not user_info or user_info['password'] != password: return {'result': error_code.ERROR_USER_NAME_OR_PASSWORD_ERROR} UserService().del_user(user_name) params = {'user_name_ls': [user_name]} result = rgst_da_tcp.fetch_async("user_delete", ujson.dumps(params)) if ArgumentParser().args.use_sign: result['sign'] = proxy_sign if proxy_sign else HTTP_SIGN return result
def get_users(self, access_token, user_name_ls): """ 获取用户信息 :param access_token: 访问码 :param user_name_ls: 用户名列表 :return:[user_dic,,,,] """ if not access_token\ or not user_name_ls: return {'result': error_code.ERROR_PARAMS_ERROR} if not TokenMgr.check_expire_access_token(access_token): return {'result': error_code.ERROR_ACCESS_TOKEN_ERROR} result = {'result': error_code.ERROR_SUCCESS} connects = ServiceMgrCacher().get_connections(US_REGISTER_DA, RT_HASH_RING, user_name_ls) for connect, name_ls in connects.items(): params = {"user_name_ls": name_ls} user_info_ls = result.setdefault('user_info_ls', []) user_info_ls.extend(user_select(connect, **params)) return result
def post(self, mobile, code, seconds, param_sign, token): """ :param mobile: 手机号码 :param code: 验证码 :param seconds: 有效时间 :param param_sign: 参数验证 :param token:令牌 :return: """ if not valid_phone(mobile): return {'result': 'FAIL', 'reason': 'INVALID_MOBILE'} checked = False if param_sign and not Signer().check_sign(param_sign, mobile, code, seconds): checked = True if not checked and token: register_setting = ServiceMgrCacher.find_service(US_REGISTER) if not register_setting: return tcp_client = TcpRpcClient(str(register_setting['ip']), register_setting['port']['tcp']) result = tcp_client.fetch_async('verify_access_token', token) if result['result'] == error_code.ERROR_SUCCESS: checked = True if not checked: return {'result': 'FAIL', 'reason': 'INVALID_VERIFICATION'} http_client = HttpRpcClient() headers = { 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' } msg = { 'apiKey': API_KEY, 'appId': APP_ID, 'templateId': TEMPLATE['GENERAL'], 'mobile': mobile, 'param': '%s,%s' % (code, seconds2minutes(seconds)) } body = ujson.dumps(msg) result = ujson.loads(http_client.fetch_async(URL, headers, body)) return result
#!/usr/bin/python2.7 # coding=utf-8 """ Created on 2015-6-4 @author: Jay """ from utils.service_control.cacher import ServiceMgrCacher from utils.service_control.setting import ST_MMM_DA from utils.service_control.setting import PT_HTTPS # register RgstTcpRpc = ServiceMgrCacher().get_connection(ST_MMM_DA) RgstHttpRpc = ServiceMgrCacher().get_connection(ST_MMM_DA, protocol=PT_HTTPS)
@author: Jay """ from utils.service_control.cacher import ServiceMgrCacher from lib.common import ST_REGISTER, ST_BRIDGE, ST_PANDORA, ST_HTTPS_PROXY, ST_MXADAP from utils.service_control.setting import PT_HTTP, PT_HTTPS, RT_CPU_USAGE_RDM from lib.user import LoginGetToken, DUserName2, DPassword2 from utils.comm_func import get_mxadap_host_flag # register RgstTcpRpc = ServiceMgrCacher().get_connection(ST_REGISTER) RgstHttpRpc = ServiceMgrCacher().get_connection(ST_REGISTER, protocol=PT_HTTPS) # bridge bridge_setting = ServiceMgrCacher.find_service(ST_BRIDGE, RT_CPU_USAGE_RDM, 1) BrgTcpRpcClt = ServiceMgrCacher().get_connection(ST_BRIDGE) BrgHttpRpcClt = ServiceMgrCacher().get_connection(ST_BRIDGE, protocol=PT_HTTPS) # pandora PandoraHttpClt = ServiceMgrCacher().get_connection(ST_PANDORA, protocol=PT_HTTP) # https_proxy HttpsProxyHttpClt = ServiceMgrCacher().get_connection(ST_HTTPS_PROXY, protocol=PT_HTTP) # mxadap mxadap_setting = ServiceMgrCacher.find_service(ST_MXADAP, RT_CPU_USAGE_RDM, 1) mxadap_port = mxadap_setting['port'] http_port = mxadap_port.get('https') if 'https' in mxadap_port else mxadap_port.get('http') mxadap_host = get_mxadap_host_flag(mxadap_setting['ip'], http_port, mxadap_setting['port']['tcp']) if mxadap_setting else None
#!/usr/bin/python2.7 # coding=utf-8 """ Created on 2015-4-28 @author: Jay """ from utils.route import route from utils.network.http import HttpRpcHandler from utils.wapper.web import web_adaptor from utils.service_control.setting import PT_HTTPS, PT_HTTP from utils.service_control.cacher import ServiceMgrCacher from utils.interfaces.mmm_da.http_rpc import apply_help_paid from mmm_da.setting import SERVICE_TYPE as ST_MMM_DA MMMDAHttpRpcClt = ServiceMgrCacher().get_connection(ST_MMM_DA, protocol=PT_HTTPS) if not MMMDAHttpRpcClt: MMMDAHttpRpcClt = ServiceMgrCacher().get_connection(ST_MMM_DA, protocol=PT_HTTP) assert MMMDAHttpRpcClt @route(r'/apply_help_pay', name='apply_help_pay') class ApplyHelpPayHandler(HttpRpcHandler): @web_adaptor() def post(self, id, access_token, apply_sorder, pay_msg="", file="",
def redirect_webcontroller_wechat_device_ls(http_handler, *args, **kwargs): url = "?username=%s@password=%s" % (urllib.quote(kwargs["openid"]), WECHAT_PASSWORD) logger.info("redirect_webcontroller_wechat_device_ls, redirect url:%s args:%s kwargs:%s" % (url, args, kwargs)) return ServiceMgrCacher.tp_redirect(http_handler, "tp_device_front", url)