63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
sys.path.append('../local_packages')
|
|
import q7
|
|
import f7
|
|
|
|
import os
|
|
import json
|
|
|
|
from google.oauth2 import id_token
|
|
from google.auth.transport import requests
|
|
|
|
CONFIG_DIR = '../config' if f7.isOnlineEnv() else '/var/data/conf_test/mailsender/config'
|
|
|
|
def __loginGoogleAuth(request):
|
|
try:
|
|
client_id = request('client_id', '')
|
|
token = request('token', '')
|
|
idinfo = id_token.verify_oauth2_token(token, requests.Request(), client_id)
|
|
return json.dumps({
|
|
'errcode': 0,
|
|
'errmsg': '',
|
|
'openid': idinfo['sub']
|
|
})
|
|
except Exception as e:
|
|
return json.dumps({
|
|
'errcode': 101,
|
|
'errmsg': '认证失败' + str(e),
|
|
})
|
|
|
|
def __loginAuth(request):
|
|
gameid = request('gameid', '')
|
|
channel = request('channel', '')
|
|
if channel != '6512':
|
|
return json.dumps({
|
|
'errcode': 100,
|
|
'errmsg': '不支持该渠道',
|
|
})
|
|
return __loginGoogleAuth(request)
|
|
|
|
def getConf():
|
|
cluster_conf = json.loads(open(CONFIG_DIR + '/loginserver_be.cluster.json', 'r').read())
|
|
for conf in cluster_conf:
|
|
if conf['instance_id'] == f7.app.getInstanceId():
|
|
return conf
|
|
return None
|
|
|
|
if __name__ == "__main__":
|
|
q7.xPrint('pid %d' % os.getpid())
|
|
f7.app.init('/data/logs/mailsender/logs')
|
|
f7.udplog.info('mailsender start pid:%d node_id:%d instance_id:%d' % (
|
|
os.getpid(),
|
|
f7.app.getNodeId(),
|
|
f7.app.getInstanceId())
|
|
)
|
|
|
|
conf = getConf()
|
|
# f7.app.registerHandler('Login', 'auth', __loginAuth)
|
|
f7.app.listen(conf['listen_port'])
|
|
f7.app.start()
|