Skip to content

Commit

Permalink
gjg
Browse files Browse the repository at this point in the history
  • Loading branch information
you285168 committed Mar 8, 2020
1 parent b375010 commit ceaff75
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 10 deletions.
11 changes: 11 additions & 0 deletions charge/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
from django.contrib import admin
from .models import ChargeOrder

# Register your models here.


@admin.register(ChargeOrder)
class WebAccountAdmin(admin.ModelAdmin):
list_display = ('uid', 'serverid', 'playerid', 'device', 'order_id', 'product_id', 'status', 'tester', 'platform', 'pay_way', 'time')

'''
def get_readonly_fields(self, request, obj=None):
return [f.name for f in self.model._meta.fields]
'''
1 change: 1 addition & 0 deletions charge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ class ChargeOrder(models.Model):

class Meta:
verbose_name_plural = "充值"
unique_together = ('platform', 'order_id',)
2 changes: 0 additions & 2 deletions charge/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from . import views

urlpatterns = [
path('android/pay', views.android_pay),
path('apple/pay', views.apple_pay),
path('feiyu/pay', views.feiyu_pay),
path('player/info', views.charge_player_info),
path('xindong/pay', views.xindong_pay),
Expand Down
127 changes: 127 additions & 0 deletions charge/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,130 @@
from django.shortcuts import render
from webaccount.account import get_cache_account
from webaccount.platform import XINDONG_KEY
from hashlib import md5
import logging
from .models import ChargeOrder
from django.core.exceptions import ObjectDoesNotExist
from django.utils import timezone
from serverconf.interface import get_game_config, game_http_port
import requests
from django.http import HttpResponse
from django.core.cache import cache

logger = logging.getLogger('wasteland')

# Create your views here.
ORDER = 'ORDER-'
CHARGE = 'CHARGE-'
CACHE_TIME = 15 * 60


def _charge_ship(obj):
try:
server = get_game_config(obj.serverid)
if not server:
raise Exception("not found server {0}".format(obj.serverid))
platform = 0
if obj.tester == 1:
platform = 1
elif obj.platform == 'android':
platform = 3
elif obj.platform == 'ios':
platform = 2
elif obj.platform == 'feiyu':
platform = 4
res = requests.get('http://{0}:{1}'.format(server['http_host'], game_http_port(obj.serverid)), params={
'account': obj.uid,
'productid': obj.product_id,
'platform': platform,
'order': obj.order_id,
'pay_way': obj.pay_way,
})
if res:
obj.status = 1
obj.save()
return True
except Exception as e:
logger.error('_charge_ship error: {0}'.format(str(e)))
return False


def _pay_logic(platform, param):
cachekey = ORDER + param['order_id']
if cache.get(cachekey):
return
cache.set(cachekey, 1, CACHE_TIME)
try:
try:
obj = ChargeOrder.objects.get(order_id=param['order_id'], platform=platform)
except ObjectDoesNotExist:
obj = None
if not obj:
param['platform'] = platform
param['time'] = timezone.now().strftime("%Y-%m-%d %H:%M:%S")
obj = ChargeOrder.objects.create(**param)
print(obj.status)
if obj.status == 0:
print('here')
if not _charge_ship(obj):
cache.delete(CHARGE + param['uid'])

except Exception as e:
logger.error('_pay_logic error: {0}'.format(str(e)))
cache.delete(cachekey)


def xindong_pay(request):
product_id = request.GET.get('productid', None)
sign = request.GET.get('sign', None)
sid = request.GET.get('server_id', None)
mark = request.GET.get('mark', None)
uid = request.GET.get('uid', None)
order = request.GET.get('order', None)
pay_way = request.GET.get('pay_way', None)

code = 0
if not product_id or not sign or not sid or not uid or not order:
code = 2
else:
data = get_cache_account(xindong=uid)
if not data:
code = 7
else:
my_sign = str.lower(md5((uid + '_' + order + '_' + product_id
+ '_' + mark + '_' + XINDONG_KEY).encode('utf8')).hexdigest())
if my_sign != sign:
code = 5
else:
param = {
'serverid': sid,
'uid': data['uid'],
'product_id': product_id,
'pay_way': pay_way,
'order_id': order,
}
if 'device' in data:
param['device'] = data['device']
_pay_logic('xindong', param)
code = 1
'''
{
code:
1 充值成功(重复订单号储值也返回1)
2 充值的服务器不存在,请确认游戏服域名正确并已被添加到后台
3 充值游戏币有误
5 md5错误,请确认密钥正确,充值票据算法跟文档描述一致,参与票据计算的参数于传递给接口的参数一致
7 不存在此账号,请确认用户名和登录接口传递的是一致的
0 充值失败,订单处于待充状态,可以重复请求直到返回值为1
- 1 充值请求参数错误
}
'''
return HttpResponse(code)


def feiyu_pay(request):
pass


def charge_player_info(request):
pass
3 changes: 3 additions & 0 deletions common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import geoip2.database
import logging
import uuid
from django.core.cache import cache
from django.db import models

reader = geoip2.database.Reader('./extend/GeoLite2-Country.mmdb')
logger = logging.getLogger('wasteland')
Expand Down Expand Up @@ -97,3 +99,4 @@ def get_admin_url(request):

def get_url_params():
return _get_request_params(global_request)

1 change: 1 addition & 0 deletions wasteland/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'serverweight',
'common',
'webaccount',
'charge',
]

