Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
def addUserCredit(userId, productId, rmbs):
    """
    增加用户微信公众号积分商城积分
    """
    # 玩家每充值1元,增加10积分
    if gdata.mode() == gdata.RUN_MODE_ONLINE:
        requestUrl = "http://wx.dnale4.cn/"
    else:
        requestUrl = "http://wxtest.tuyoo.com/"
    response = None
    try:
        params = {
            "act": "xxfishpoint.xxfishHandel",
            "type": 1,
            "typename": u"游戏充值",
            "account_num": rmbs * 10,
            "user_id": userId
        }
        params["code"] = util.httpParamsSign(params)
        response, _ = webpage.webget(requestUrl, querys=params, method_="GET")
        response = json.loads(response)
        if response.get("code") != 0:
            ftlog.error("addUserCredit->error", "userId=", userId,
                        "productId=", productId, "rmbs=", rmbs, "response=",
                        response)
        else:
            ftlog.info("addUserCredit->success", "userId=", userId,
                       "productId=", productId, "rmbs=", rmbs, "response=",
                       response)
    except:
        ftlog.error("addUserCredit->error", "userId=", userId, "productId=",
                    productId, "rmbs=", rmbs, "response=", response)
Ejemplo n.º 4
0
def _requestSdk2(path, params, needresponse=False):
    url = '%s%s' % (gdata.httpSdkInner(), path)
    jsonstr, _ = webpage.webget(url, postdata_=params, needresponse=needresponse)
    if needresponse:
        try:
            return strutil.loads(jsonstr)
        except:
            ftlog.error('SDKURL=', url, 'PARAMS=', params)
    return None
Ejemplo n.º 5
0
 def _requestCode(self):
     response, _ = webpage.webget('https://0x3.me/apis/authorize/getCode', method_='GET')
     status, info, data = self._validResponse(response)
     if ftlog.is_debug():
         ftlog.debug('ShortUrlx3me._requestCode',
                     'response=', response)
     if status != 1:
         ftlog.warn('ShortUrlx3me._requestCode',
                    'response=', response)
         raise TYBizException(-1, '%s:%s' % (status, info))
     return data
Ejemplo n.º 6
0
def _requestSdk2(path, params, needresponse=False):
    url = '%s%s' % (gdata.httpSdkInner(), path)
    jsonstr, _ = webpage.webget(url,
                                postdata_=params,
                                needresponse=needresponse)
    if needresponse:
        try:
            return strutil.loads(jsonstr)
        except:
            ftlog.error('SDKURL=', url, 'PARAMS=', params)
    return None
Ejemplo n.º 7
0
def _requestSdkUrl(url, params, needresponse=False):
    params['code'] = _sign(params)
    jsonstr, _ = webpage.webget(url, postdata_=params, needresponse=needresponse)
    if needresponse:
        try:
            data = strutil.loads(jsonstr)
            return data['result']
        except:
            ftlog.error()
            return BAD_RESPONSE
    return None
Ejemplo n.º 8
0
 def _requestTokenWithCode(self, code):
     timestr = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     params = {'api_key':self.apiKey, 'code':code, 'request_time':timestr}
     params['sign'] = self._calcSign(params)
     response, _ = webpage.webget('https://0x3.me/apis/authorize/getAccessToken', postdata_=params, method_='POST')
     status, info, data = self._validResponse(response)
     if status != 1:
         ftlog.warn('ShortUrlx3me._requestTokenWithCode',
                    'code=', code,
                    'response=', response)
         raise TYBizException(-1, '%s:%s' % (status, info))
     return data['access_token'], int(data['expire_timestamp'])
Ejemplo n.º 9
0
    def _getShorUrl(self, longUrl):
        if not self.token:
            ftlog.warn('ShortUrlx3me._getShorUrl',
                       'err=', 'NoToken')
            return longUrl
        
        response, _ = webpage.webget('https://0x3.me/apis/urls/add', postdata_={'access_token':self.token, 'longurl':longUrl}, method_='POST')
        status, info, data = self._validResponse(response)
        if status != 1:
            raise TYBizException(-1, '%s:%s' % (status, info))

        return data['short_url']
Ejemplo n.º 10
0
def _requestSdkUrl(url, params, needresponse=False):
    params['code'] = _sign(params)
    jsonstr, _ = webpage.webget(url,
                                postdata_=params,
                                needresponse=needresponse)
    if needresponse:
        try:
            data = strutil.loads(jsonstr)
            return data['result']
        except:
            ftlog.error()
            return BAD_RESPONSE
    return None
