コード例 #1
0
ファイル: storage.py プロジェクト: flamedancer/local_qz
 def process_response(self, request, response):
     try:
         app.pier.save()
     except:
         print_err()
         send_exception_mail(request)
     return response
コード例 #2
0
ファイル: __init__.py プロジェクト: flamedancer/local_qz
 def new_func(request, *args, **argw):
     try:
         params = request.REQUEST
         oid = params.get('oid', '')
         signature = params.get('sign', '')
         key = RSA.importKey(_pub_rsa_key)
         h = SHA.new(str(oid))
         verifier = PKCS1_v1_5.new(key)
         if verifier.verify(h, b64decode(signature)):
             result = func(request, *args, **argw)
             return result
     except:
         send_exception_mail(request)
         print_err()
         #清空storage
         app.pier.clear()
     return HttpResponse(
         json.dumps(
             {
                 'rc': 8,
                 'data': {
                     'msg': get_msg('login', 'server_exception'),
                     'server_now': int(time.time())
                 }
             },
             indent=1),
         content_type='application/x-javascript',
     )
コード例 #3
0
ファイル: storage.py プロジェクト: flamedancer/local_qz
 def process_request(self, request):
     try:
         subarea = request.REQUEST.get('subarea', '1') or '1'
         game_config.set_subarea(subarea)
         game_config.reload_config()
         app.pier.clear()
     except:
         print_err()
         send_exception_mail(request)
コード例 #4
0
ファイル: __init__.py プロジェクト: flamedancer/local_qz
 def new_func(request,*args,**argw):
     try:
         params = request.REQUEST
         oid = params.get('oid','')
         signature = params.get('sign','')
         key = RSA.importKey(_pub_rsa_key)
         h = SHA.new(str(oid))
         verifier = PKCS1_v1_5.new(key)
         if verifier.verify(h, b64decode(signature)):
             result = func(request,*args,**argw)
             return result
     except:
         send_exception_mail(request)
         print_err()
         #清空storage
         app.pier.clear()
     return HttpResponse(
           json.dumps({'rc':8,'data':{'msg':get_msg('login','server_exception'),'server_now':int(time.time())}}, indent=1),
           content_type='application/x-javascript',)
コード例 #5
0
ファイル: __init__.py プロジェクト: flamedancer/local_qz
 def new_func(request, *args, **argw):
     try:
         if game_config.system_config['maintenance']:
             pid = request.REQUEST.get('pid', '')
             platform = request.REQUEST.get('platform', '')
             openid = request.REQUEST.get('openid', '')
             subarea = request.REQUEST.get('subarea', '1')
             allow = False
             if platform and (pid or openid):
                 uid = __get_uid(platform, openid, pid, subarea)
                 if uid and uid in game_config.system_config.get(
                         'allow_uids', []):
                     allow = True
             if not allow:
                 data = {
                     'rc': 9,
                     'data': {
                         'msg': get_msg('login', 'maintenance'),
                         'server_now': int(time.time()),
                     }
                 }
                 return HttpResponse(
                     json.dumps(data, indent=1),
                     content_type='application/x-javascript',
                 )
         result = func(request, *args, **argw)
         return result
     except:
         print_err()
         app.pier.clear()
         #send mail
         send_exception_mail(request)
         data = {
             'rc': 8,
             'data': {
                 'msg': get_msg('login', 'server_exception'),
                 'server_now': int(time.time())
             }
         }
         return HttpResponse(
             json.dumps(data, indent=1),
             content_type='application/x-javascript',
         )
コード例 #6
0
ファイル: __init__.py プロジェクト: flamedancer/local_qz
 def new_func(request, *args, **argw):
     try:
         if game_config.system_config['maintenance']:
             pid = request.REQUEST.get('pid', '')
             platform = request.REQUEST.get('platform', '')
             openid = request.REQUEST.get('openid', '')
             subarea = request.REQUEST.get('subarea', '1')
             allow = False
             if platform and (pid or openid):
                 uid = __get_uid(platform, openid, pid, subarea)
                 if uid and uid in game_config.system_config.get('allow_uids', []):
                     allow = True
             if not allow:
                 data = {
                     'rc': 9,
                     'data': {
                         'msg': get_msg('login', 'maintenance'),
                         'server_now': int(time.time()),
                     }
                 }
                 return HttpResponse(
                     json.dumps(data, indent=1),
                     content_type='application/x-javascript',
                 )
         result = func(request, *args, **argw)
         return result
     except:
         print_err()
         app.pier.clear()
         #send mail
         send_exception_mail(request)
         data = {
             'rc': 8,
             'data': {
                 'msg': get_msg('login', 'server_exception'),
                 'server_now': int(time.time())
             }
         }
         return HttpResponse(
             json.dumps(data, indent=1),
             content_type='application/x-javascript',
         )
