def filterErrorMessage(msg): from poker.util import webpage gameId, clientId, userId, action = msg.getParams('gameId', 'clientId', 'userId', 'action') cmd = msg.getCmd() bugclientId = 'IOS_3.82_tuyoo.appStore,weixinPay,alipay.0-hall6.appStore.tuyoo2016' url = 'http://open.touch4.me/open/v3/user/setForbidden' if (gameId is None and cmd == 'game' and action == 'leave' and clientId == bugclientId): datas = {'lock_users': [userId]} ftlog.warn('kill cracker, msg:', msg) webpage.webgetJson(url, datas, None, 10)
def make_order_id(appId, orderIdVer62, httpcallback=None, isRemote=False): if gdata.mode() == gdata.RUN_MODE_ONLINE or isRemote: appId = int(appId) seqNum = daobase.executeMixCmd('INCR', 'global.orderid.seq.' + orderIdVer62) # orderId构成:<1位API版本号>+<4位APPID>+DD+<5位序号>,共14位 ct = datetime.now() dd = ct.strftime('%d') a = hex(appId)[2:][-4:] a = '0' * (4 - len(a)) + a b = hex(seqNum)[2:][-7:] b = '0' * (7 - len(b)) + b oid = orderIdVer62 + a + dd + b # 记录单号回应的回调地址 if httpcallback != None and isinstance(httpcallback, (str, unicode)) and httpcallback.find('http://') == 0: daobase.executeMixCmd('HSET', 'global.orderid.callback', oid, httpcallback) return oid else: # 通知订单数据中心(线上GATEWAY服务), 产生了一个新订单, 需要进行 单号<->回调服务的记录 httpurl = gdata.httpOnlieGateWay() + '/_testorder_make_id' datas = { 'appId': appId, 'orderIdVer62': orderIdVer62, 'httpcallback': gdata.httpSdk() } result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['orderPlatformId']
def _onPlayerSignin(event): conf = hallconf.getPublicConf('match_360kp', None) if not conf or not isinstance(conf, dict): if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin NoConf userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return callbackUrl = conf.get('signinCallbackUrl') if not callbackUrl: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin NoCallbackUrl userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return timestamp = pktimestamp.getCurrentTimestamp() params = getParamsByPlayer(event.player, timestamp) if not params: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin NoParams userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return sign = signin('REGIST', params) params['sign'] = sign result = webpage.webgetJson(callbackUrl, datas=params, appKey=None, timeout=conf.get('timeout', 3)) if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result) if 'errno' in result: ftlog.warn('match360kp.onPlayerSignin userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result)
def get_short_order_id(orderPlatformId): if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么再mix库中生成短单号 shortOrderId = daobase.executeMixCmd('INCR', 'global.orderid.seq.sort') shortOrderId = str(100000 + shortOrderId)[-6:] daobase.executeMixCmd('HSET', 'sort.orderid.map', shortOrderId, orderPlatformId) return shortOrderId else: # 若是测试服务, 那么调用正式服远程API生成单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_short_id' datas = {'orderPlatformId': orderPlatformId} result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['sortOrderPlatformId']
def get_short_order_id(orderPlatformId): if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么再mix库中生成短单号 shortOrderId = daobase.executeMixCmd('INCR', 'global.orderid.seq.sort') shortOrderId = str(100000 + shortOrderId)[-6:] daobase.executeMixCmd('HSET', 'sort.orderid.map', shortOrderId, orderPlatformId) return shortOrderId else: # 若是测试服务, 那么调用正式服远程API生成单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_short_id' datas = { 'orderPlatformId': orderPlatformId } result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['sortOrderPlatformId']
def get_long_order_id(shortOrderId): if not is_short_order_id_format(shortOrderId): return shortOrderId if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么重mix库中取得长单号 orderPlatformId = daobase.executeMixCmd('HGET', 'sort.orderid.map', shortOrderId) return str(orderPlatformId) else: # 若是测试服务, 那么调用正式服远程API取得长单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_long_id' datas = {'sortOrderPlatformId': shortOrderId} result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['orderPlatformId']
def get_long_order_id(shortOrderId): if not is_short_order_id_format(shortOrderId): return shortOrderId if gdata.mode() == gdata.RUN_MODE_ONLINE: # 若是线上正式服, 那么重mix库中取得长单号 orderPlatformId = daobase.executeMixCmd('HGET', 'sort.orderid.map', shortOrderId) return str(orderPlatformId) else: # 若是测试服务, 那么调用正式服远程API取得长单号 httpurl = gdata.httpOnlieGateWay() + '/_testorder_get_long_id' datas = { 'sortOrderPlatformId': shortOrderId } result, _ = webpage.webgetJson(httpurl, datas, None, 10) return result['orderPlatformId']
def _onPlayerSignin(event): conf = hallconf.getPublicConf('match_360kp', None) if not conf or not isinstance(conf, dict): if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin NoConf userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return callbackUrl = conf.get('signinCallbackUrl') if not callbackUrl: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin NoCallbackUrl userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return timestamp = pktimestamp.getCurrentTimestamp() params = getParamsByPlayer(event.player, timestamp) if not params: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin NoParams userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return sign = signin('REGIST', params) params['sign'] = sign result = webpage.webgetJson(callbackUrl, datas=params, appKey=None, timeout=conf.get('timeout', 3)) if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerSignin userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result) if 'errno' in result: ftlog.warn('match360kp.onPlayerSignin userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result)
def _reportOnlineToSdk(_lockobj): ''' 向当前的SDK服务汇报自己的运行状态 ''' posturl = '%s/_game_server_online_?' % (gdata.httpSdkInner()) datas = {'http_game': gdata.httpGame(), 'conns': gdata.getUserConnIpPortList(), 'mode': gdata.mode(), 'name': gdata.name(), 'time': int(time.time()) } datas = strutil.dumpsbase64(datas) ret, _ = webpage.webgetJson(posturl, {'params': datas}, None, 10) if isinstance(ret, dict): result = ret.get('result', {}) ok = result.get('ok', False) if ok == True: global _REPORT_OK _REPORT_OK = True ftlog.debug('_reportOnlineToSdk-> OK !', ret) return ftlog.debug('_reportOnlineToSdk-> ERROR !', ret)
def _reportOnlineToSdk(_lockobj): ''' 向当前的SDK服务汇报自己的运行状态 ''' posturl = '%s/_game_server_online_?' % (gdata.httpSdkInner()) datas = { 'http_game': gdata.httpGame(), 'conns': gdata.getUserConnIpPortList(), 'mode': gdata.mode(), 'name': gdata.name(), 'time': int(time.time()) } datas = strutil.dumpsbase64(datas) ret, _ = webpage.webgetJson(posturl, {'params': datas}, None, 10) if isinstance(ret, dict): result = ret.get('result', {}) ok = result.get('ok', False) if ok == True: global _REPORT_OK _REPORT_OK = True ftlog.debug('_reportOnlineToSdk-> OK !', ret) return ftlog.debug('_reportOnlineToSdk-> ERROR !', ret)
def _onPlayerOver(event): conf = hallconf.getPublicConf('match_360kp', None) if not conf or not isinstance(conf, dict): if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver NoConf userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return callbackUrl = conf.get('matchResultCallbackUrl') if not callbackUrl: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver NoCallbackUrl userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return timestamp = pktimestamp.getCurrentTimestamp() params = getParamsByPlayer(event.player, timestamp) if not params: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver NoParams userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return sign = signin('MATCH_RESULT', params) params['sign'] = sign matchResult = '' reward = '' if event.rankRewards: matchResult = conf.get('resultDescReward', '') reward = event.rankRewards.desc else: matchResult = conf.get('resultDescNoReward', '') matchResult = strutil.replaceParams( matchResult, { 'match.name': event.player.inst.match.conf.name, 'rank': event.player.rank, 'reward': reward }) params['result'] = matchResult result = webpage.webgetJson(callbackUrl, datas=params, appKey=None, timeout=conf.get('timeout', 3)) if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result) if not result or 'errno' in result: ftlog.warn('match360kp.onPlayerOver userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result)
def _main(): from freetime.entity.msg import MsgPack from freetime.util import log as ftlog from poker.util import webpage, strutil from poker.util.constants import CLIENT_SYS_H5 from poker.entity.dao import daobase, sessiondata from poker.entity.configure import gdata from poker.protocol import router from hall.entity import hallstore, hallconf # 开始支付 serverUrl = gdata.httpGame() product = hallstore.findProduct(gameId, userId, productId) appId = 9999 appKey = hallconf.getAppKeyInfo(appId).get("key", "") clientId = sessiondata.getClientId(userId) clientOs = sessiondata.getClientIdSys(userId) if clientOs == CLIENT_SYS_H5: # 发起支付请求 httpUrl = serverUrl + "/open/v4/pay/order" datas = { "userId": userId, "appId": appId, "wxAppId": "wx30efe34580243475", "clientId": clientId, "imei": "null", "uuid": "9503fcb2e234423081a13010cd401554", "prodId": productId, "prodName": product.displayName, "prodCount": 1, "prodPrice": product.price, "chargeType": "wxapp.iap", "gameId": gameId, "appInfo": "", "mustcharge": 1 } ret, _ = webpage.webgetJson(httpUrl, datas) if ret.get("result").get("code") != 0: ftlog.error("pay test error", ret, datas) return platformOrder = ret.get("result").get("chargeInfo").get("platformOrderId") chargeData = daobase._executePayDataCmd("HGET", "sdk.charge:%s" % platformOrder, "consume") orderId = strutil.loads(chargeData, False, True, {}).get("prodOrderId") # SDK通知游戏服钻石变更 httpUrl = serverUrl + "/v2/game/charge/notify" datas = { "appId": appId, "clientId": clientId, "userId": userId, "buttonId": productId, "diamonds": int(product.priceDiamond), "rmbs": float(product.price) } ret = webpage.webget(httpUrl, datas) print ret # SDK通知游戏服发货 httpUrl = serverUrl + "/v2/game/consume/delivery" datas = { "apiver": 2, "appId": appId, "appInfo": "1", "chargeType": "wxwap", "chargedDiamonds": int(product.priceDiamond), "chargedRmbs": float(product.price), "clientId": clientId, "consumeCoin": product.priceDiamond, "consumeId": orderId, "orderId": orderId, "platformOrder": platformOrder, "prodCount": 1, "prodId": productId, "prodPrice": product.price, "userId": userId } webpage.webget(httpUrl, datas, appKey) else: # SDK通知游戏服钻石变更 httpUrl = serverUrl + "/api/hall5/store/charge/notify" datas = { "appId": appId, "userId": userId, "chargedDiamonds": int(product.priceDiamond), "chargedRmbs": float(product.price), "clientId": clientId, "prodId": productId, "realGameId": 9998 } ret = webpage.webget(httpUrl, datas, appKey) print ret
def _onPlayerOver(event): conf = hallconf.getPublicConf('match_360kp', None) if not conf or not isinstance(conf, dict): if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver NoConf userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return callbackUrl = conf.get('matchResultCallbackUrl') if not callbackUrl: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver NoCallbackUrl userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return timestamp = pktimestamp.getCurrentTimestamp() params = getParamsByPlayer(event.player, timestamp) if not params: if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver NoParams userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf) return sign = signin('MATCH_RESULT', params) params['sign'] = sign matchResult = '' reward = '' if event.rankRewards: matchResult = conf.get('resultDescReward', '') reward = event.rankRewards.desc else: matchResult = conf.get('resultDescNoReward', '') matchResult = strutil.replaceParams(matchResult, { 'match.name': event.player.inst.match.conf.name, 'rank': event.player.rank, 'reward': reward }) params['result'] = matchResult result = webpage.webgetJson(callbackUrl, datas=params, appKey=None, timeout=conf.get('timeout', 3)) if ftlog.is_debug(): ftlog.debug('match360kp.onPlayerOver userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result) if not result or 'errno' in result: ftlog.warn('match360kp.onPlayerOver userId=', event.userId, 'matchId=', event.matchId, 'signinParams=', event.player.signinParams, 'snsId=', event.player.snsId, 'conf=', conf, 'result=', result)