Ejemplo n.º 11
0
def http7Mgetlivedata():
    # 实时比分

    contents = {}

    _status_uri = http7muri() + '?type=getlivedata'

    try:
        hbody, httpurl = webpage.webget(_status_uri, method_='GET')
        contents = json.loads(hbody)
    except Exception, e:
        ftlog.warn('http7Mgetlivedata except', '_status_uri=', _status_uri,
                   'warn=', e.message)
Ejemplo n.º 12
0
def http7Mgethdaoddsinfo(matchId):
    # 欧盘指数

    contents = {}

    _cid_uri = http7muri() + '?type=gethdaoddsinfo&gameid=%s'

    try:
        hbody, httpurl = webpage.webget(_cid_uri % matchId, method_='GET')
        contents = json.loads(hbody)
    except Exception, e:
        ftlog.warn('http7Mgethdaoddsinfo except', '_cid_uri=', _cid_uri,
                   'matchId=', matchId, 'warn=', e.message)
Ejemplo n.º 13
0
 def _getJdAddress(self, url, keyTuple, *retfilters):
     from poker.util import webpage
     resp, _ = webpage.webget(
         url, {keyTuple[0]: keyTuple[1]} if keyTuple[0] else {},
         connect_timeout=6,
         timeout=6,
         retrydata={'max': 3})
     if resp:
         resp = strutil.loads(resp)
         retcode = resp.get('retcode', -1)
         if retcode in retfilters:
             return self.JD_ADDRESS_RET_CODE_HANDLE[retcode](resp['retmsg'])
     raise Exception('ret error', resp)  # 抛出异常,从而不缓存
Ejemplo n.º 14
0
 def _requestSdkUrl(cls, url, params, needresponse=False):
     params['code'] = cls._sign(params)
     jsonstr, _ = webpage.webget(url,
                                 postdata_=params,
                                 needresponse=needresponse)
     if needresponse:
         try:
             data = strutil.loads(jsonstr)
             return data['result']
         except:
             ftlog.error()
             return ErrorEnum.ERR_UNKNOWN
     return None
Ejemplo n.º 15
0
    def getRedEnvelopeCode(cls, userId, gameId, exchangeMoney, roomId, instId, rank):
        '''
        获取红包口令
        '''
        try:

            params = {
                "userId": userId,
                "gameId": gameId,
                "money": exchangeMoney,
                "matchId": instId or "",
                "roomId": roomId or "",
                "rank": rank or ""
            }
            sign = cls.signParams(params)
            params['sign'] = sign
            exchangeCode = None
            jsonstr, _ = webpage.webget(cls.REQUEST_URL, querys=params, method_='GET')
            data = None
            if jsonstr:
                data = strutil.loads(jsonstr)
                if data['retcode'] == 1:
                    exchangeCode = data['retmsg']
            ftlog.info('RedEnvelopeHelper.getRedEnvelopeCode:',
                       'userId=', userId,
                       'exchangeMoney=', exchangeMoney,
                       'gameId=', gameId,
                       'roomId=', roomId,
                       'instId=', instId,
                       'rank=', rank,
                       'data=', data,
                       'jsonstr=', jsonstr,
                       'params=', params,
                       'sign=', sign)


            return exchangeCode

        except Exception, e:
            ftlog.error('RedEnvelopeHelper.getRedEnvelopeCode:',
                        'userId=', userId,
                        'exchangeMoney=', exchangeMoney,
                        'gameId=', gameId,
                        'roomId=', roomId,
                        'instId=', instId,
                        'rank=', rank,
                        'err=', e.message)
            return None
Ejemplo n.º 16
0
def _sendHttpMessage(params, needresponse=True):
    if params:
        jsonstr, _ = webpage.webget(_serverUrl,
                                    postdata_=params,
                                    needresponse=needresponse)
        if ftlog.is_debug():
            ftlog.debug('JiGuangPush._sendHttpMessage', 'url=', _serverUrl,
                        'params=', params, 'res=', jsonstr)
        if needresponse:
            try:
                data = strutil.loads(jsonstr)
                return data['code']
            except Exception, e:
                ftlog.error('JiGuangPush._sendHttpMessageError=', e.message)
                return BAD_RESPONSE
            return None
Ejemplo n.º 17
0
def http7Mgetschedulebydate(dateStr):
    # 赛程赛果

    contents = {}

    _match_uri = http7muri() + '?type=getschedulebydate&date=%s'

    hbody = 'test'
    try:
        hbody, httpurl = webpage.webget(_match_uri % dateStr, method_='GET')
        ftlog.info('http7Mgetschedulebydate webget', 'hbody=', hbody,
                   'httpurl=', httpurl)

        contents = json.loads(hbody)
    except Exception, e:
        ftlog.warn('http7Mgetschedulebydate except', 'dateStr=', dateStr,
                   '_match_uri=', _match_uri, 'hbody=', hbody, 'warn=',
                   e.message)
