def saveVideoDataToHttp(userId, gameRound): # 调用http videoId = '%s_%s' % (userId, gameRound.roundId) url = '%s/dizhu/tupt/replay/video/save?videoId=%s' % (gdata.httpGame(), videoId) gameRoundDict = GameRoundCodecDictReplay().encode(gameRound) gameRoundDict['uid'] = userId if ftlog.is_debug(): ftlog.debug('obsystem.saveVideoDataToHttp userId=', userId, 'videoId=', videoId, 'url=', url, 'gameRoundDict=', gameRoundDict) response = None try: _, response = http.runHttp('POST', url, None, strutil.dumps(gameRoundDict), 3, 6) datas = strutil.loads(response) ec = datas.get('ec', 0) if ec == 0: return videoId raise TYBizException(ec, datas.get('info', '')) except TYBizException: raise except: ftlog.error(url, 'response=', response) raise TYBizException(-1, '保存失败')
def executeForbidden(userId, isForbidden): """ 对玩家执行封禁/解除封禁 :return: 0:执行成功 1:执行失败 """ requestUrl = gdata.httpGame() + "/open/v3/user/setForbidden" if isForbidden: postData = {"lock_users": [userId]} else: postData = {"unlock_users": [userId]} try: result = util.doHttpQuery(requestUrl, postData, timeout=3) if result and result.get("error") is None: return 0 except: ftlog.error("executeForbidden error", userId, isForbidden) return 1
def isFollowAccount(userId): """ 是否关注微信公众号 """ followAccount = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.followAccount) if followAccount: return True requestUrl = gdata.httpGame() + "/open/v4/user/act/wx/checkfollowmp" postData = { "userId": userId, "wxgameappid": config.WX_APPID, "wxmpappid": config.WX_MP_APPID } result = util.doHttpQuery(requestUrl, postData) if result and result.get("result", {}).get("follow") is True: gamedata.setGameAttr(userId, FISH_GAMEID, GameData.followAccount, 1) return True return False
def queryForbidden(userId): """ 查询玩家账号是否被封禁 :return: 0:未封禁 1:已封禁 """ requestUrl = gdata.httpGame() + "/open/v4/tools/query_forbidden" signStr = "access_id=wa15b4444ce9d977f4&user_Id=%d:G64RBRAkKh57PR0EWZqsVE5H4GiPKPx7" % userId import hashlib sign = str(hashlib.sha256(signStr).hexdigest().lower()) postData = {"user_Id": userId, "access_id": "wa15b4444ce9d977f4", "sign": sign} try: result = util.doHttpQuery(requestUrl, postData) if result and result.get("result", {}).get("code") == 1: return 1 except: ftlog.error("queryForbidden error", userId) return 0
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 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 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 _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