def getWeixinRedEnvelopePassword(gameId, userId, itemId, amount): redenvlopeConf = hallconf.getPublicConf('weixin_redenvlope', {}) if not redenvlopeConf: return -1, '红包系统忙,请稍后再试' response = None try: params = { 'gameId': str(gameId), 'userId': str(userId), 'itemId': str(itemId), 'amount': str(amount) } params['code'] = _signForWeixin(params) response, _ = webpage.webget(redenvlopeConf['url'], postdata_=params, needresponse=True) ftlog.debug('sdkclient.getWeixinRedEnvelopePassword gameId=', gameId, 'userId=', userId, 'itemId=', itemId, 'amount=', amount, 'response=', response) return checkResponse(redenvlopeConf, response) except: ftlog.error('sdkclient.getWeixinRedEnvelopePassword Exception gameId=', gameId, 'userId=', userId, 'itemId=', itemId, 'amount=', amount, 'response=', response) return -1, redenvlopeConf.get('errorInfo')
def needSendGameList(self, userId, gameId, clientId, isdayfirst): from poker.util import strutil from hall.entity import hallconf from hall.entity.hallconf import HALL_GAMEID from datetime import datetime if not isdayfirst or gameId != HALL_GAMEID: if ftlog.is_debug(): ftlog.debug('UtilHelper.needSendGameList NotDayFirstOrHallGameId', 'userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'isdayfirst=', isdayfirst) return False autoSendGameList = hallconf.getPublicConf('autoSendGameList', {}) if autoSendGameList.get('close', 0): if ftlog.is_debug(): ftlog.debug('UtilHelper.needSendGameList Closed', 'userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'isdayfirst=', isdayfirst) return False games = autoSendGameList.get('games', []) if not games: if ftlog.is_debug(): ftlog.debug('UtilHelper.needSendGameList NotConfGames', 'userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'isdayfirst=', isdayfirst) return False nowT = datetime.now() hallGameId = strutil.getGameIdFromHallClientId(clientId) for gameConf in games: if gameConf.get('gameId') == hallGameId: timeRange = gameConf.get('timeRange') if not timeRange: return True sTime = datetime.strptime(timeRange[0], '%Y-%m-%d %H:%M:%S') eTime = datetime.strptime(timeRange[1], '%Y-%m-%d %H:%M:%S') if nowT >= sTime and nowT < eTime: return True if ftlog.is_debug(): ftlog.debug('UtilHelper.needSendGameList NotInTimeRange', 'userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'isdayfirst=', isdayfirst, 'timeRange=', timeRange) return False if ftlog.is_debug(): ftlog.debug('UtilHelper.needSendGameList NotInGames', 'userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'isdayfirst=', isdayfirst, 'timeRange=', timeRange) return False
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 sendLed(gameId, msgstr, ismgr=0, scope="hall", clientIds=None, isStopServer=False): """ 发送LED @param gameId: 游戏gameId,gameId部分起到了过滤/范围的作用 @param msgstr: LED消息内容 @param ismgr: 是否是GDSS发的,默认非GDSS发送的 @param scope: string类型,LED显示级别/范围,详见http://192.168.10.93:8090/pages/viewpage.action?pageId=1281059 scope摘要 - "6": 只在地主插件里面播放 - "hall": 在大厅界面播放 - "hall6": 在大厅和地主插件里面播放 - "global": 在大厅任何界面都播放 @param clientIds: 不发送的clientId集合,默认全发送 @param isStopServer: 是否是停服led """ assert isinstance(msgstr, basestring) clientIds = clientIds or [] closeLedGameIds = hallconf.getPublicConf("closeLedGameIds", []) if not isStopServer and closeLedGameIds and gameId in closeLedGameIds: if ftlog.is_debug(): ftlog.debug("led.sendLed closed", "gameId=", gameId, "msgstr=", msgstr, "scope=", scope, "ismgr=", ismgr, "isStopServer=", isStopServer) return None if ftlog.is_debug(): ftlog.debug("led.sendLed gameId=", gameId, "msgstr=", msgstr, "scope=", scope, "ismgr=", ismgr, "isStopServer=", isStopServer) try: msgDict = decodeMsg(gameId, msgstr) # 每条LED所包含的数据内容 msg = [0, gameId, msgDict, scope, clientIds, isStopServer] leds = _LEDS kmsg = "m:" + str(gameId) ktime = "t:" + str(gameId) if ismgr: leds[kmsg] = [msg] leds[ktime] = datetime.now() else: if not kmsg in leds: leds[kmsg] = [] leds[ktime] = None timeout = leds[ktime] if timeout != None: timeouts = hallconf.getHallPublic().get( "led.manager.timeout", 30) secondes = (datetime.now() - timeout).seconds if secondes < timeouts: if ftlog.is_debug(): ftlog.warn("led.sendLed Failed gameId=", gameId, "msgstr=", msgstr, "ismgr=", ismgr, "scope=", scope, "timeouts=", timeouts, "secondes=", secondes) return msgq = leds[kmsg] msgq.append(msg) ledlength = 3 leds[ktime] = datetime.now() leds[kmsg] = msgq[-ledlength:] if ftlog.is_debug(): ftlog.debug("led.sendLed gameId=", gameId, "msgstr=", msgstr, "ismgr=", ismgr, "msg=", msg, "leds=", _LEDS) return msg except: ftlog.error("led.sendLed gameId=", gameId, "msgstr=", msgstr, "scope=", scope, "ismgr=", ismgr, "leds=", _LEDS) return None
def sendLed(gameId, msgstr, ismgr=0, scope='hall', clientIds=[], isStopServer=False, **kwargs): ''' 发送LED @param gameId: 游戏gameId,gameId部分起到了过滤/范围的作用 @param msgstr: LED消息内容 @param ismgr: 是否是GDSS发的,默认非GDSS发送的 @param scope: string类型,LED显示级别/范围,详见http://192.168.10.93:8090/pages/viewpage.action?pageId=1281059 scope摘要 - '6': 只在地主插件里面播放 - 'hall': 在大厅界面播放 - 'hall6': 在大厅和地主插件里面播放 - 'global': 在大厅任何界面都播放 @param clientIds: 发送的clientId集合,默认全发送 @param isStopServer: 是否是停服led ''' if not kwargs.get('active', 0): return assert isinstance(msgstr, basestring) closeLedGameIds = hallconf.getPublicConf('closeLedGameIds', []) if not isStopServer and closeLedGameIds and gameId in closeLedGameIds: if ftlog.is_debug(): ftlog.debug('hallled.sendLed closed', 'gameId=', gameId, 'msgstr=', msgstr, 'scope=', scope, 'ismgr=', ismgr, 'isStopServer=', isStopServer) return None if ftlog.is_debug(): ftlog.debug('hallled.sendLed gameId=', gameId, 'msgstr=', msgstr, 'scope=', scope, 'ismgr=', ismgr, 'isStopServer=', isStopServer) try: msgDict = decodeMsg(gameId, msgstr) msg = [0, gameId, msgDict, scope, clientIds, isStopServer] leds = _LEDS kmsg = 'm:' + str(gameId) ktime = 't:' + str(gameId) if ismgr: leds[kmsg] = [msg] leds[ktime] = datetime.now() else: if not kmsg in leds: leds[kmsg] = [] leds[ktime] = None timeout = leds[ktime] if timeout != None: timeouts = hallconf.getHallPublic().get( 'led.manager.timeout', 40) secondes = (datetime.now() - timeout).seconds if secondes < timeouts: if ftlog.is_debug(): ftlog.warn('hallled.sendLed Failed gameId=', gameId, 'msgstr=', msgstr, 'ismgr=', ismgr, 'scope=', scope, 'timeouts=', timeouts, 'secondes=', secondes) return msgq = leds[kmsg] msgq.append(msg) ledlength = 3 leds[ktime] = datetime.now() leds[kmsg] = msgq[-ledlength:] if ftlog.is_debug(): ftlog.debug('hallled.sendLed gameId=', gameId, 'msgstr=', msgstr, 'ismgr=', ismgr, 'msg=', msg, 'leds=', _LEDS) return msg except: ftlog.error('hallled.sendLed gameId=', gameId, 'msgstr=', msgstr, 'scope=', scope, 'ismgr=', ismgr, 'leds=', _LEDS) return None
def requestExchangeCash(userId, count, wxappId, timestamp): # 扣除奖券 userAssets = hallitem.itemSystem.loadUserAssets(userId) _, consumeCount, _ = userAssets.consumeAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH', count) if consumeCount < count: raise TYExchangeRequestError('余额不足') exchangeId = None try: exchangeId = _makeExchangeId() record = TYExchangeRecord(exchangeId) record.createTime = timestamp amount = count / 100.0 record.params = { 'type': 7, 'count': count, 'amount': amount, 'wxappId': wxappId } record.errorCode = 0 record.state = TYExchangeRecord.STATE_NORMAL jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) displayName = '%.2f现金' % (amount) parasDict = {} httpAddr = gdata.httpGame() parasDict[ 'callbackAudit'] = httpAddr + '/v3/game/exchange/auditCallback' parasDict[ 'callbackShipping'] = httpAddr + '/v3/game/exchange/shippingResultCallback' parasDict['user_id'] = userId parasDict['exchange_id'] = exchangeId parasDict['prod_id'] = 'cash' parasDict['prod_kind_name'] = displayName parasDict['prod_num'] = 1 parasDict['exchange_type'] = record.params.get('type', 7) parasDict['exchange_amount'] = amount parasDict['exchange_desc'] = displayName platformId = hallconf.getPublicConf('platformId', None) if platformId: parasDict['platform_id'] = platformId # gdss那边需要 parasDict['user_phone'] = '' parasDict['user_name'] = '' parasDict['user_addres'] = '' parasDict['wxappid'] = wxappId gdssUrl = hallconf.getItemConf().get( 'exchangeGdssUrl', 'http://gdss.touch4.me/?act=api.propExchange') from poker.util import webpage try: hbody, _ = webpage.webgetGdss(gdssUrl, parasDict) resJson = json.loads(hbody) except: ftlog.exception() raise TYExchangeRequestError() retcode = resJson.get('retcode', -1) retmsg = resJson.get('retmsg', '兑换请求出错') if retcode != 1: raise TYExchangeRequestError(retmsg) record.state = TYExchangeRecord.STATE_AUDIT rStr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, rStr) ftlog.info('requestExchangeCash', 'userId=', userId, 'count=', count, 'amount=', amount, 'wxappId=', wxappId, 'exchangeId=', exchangeId, 'retcode=', retcode, 'retmsg=', retmsg) return record, retmsg except: userAssets.addAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH_BACK', count) # 历史提现记录对应减掉这个数额 userdata.incrAttr(userId, 'exchangedCoupon', -abs(count)) ftlog.warn('requestExchangeCash BackCoupon', 'userId=', userId, 'count=', count, 'wxappId=', wxappId, 'exchangeId=', exchangeId) raise finally: datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'coupon')
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 handleShippingResult(userId, exchangeId, result): supportWXCash = hallconf.getPublicConf('support_wx_cash', 1) if supportWXCash: return handleShippingResult2(userId, exchangeId, result) return handleExchangeAuditResult1(userId, exchangeId, result)
def requestExchange(userId, item, params, timestamp): assert (isinstance(item, TYExchangeItem)) exchangeId = _makeExchangeId() record = TYExchangeRecord(exchangeId) record.itemId = item.itemId record.itemKindId = item.kindId record.createTime = timestamp record.params = params record.errorCode = 0 record.state = TYExchangeRecord.STATE_NORMAL jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) parasDict = {} httpAddr = gdata.httpGame() parasDict['callbackAudit'] = httpAddr + '/v3/game/exchange/auditCallback' parasDict[ 'callbackShipping'] = httpAddr + '/v3/game/exchange/shippingResultCallback' parasDict['user_id'] = userId parasDict['exchange_id'] = exchangeId parasDict['prod_id'] = item.itemId parasDict['prod_kind_name'] = item.itemKind.displayName parasDict['prod_num'] = 1 parasDict['exchange_type'] = params.get('type', 0) parasDict['exchange_amount'] = params.get('count', 0) parasDict['exchange_desc'] = params.get('desc', '') parasDict['user_phone'] = params.get('phone') parasDict['user_name'] = params.get('uName') parasDict['user_addres'] = params.get('uAddres') platformId = hallconf.getPublicConf('platformId', None) if platformId: parasDict['platform_id'] = platformId if parasDict['exchange_type'] == 5: parasDict['wxappid'] = params.get('wxappid', '') # 微信红包需要 if parasDict['exchange_type'] == 6: parasDict['user_province'] = params.get('uProvince') parasDict['user_city'] = params.get('uCity') parasDict['user_district'] = params.get('uDistrict') parasDict['user_town'] = params.get('uTown') parasDict['jd_product_id'] = params.get('jdProductId', '') gdssUrl = hallconf.getItemConf().get( 'exchangeGdssUrl', 'http://gdss.touch4.me/?act=api.propExchange') from poker.util import webpage try: hbody, _ = webpage.webgetGdss(gdssUrl, parasDict) resJson = json.loads(hbody) except: ftlog.exception() raise TYExchangeRequestError() retcode = resJson.get('retcode', -1) retmsg = resJson.get('retmsg', '兑换请求出错') if retcode != 1: raise TYExchangeRequestError(retmsg) record.state = TYExchangeRecord.STATE_AUDIT rStr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, rStr) ftlog.info('requestExchange', 'userId=', userId, 'exchangeId=', exchangeId, 'itemId=', item.itemId, 'itemKindId=', item.kindId, 'retcode=', retcode, 'retmsg=', retmsg) return record, retmsg
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)