Ejemplo n.º 18
0
    def _doLogin(self):
        loginur = gdata.httpSdkInner() + '/open/v3/user/processSnsId'
        params = {'svninfo': '$robot$',
                  'appId': str(self.gameId),
                  'ty_bindmobile': '',
                  'phoneType': '',
                  'imei': ['Xb6tiNAVcw5eLrd1F4JTW2dnDrGNr3P0EXl2x99NUeVYGHCQB6ECeQ=='],
                  'iccid': ['RcjQJPkcLGfazgYaKJGWd8hTMfWp8OVr86NEoHuo1C0fIaCKUsTAhuB7huInoqWf'],
                  'androidId': ['BwyJv/PH1UCPjZDob4BSPgiwpuTq4dYgt1OFMrAoLJTED4oxlxdnEtuXKiOJxpkV'],
                  'snsToken': '',
                  'mac': ['wn+rGmlh6/AG6S6O+7kew0ZaMHsfR0LstUtr/WOvXtX681nrM5c+406L0PvY3P7W'],
                  'ty_uid': '0',
                  'clientId': self.clientId,
                  'deviceName': self.name,
                  'snsId': strutil.tyDesEncode(self.snsId),
                  'deviceId': ''
                  }
        sigstr = ''
        pkeys = params.keys()
        pkeys.sort()
        for k in pkeys:
            sigstr = sigstr + str(k) + '=' + str(params[k]) + '&'
        sigstr = sigstr[:-1]
        code = strutil.md5digest(strutil.tyDesEncode(sigstr))
        params['code'] = code

        userInfo, _ = webpage.webget(loginur, params)
        userInfo = strutil.loads(userInfo, ignoreException=True, execptionValue=userInfo)
        if not isinstance(userInfo, dict):
            ftlog.warn('snsId=', self.snsId, 'login-> return error !', userInfo)
            self.stop()
            return
        if self.isbusy == 0:  # 已经关闭
            return

        ftlog.debug('snsId=', self.snsId, 'login->', userInfo)

        result = userInfo.get('result', {})
        self.userId = result.get('userId', 0)
        if not isinstance(self.userId, int) or self.userId < 0:
            raise Exception('robot user login false !' + self.snsId)
        ftlog.debug('Robot login ok snsId=', self.snsId, 'userId=', self.userId)
        self.userInfo = result
        self.checkState(CMD_LOGIN)
Ejemplo n.º 19
0
    def sendSms(self, mobile, content):
        content = content + '【在线途游】'
        content = unicode(content, 'utf8')
        content = content.encode('utf8')

        querys = {
            'sn': self.sn,
            'pwd': self.pwd,
            'mobile': mobile,
            'content': content,
        }

        surl = self.smsurl + strutil.urlencode(querys)

        response, _ = webpage.webget(surl)
        response = str(response).strip()
        if response[0] == '-':
            return False
        return True
Ejemplo n.º 20
0
    def sendSms(self, mobile, content):
        content = content + '【在线途游】'

        querys = {
            'sname': 'dlzxty00',
            'spwd': '18lJsdrv',
            'scorpid': '',
            'sprdid': '1012818',
            'sdst': str(mobile),
            'smsg': content
        }

        # 不用post会500错误
        response, _ = webpage.webget(self.smsurl, postdata_=querys)
        xmlroot = ElementTree.fromstring(response)
        state = xmlroot.find('{http://tempuri.org/}State').text
        if int(state) != 0:
            return False
        return True
Ejemplo n.º 21
0
def _get_web(params, url=None):
    """http调用代理后台底层接口"""

    card_type = params['cardType']
    if not url:
        url = get_url_by_card_type(card_type)

    response = {}
    has_error = True

    for i in range(3):
        try:
            response, _ = webpage.webget(url,
                                         params,
                                         appKey="sales.shediao.com-api-",
                                         appKeyTail="-sales.shediao.com-api",
                                         codeKey='sign',
                                         filterParams=['act'],
                                         connector='',
                                         connect_timeout=10,
                                         timeout=10)
            if response is None:
                ftlog.error("webget response is None|retry:", i,
                            "|url, params:", url, params)
                continue

            has_error = False
            break
        except Exception as e:
            ftlog.error("webget Exception|url, params:", url, params)

    if has_error:
        return -10, "网络异常导致购买失败,请联系客服"

    if DEBUG:
        ftlog.info("webget |url, params:", url, params, "|response:", response)

    response = strutil.loads(response)

    return response['retcode'], response['retmsg']