MIDDLEWARE = [
Expand Down
2 changes: 1 addition & 1 deletion wasteland/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
path('server/', include('serverconf.urls')),
path('weight/', include('serverweight.urls')),
path('account/', include('webaccount.urls')),
# path('charge/', include('charge.urls')),
path('charge/', include('charge.urls')),
]
5 changes: 5 additions & 0 deletions webaccount/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def get_last_sid(uid):
return sid


def set_last_sid(uid, sid):
cachekey = _get_sid_key(uid)
cache.set(cachekey, sid, None)


def is_lock_ip(ip):
ips = get_lock_ip()
if ips:
Expand Down
2 changes: 2 additions & 0 deletions webaccount/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
PLATFORM = ('gamecenter', 'googleplay', 'facebook', 'feiyu', 'xindong')
FEIYU_KEY = 'bdc96026c4fb2bdbe86cf2c29aaf39c9'
FEIYU_ID = '10029'
XINDONG_KEY = 'd013b9dfe96ab8396f45070fae87653d'
XINDONG_ID = '161414'


def platform_verify(platform, signture, subplatform, email):
Expand Down
2 changes: 1 addition & 1 deletion webaccount/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
path('login', views.user_login),
path('test', views.account_test),
path('bind', views.bind_account),
path('server/user', views.server_user_login),
path('enter/game', views.enter_game),
]
22 changes: 16 additions & 6 deletions webaccount/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from .platform import platform_verify, FEIYU_KEY
import logging
from .account import *
from common import get_client_ip, md5_sign, get_country_code, create_uuid
from common import get_client_ip, md5_sign, get_country_code
import time
from .models import WebAccount
from django.core.exceptions import ObjectDoesNotExist
import requests
from serverconf.interface import get_login_config, login_http_port, get_game_config

Expand All @@ -25,8 +26,15 @@ def account_test(request):
return HttpResponse('')


def server_user_login(request):
pass
def enter_game(request):
uid = request.GET.get('account', None)
sid = request.GET.get('serverid', None)
data = get_cache_account(uid=uid)
platform = {}
if data:
set_last_sid(uid, sid)
platform = data['platform']
return JsonResponse(platform)


def bind_account(request):
Expand All @@ -41,11 +49,13 @@ def bind_account(request):
if not key:
code = 3
break
objs = WebAccount.objects.filter(uid=uid)
if len(objs) == 0:
try:
obj = WebAccount.objects.get(uid=uid)
except ObjectDoesNotExist:
obj = None
if not obj:
code = 4
break
obj = objs[0]
if getattr(obj, platform, '') != '':
code = 2
break
Expand Down

0 comments on commit ceaff75

Please sign in to comment.