コード例 #7
0
ファイル: __init__.py プロジェクト: flamedancer/local_qz
    def new_func(request, *args, **argw):
        try:
            timestamp = request.REQUEST.get('timestamp')
            if not timestamp:
                data = {
                    'rc':6,
                    'data': {
                        'msg': get_msg('login', 'refresh'),
                        'server_now': int(time.time()),
                    }
                }
                return HttpResponse(
                    json.dumps(data, indent=1),
                    content_type='application/x-javascript',
                )
            # all_post_data  是 QueryDict 类型,详见:https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.QueryDict
            all_post_data = request.POST.copy()
            if 'signature' in all_post_data:
                all_post_data['signature'] = all_post_data['signature'].replace(' ', '+')

            debug_print('all_post_datas>>>>>>>>>>>>>>' + str(all_post_data))
            
            # 检查时间  时间戳超过一定时间后,视为过期请求
            if (time.time() - int(timestamp)) > settings.AUTH_AGE:
                data = {
                    'rc':1,
                    'data': {
                        'msg': get_msg('login', 'refresh'),
                        'server_now': int(time.time()),
                    }
                }
                print 'timestamp auth failed!', request.REQUEST.get('pid', 'none')
                return HttpResponse(
                    json.dumps(data, indent=1),
                    content_type='application/x-javascript',
                )

            # 检查验证码
            arg = all_post_data.pop('arg')[0]
            all_string = ''
            all_args = []
            for key, value in sorted(all_post_data.items()):
                all_args.append('%s=%s&' % (key, value))
            all_string = ''.join(all_args)

            local_arg = md5.md5(all_string.encode('utf-8') + settings.SIG_SECRET_KEY).hexdigest()[:10]
            # 签名认证不通过
            if False: #local_arg != arg:
                signature_fail = True
                if 'method' in request.REQUEST and request.REQUEST['method'] in ['main.set_name', 'pack.rename']:
                    signature_fail = False
                if signature_fail:
                    print 'signature auth failed!', request.REQUEST.get('pid', 'none')
                    data = {
                        'rc':1,
                        'data': {
                            'msg': get_msg('login', 'refresh'),
                            'server_now': int(time.time())
                        }
                    }
                    return HttpResponse(
                        json.dumps(data, indent=1),
                        content_type='application/x-javascript',
                    )
            # 认证通过
            result = func(request, *args, **argw)
            return result
        except:
            print_err()
            # 清空storage
            app.pier.clear()
            # send mail
            send_exception_mail(request)

            data = {
                'rc': 8,
                'data': {
                    'msg': get_msg('login', 'server_exception'),
                    'server_now': int(time.time())
                }
            }
            return HttpResponse(
                json.dumps(data, indent=1),
                content_type='application/x-javascript',
            )
コード例 #8
0
ファイル: __init__.py プロジェクト: flamedancer/local_qz
    def new_func(request, *args, **argw):
        try:
            timestamp = request.REQUEST.get('timestamp')
            if not timestamp:
                data = {
                    'rc': 6,
                    'data': {
                        'msg': get_msg('login', 'refresh'),
                        'server_now': int(time.time()),
                    }
                }
                return HttpResponse(
                    json.dumps(data, indent=1),
                    content_type='application/x-javascript',
                )
            # all_post_data  是 QueryDict 类型,详见:https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.QueryDict
            all_post_data = request.POST.copy()
            if 'signature' in all_post_data:
                all_post_data['signature'] = all_post_data[
                    'signature'].replace(' ', '+')

            debug_print('all_post_datas>>>>>>>>>>>>>>' + str(all_post_data))

            # 检查时间  时间戳超过一定时间后,视为过期请求
            if (time.time() - int(timestamp)) > settings.AUTH_AGE:
                data = {
                    'rc': 1,
                    'data': {
                        'msg': get_msg('login', 'refresh'),
                        'server_now': int(time.time()),
                    }
                }
                print 'timestamp auth failed!', request.REQUEST.get(
                    'pid', 'none')
                return HttpResponse(
                    json.dumps(data, indent=1),
                    content_type='application/x-javascript',
                )

            # 检查验证码
            arg = all_post_data.pop('arg')[0]
            all_string = ''
            all_args = []
            for key, value in sorted(all_post_data.items()):
                all_args.append('%s=%s&' % (key, value))
            all_string = ''.join(all_args)

            local_arg = md5.md5(
                all_string.encode('utf-8') +
                settings.SIG_SECRET_KEY).hexdigest()[:10]
            # 签名认证不通过
            if False:  #local_arg != arg:
                signature_fail = True
                if 'method' in request.REQUEST and request.REQUEST[
                        'method'] in ['main.set_name', 'pack.rename']:
                    signature_fail = False
                if signature_fail:
                    print 'signature auth failed!', request.REQUEST.get(
                        'pid', 'none')
                    data = {
                        'rc': 1,
                        'data': {
                            'msg': get_msg('login', 'refresh'),
                            'server_now': int(time.time())
                        }
                    }
                    return HttpResponse(
                        json.dumps(data, indent=1),
                        content_type='application/x-javascript',
                    )
            # 认证通过
            result = func(request, *args, **argw)
            return result
        except:
            print_err()
            # 清空storage
            app.pier.clear()
            # send mail
            send_exception_mail(request)

            data = {
                'rc': 8,
                'data': {
                    'msg': get_msg('login', 'server_exception'),
                    'server_now': int(time.time())
                }
            }
            return HttpResponse(
                json.dumps(data, indent=1),
                content_type='application/x-javascript',
            )