Ejemplo n.º 22
0
def getShortUrlNew(longUrl, expTime=-1):
    '''
    调用新的短链接API
    expTime :整数,单位:秒,短连接的有效时间,超出这个时间后,生成的短链接将被删除
                小于0或其他非数字则永久保留,若无则只保存一周
    :return: shortUrl
    例子:
    http://shorturl.ywdier.com/api/shorturl/make?expTime=0&longUrl=http://ddz.dl.tuyoo.com/cdn37/hall/item/imgs/coupon.png
    '''
    headUrl = 'http://shorturl.ywdier.com/api/shorturl/make' # 抛弃IP使用内网域名的方式 ZQH
    params = {
        'expTime': expTime,
        'longUrl': longUrl
    }

    response, _ = webpage.webget(headUrl, querys=params, method_='GET')
    if not response:
        ftlog.warn('hall_short_url.getShortUrlNew error= no response',
                   'headUrl=', headUrl,
                   'params=', params)
        return longUrl
    datas = strutil.loads(response)

    if ftlog.is_debug():
        ftlog.debug('longUrlToShort.ShortUrlx3me._getShorUrl',
                    'longUrl=', longUrl,
                    'headUrl=', headUrl,
                    'method_=', 'GET',
                    'response=', response,
                    'datas=', datas)

    if 'error' in datas:
        ftlog.warn('hall_short_url.getShortUrlNew error=', datas.get('error'),
                   'headUrl=', headUrl)
        return longUrl
    shortUrl = datas.get('url')
    return shortUrl if shortUrl else longUrl
Ejemplo n.º 23
0
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
Ejemplo n.º 24
0
    def _doLogin(self):
        loginur = gdata.httpSdkInner() + '/open/v3/user/processSnsId'
        params = {
            'svninfo':
            '$robot$',
            'appId':
            str(self.gameId),
            'ty_bindmobile':
            '',
            'phoneType':
            '',
            'imei':
            ['Xb6tiNAVcw5eLrd1F4JTW2dnDrGNr3P0EXl2x99NUeVYGHCQB6ECeQ=='],
            'iccid': [
                'RcjQJPkcLGfazgYaKJGWd8hTMfWp8OVr86NEoHuo1C0fIaCKUsTAhuB7huInoqWf'
            ],
            'androidId': [
                'BwyJv/PH1UCPjZDob4BSPgiwpuTq4dYgt1OFMrAoLJTED4oxlxdnEtuXKiOJxpkV'
            ],
            'snsToken':
            '',
            'mac': [
                'wn+rGmlh6/AG6S6O+7kew0ZaMHsfR0LstUtr/WOvXtX681nrM5c+406L0PvY3P7W'
            ],
            'ty_uid':
            '0',
            'clientId':
            self.clientId,
            'deviceName':
            self.name,
            'snsId':
            strutil.tyDesEncode(self.snsId),
            'deviceId':
            ''
        }
        sigstr = ''
        pkeys = params.keys()
        pkeys.sort()
        for k in pkeys:
            sigstr = sigstr + str(k) + '=' + str(params[k]) + '&'
        sigstr = sigstr[:-1]
        code = strutil.md5digest(strutil.tyDesEncode(sigstr))
        params['code'] = code

        userInfo, _ = webpage.webget(loginur, params)
        userInfo = strutil.loads(userInfo,
                                 ignoreException=True,
                                 execptionValue=userInfo)
        if not isinstance(userInfo, dict):
            ftlog.warn('snsId=', self.snsId, 'login-> return error !',
                       userInfo)
            self.stop()
            return
        if self.isbusy == 0:  # 已经关闭
            return

        ftlog.debug('snsId=', self.snsId, 'login->', userInfo)

        result = userInfo.get('result', {})
        self.userId = result.get('userId', 0)
        if not isinstance(self.userId, int) or self.userId < 0:
            raise Exception('robot user login false !' + self.snsId)
        ftlog.debug('Robot login ok snsId=', self.snsId, 'userId=',
                    self.userId)
        self.userInfo = result
        self.checkState(CMD_LOGIN)
Ejemplo n.º 25
0
 def _post(cls, url, headers, body):
     ftlog.debug('HttpPostRequest._post:begin', 'url=', url, 'headers=',
                 headers, 'body=', body)
     jsonstr, _ = webpage.webget(url, headers_=headers, postdata_=body)
     ftlog.debug('HttpPostRequest._post:end', 'jsonstr=', jsonstr)
     return jsonstr
Ejemplo n.º 26
0
 def _get(cls, url, querys):
     ftlog.debug('HttpGetRequest._get:begin', 'url=', url, 'querys=',
                 querys)
     jsonstr, _ = webpage.webget(url, querys=querys, method_='GET')
     ftlog.debug('HttpGetRequest._get:end', 'jsonstr=', jsonstr)
     return jsonstr