Beispiel #1
0
def backstage_push(request):
    model_id = request.GET.get('Modelid', 0)
    serv_id = int(request.GET.get('Servid', 0))
    push_id = int(request.GET.get('Pushid', 0))
    is_local = int(request.GET.get('is_local', 0))  #本地同步标识

    syncMod = _MODULES.get(str(model_id))  #根据传入的model_id获取数据模型

    if not syncMod or not serv_id or not push_id:
        return HttpResponse('{"code": 1, "msg": "缺少请求所需参数"}')

    serv_info = get_backstage_data(bid=serv_id)

    serv_url = serv_info['url']
    if not serv_url:
        return HttpResponse('{"code": 1, "msg": "访问地址不存在"}')

    if is_local:
        #从指定后台获取数据同步至本地
        post_datas = http_post(
            serv_url + 'sync/backstage/remotedb',
            urllib.urlencode({
                "Modelid": model_id,
                "Pushid": push_id
            }))
        sync_mods = deserialize('json', post_datas)
        for m in sync_mods:
            m.save()
        result = '{"code": 0}'
    else:
        #本地数据推送至其他后台
        push_db = syncMod.objects.get(id=push_id)  #获取推送数据
        post_datas = pickle.dumps(push_db)

        hashObj = md5()
        hashObj.update(post_datas + model_id + _AUTHKEY)

        #pickle序列化模型和数据

        post_params = urllib.urlencode({
            'model': model_id,
            'datas': post_datas,
            'sign': hashObj.hexdigest()
        })

        # serv_url = 'http://127.0.0.1:90/sync/backstage/dosync'  #测试硬编码
        try:
            result = http_post(serv_url + 'sync/backstage/dosync',
                               post_params,
                               timeout_param=60)
        except Exception, e:
            return HttpResponse('{"code": 1, "msg": "http_post: %s"}' % e)
Beispiel #2
0
def server_list_cn(request):
    ios_interface_url = 'http://ios.server.fytxonline.com/interface/server_list?method=server_list&unixtime=1395300340&sign=16a94d89d641f5b89e11b6445fa69eb9'
    cn_server_list = server_list(request, True)
    ios_server_list = []
    try:
        _r = http_post(ios_interface_url)
        if _r:
            ios_server_list = json.loads(_r)
        cn_server_list += ios_server_list
    except Exception, e:
        pass
Beispiel #3
0
def backstage_list(request):
    form_operation = request.method
    operation_info = getattr(request, form_operation, None)
    model_id = None
    backs_id = None
    if operation_info:
        error_msg = ''
        model_id = operation_info.get('Modelid', '')
        backs_id = operation_info.get('Servid', '')  #接收到字符串形式的若干id值
        is_remote = int(operation_info.get('is_remote', 0))  #远程获取其他后台数据标识
        db_list = None
        if is_remote:
            backsData = get_backstage_data(bid=backs_id)
            back_url = backsData['url'] + 'sync/backstage/'
            try:
                response = http_post(back_url,
                                     urllib.urlencode({
                                         "Modelid": model_id,
                                         "Servid": backs_id
                                     }),
                                     timeout_param=60)
                return HttpResponse(response)
            except:
                error_msg = "请求失败."
        else:
            model = _MODULES.get(model_id)
            if model_id:
                db_list = model.objects.using('read').all().order_by('-id')
            else:
                error_msg = "请求失败."

        return render_to_response('log/sync_backstage_push.html', {
            'db_list': db_list,
            'error': error_msg
        })

    serv_list = get_backstage_data()

    model_list = {}
    for k, v in _MODULES.iteritems():
        model_list[k] = v._meta.db_table

    results = {}
    results['model_id'] = model_id
    results['backs_id'] = backs_id
    results['serv_list'] = serv_list
    results['model_list'] = model_list

    return render_to_response("log/sync_backstage_list.html", results)
def register_gfan(username, password, mail):
    from tea import encrypt
    channel_id = 86
    app_key = 'fengyunanghu218&'
    post_url = 'http://api.gfan.com/uc1/common/register'
    post_data = u'<request><username>%s</username><password>%s</password><email>%s</email></request>' % (username, password, mail)
    post_data = post_data.encode('utf-8') #map(ord, post_data)
    app_key = app_key.encode('utf-8') #map(ord, app_key)
    #print(post_data,app_key)
    post_data = base64.encodestring(encrypt(post_data, app_key))

    user_agent = 'channelID=%d' % channel_id
    result = http_post(post_url, post_data, 'text', user_agent)
    print(result)
    link_key = 0
    if result != '':
        xml_dom = minidom.parseString(result)
        xml_root = xml_dom.documentElement
        link_key = xml_root.getElementsByTagName('uid')[0].toxml().replace('<uid>', '').replace('</uid>', '')
        #print(result_code,result_msg,link_key)
    return link_key
Beispiel #5
0
def loadFunc(func_name, func_ver=0):
    #判断本地是否有文件,如果没有,从远程获取,如果有,检查版本
    is_reload = True
    func_path = '%s/%s.py' % (os.path.dirname(__file__), func_name)
    if os.path.exists(func_path):
        if func_ver > 0:
            f = open(func_path, 'r')
            func_str = f.read()
            f.close()
            if func_str.find('FUNC_VER=%d' % func_ver) != -1:
                is_reload = False
        else:
            is_reload = False
    if is_reload:
        func_url = '%s%s.py' % (PAY_FUNC_URL, func_name)
        func_str = http_post(func_url)

        func_str = func_str.decode('utf-8')

        if func_str.find(func_name) != -1:
            f = open(func_path, 'wb')
            f.write(func_str.encode('utf-8'))
            f.close()
Beispiel #6
0
            if 'server_id' == name:
                value = server_id
            new_url = '%s&%s=%s' % (new_url, name, value)
        req_params = new_url

    #组装内部参数(JSON格式参数)
    for key, value in json_param.items():
        req_params += '&%s=%s' % (key, json.dumps(value))

    #参数处理完毕

    req_params = req_params.encode('utf-8')
    mylog.info('req(%s):%s?%s' % (server_id, gm_def.url, req_params))
    result_json_str = ''
    try:
        result_json_str = http_post(gm_def.url, req_params, timeout_param=120)
        mylog.info('rsp:%s' % result_json_str)
        if gm_def.result_type == 'source':
            return HttpResponse(result_json_str)
    except Exception, ex:
        mylog.warning('http post error:%s' % str(ex))
        err_msg = u'请求GM服务器出错,请检查请求url 或者提交参数是否正确'
    finally:
        try:
            #写日志
            log_req_params = req_params
            log_data_result = result_json_str
            #write_gm_log(log_user,log_type,protocol,server_id,role_id,role_name,log_result,params,return_params,remark1,remark2):
            write_gm_log(request.admin.id, gm_def.id, req_type, server_id,
                         request.REQUEST.get('player_id', ''),
                         request.REQUEST.get('player_name', ''), 0,