コード例 #9
0
ファイル: charge.py プロジェクト: flamedancer/local_qz
def charge_api(user_base_obj, oid, item_id, platform='', res_dict={},
               request=None, charge_way='', more_msg={}, charge_money=None):
    """充值通用函数


    Args:
        oid:   订单号,唯一标示
        item_id:   虚拟产品ID
        user_base_obj:  UserBase对象
        platform:   平台  例如:  qq, 360 , sina
    """
    data = {
        'rc': 0,
        'result': '',
        'data': {
            'msg': get_msg('charge','success'),
        }
    }

    if ChargeRecord.find({'oid':oid}):
        data['result'] = u'fail_订单重复' 
        return data

    rk_user = user_base_obj
    user_property_obj = rk_user.user_property
    property_info = user_property_obj.property_info
            
    try:
        shop_config = game_config.shop_config
        sale_conf = shop_config['sale']
        monthCard_sale_conf = shop_config.get('monthCard', {})
        item_info = sale_conf.get(item_id) or monthCard_sale_conf.get(item_id)
        if not item_info:
            data['rc'] = 12
            data['result'] = u'fail_无此商品' 
            data['data']['msg'] = 'item_id not exist:  ' + item_id
            return data
            

        # all_sale_type = ['sale']
        # for sale_type in all_sale_type:
        #     sale_items.update(shop_config.get(sale_type, {}))

        
        # 检查金额是否对
        if charge_money and not settings.DEBUG and float(charge_money) != float(item_info['price']):
            data['rc'] = 12
            data['result'] = u"充值金额不正确:%f" % float(charge_money)
            data['data']['msg'] = get_msg('charge','charge_money_invalid')
            return data
        before_coin = user_property_obj.coin
        # 分为月卡购买和  普通元宝购买
        free_coin = 0
        if item_id in sale_conf:
            # 计算此次购买可以买到的sale_coin 和额外赠送的 free_coin
            this_item_has_bought_times = property_info["charge_item_bought_times"].get(item_id, 0)
            if this_item_has_bought_times < item_info['extreme_cheap_time']:
                free_coin = item_info['extreme_free_coin']
            else:
                free_coin = item_info['free_coin']
            all_get_coin = item_info['sale_coin'] + free_coin
            # 记录此商品已购买次数
            property_info['charge_item_bought_times'].setdefault(item_id, 0)
            property_info['charge_item_bought_times'][item_id] += 1

        else:
            monthCard_remain_days = property_info.get('monthCard_remain_days', {})
            monthCard_remain_days.setdefault(item_id, 0)
            monthCard_remain_days[item_id] += 29
            property_info['monthCard_remain_days'] = monthCard_remain_days
            all_get_coin = item_info['sale_coin']

        # 记录总充值金额和元宝数
        property_info["charge_coins"] += all_get_coin
        property_info["charge_money"] += item_info['price']
        # 加元宝
        user_property_obj.property_info["coin"] += all_get_coin

        after_coin = user_property_obj.coin

        #作记录
        record_data = {
                        'oid': oid,
                        'platform': rk_user.platform,
                        'lv': user_property_obj.lv,
                        'price': item_info['price'],
                        'item_id': item_id,
                        'sale_coin': item_info['sale_coin'],
                        'free_coin': free_coin,
                        'createtime': datetime_toString(datetime.datetime.now()),
                        'before_coin': before_coin,
                        'after_coin': after_coin,
                        'client_type':rk_user.client_type,
                        'charge_way': charge_way,
                      }
        if more_msg:
            record_data.update(more_msg)
        ChargeRecord.set_log(rk_user, record_data)

        data['result'] = 'success'
        # 判断是否首次充值,若是,给首充奖励
        if (property_info["charge_money"] - item_info['price']) <= 0:
            __give_first_charge_award(rk_user)

        # (运营活动)充值满多少原价元宝给奖励
        __give_charge_award(rk_user, item_info['sale_coin'])        
        # 月卡处理
        # if item_id in month_items:
        #     __record_month_item(rk_user, item_id, item_info)
        user_property_obj.property_info = property_info
        user_property_obj.put()
    except:
        print_err()
        send_exception_mail(request)
        #清空storage
        app.pier.clear()
        data['rc'] = 12
        data['result'] = 'fail_' + traceback.format_exc()
        data['data']['msg'] = get_msg('charge','invalid')
    return data