예제 #1
0
def verify_login(token, ssoid):
    """
    登录校验
    """
    parameters = {'fileId': ssoid, 'token': token}
    url = QUERY_URL + '?' + urllib.urlencode(parameters)
    oauthTimestamp = xtime.timestamp(1000)
    oauthNonce = xtime.timestamp() + xrand.randomint(0, 9)
    base_str = urllib.urlencode({'oauthConsumerKey': APP_KEY}) + '&'
    base_str += urllib.urlencode({'oauthToken': token}) + '&'
    base_str += urllib.urlencode({'oauthSignatureMethod': 'HMAC-SHA1'}) + '&'
    base_str += urllib.urlencode({'oauthTimestamp': oauthTimestamp}) + '&'
    base_str += urllib.urlencode({'oauthNonce': oauthNonce}) + '&'
    base_str += urllib.urlencode({'oauthVersion': '1.0'}) + '&'
    oauthSignature = APP_SECRET + '&'
    sign = hmac.new(oauthSignature, base_str,
                    hashlib.sha1).digest().encode('base64').rstrip()

    sign = urllib.urlencode({'': sign})[1:]
    result = request_url(url, {'param': base_str, 'oauthSignature': sign})
    if result:
        js = json.loads(result)
        if js["resultCode"] == '200' and js["ssoid"] == ssoid:
            return js

    logger.error(result)
    return None
예제 #2
0
 def present_m(self, platform, openid, pay_appid, pay_appkey, access_token, pay_token, pf, pfkey, zoneid, discountid, giftid, presenttimes):
     """ 直接赠接口,可以用于赠送充值币
     @return: example,
     {"ret":0}
     ret:返回码
     """
     uri = '/mpay/present_m'
     cookie = common.create_cookie(platform, uri)
     params = {
               'openid':openid,
               'openkey':access_token,
               'pay_token':pay_token,
               'appid':pay_appid,
               'ts':xtime.timestamp(),
               'pf':pf,
               'pfkey':pfkey,
               'zoneid':zoneid,
               'discountid': discountid,
               'giftid': giftid,
               'presenttimes': presenttimes,
               'format':'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri), en_params, cookie, method=method)
     return result
예제 #3
0
 def pay_m(self, platform, openid, pay_appid, pay_appkey, access_token,
           pay_token, pf, pfkey, zoneid, amt):
     """ 扣除用户充值币
     @return: example,
     {"ret" : 0,"billno" : "20102","balance":200}
     ret:返回码
     billno:预扣流水号
     balance:预扣后的余额
     """
     uri = '/mpay/pay_m'
     cookie = common.create_cookie(platform, uri)
     params = {
         'openid': openid,
         'openkey': access_token,
         'pay_token': pay_token,
         'appid': pay_appid,
         'ts': xtime.timestamp(),
         'pf': pf,
         'pfkey': pfkey,
         'zoneid': zoneid,
         'amt': amt,
         'format': 'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri),
                                en_params,
                                cookie,
                                method=method)
     return result
예제 #4
0
 def present_m(self, platform, openid, pay_appid, pay_appkey, access_token,
               pay_token, pf, pfkey, zoneid, discountid, giftid,
               presenttimes):
     """ 直接赠接口,可以用于赠送充值币
     @return: example,
     {"ret":0}
     ret:返回码
     """
     uri = '/mpay/present_m'
     cookie = common.create_cookie(platform, uri)
     params = {
         'openid': openid,
         'openkey': access_token,
         'pay_token': pay_token,
         'appid': pay_appid,
         'ts': xtime.timestamp(),
         'pf': pf,
         'pfkey': pfkey,
         'zoneid': zoneid,
         'discountid': discountid,
         'giftid': giftid,
         'presenttimes': presenttimes,
         'format': 'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri),
                                en_params,
                                cookie,
                                method=method)
     return result
예제 #5
0
 def get_balance_m(self, platform, openid, pay_appid, pay_appkey,
                   access_token, pay_token, pf, pfkey, zoneid):
     """ 获取用户充值币余额
     @return: example,
     {"ret":0,"balance":200,"gen_balance":0, "first_save":1}
     ret:返回码
     balance:充值币个数(包含了赠送充值币)
     gen_balance:赠送充值币个数
     first_save:是否满足首次充值,1:满足,0:不满足。
     """
     uri = '/mpay/get_balance_m'
     cookie = common.create_cookie(platform, uri)
     print cookie, "cookie============"
     params = {
         'openid': openid,
         'openkey': access_token,
         'pay_token': pay_token,
         'appid': pay_appid,
         'ts': xtime.timestamp(),
         'pf': pf,
         'pfkey': pfkey,
         'zoneid': zoneid,
         'format': 'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri),
                                en_params,
                                cookie,
                                method=method)
     return result
예제 #6
0
 def cancel_pay_m(self, platform, openid, pay_appid, pay_appkey, access_token, pay_token, pf, pfkey, zoneid, amt, billno):
     """ 退款
     @return: example,
     {"ret":0}
     ret:返回码
     """
     uri = '/mpay/cancel_pay_m'
     cookie = common.create_cookie(platform, uri)
     params = {
               'openid':openid,
               'openkey':access_token,
               'pay_token':pay_token,
               'appid':pay_appid,
               'ts':xtime.timestamp(),
               'pf':pf,
               'pfkey':pfkey,
               'zoneid':zoneid,
               'amt': amt,
               'billno': billno,
               'format':'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri), en_params, cookie, method=method)
     return result
예제 #7
0
 def cancel_pay_m(self, platform, openid, pay_appid, pay_appkey,
                  access_token, pay_token, pf, pfkey, zoneid, amt, billno):
     """ 退款
     @return: example,
     {"ret":0}
     ret:返回码
     """
     uri = '/mpay/cancel_pay_m'
     cookie = common.create_cookie(platform, uri)
     params = {
         'openid': openid,
         'openkey': access_token,
         'pay_token': pay_token,
         'appid': pay_appid,
         'ts': xtime.timestamp(),
         'pf': pf,
         'pfkey': pfkey,
         'zoneid': zoneid,
         'amt': amt,
         'billno': billno,
         'format': 'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri),
                                en_params,
                                cookie,
                                method=method)
     return result
예제 #8
0
 def buy_goods_m(self, platform, openid, pay_appid, pay_appkey, access_token, pay_token, pf, pfkey, zoneid, payitem, goodsmeta, goodsurl, appmode=1):
     """ 直接赠接口,可以用于赠送充值币
     @return: example,
     {"ret":0}
     ret:返回码
     """
     uri = '/mpay/buy_goods_m'
     cookie = common.create_cookie(platform, uri)
     params = {
               'openid':openid,
               'openkey':access_token,
               'pay_token':pay_token,
               'appid':pay_appid,
               'ts':xtime.timestamp(),
               'pf':pf,
               'pfkey':pfkey,
               'zoneid':zoneid,
               'payitem': payitem,
               'goodsmeta': goodsmeta,
               'goodsurl': goodsurl,
               'appmode': appmode,
               'format':'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri), en_params, cookie, method=method)
     return result
예제 #9
0
 def pay_m(self, platform, openid, pay_appid, pay_appkey, access_token, pay_token, pf, pfkey, zoneid, amt):
     """ 扣除用户充值币
     @return: example,
     {"ret" : 0,"billno" : "20102","balance":200}
     ret:返回码
     billno:预扣流水号
     balance:预扣后的余额
     """
     uri = '/mpay/pay_m'
     cookie = common.create_cookie(platform, uri)
     params = {
               'openid':openid,
               'openkey':access_token,
               'pay_token':pay_token,
               'appid':pay_appid,
               'ts':xtime.timestamp(),
               'pf':pf,
               'pfkey':pfkey,
               'zoneid':zoneid,
               'amt': amt,
               'format':'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri), en_params, cookie, method=method)
     return result
예제 #10
0
 def get_balance_m(self, platform, openid, pay_appid, pay_appkey, access_token, pay_token, pf, pfkey, zoneid):
     """ 获取用户充值币余额
     @return: example,
     {"ret":0,"balance":200,"gen_balance":0, "first_save":1}
     ret:返回码
     balance:充值币个数(包含了赠送充值币)
     gen_balance:赠送充值币个数
     first_save:是否满足首次充值,1:满足,0:不满足。
     """
     uri = '/mpay/get_balance_m'
     cookie = common.create_cookie(platform, uri)
     print cookie, "cookie============"
     params = {
               'openid':openid,
               'openkey':access_token,
               'pay_token':pay_token,
               'appid':pay_appid,
               'ts':xtime.timestamp(),
               'pf':pf,
               'pfkey':pfkey,
               'zoneid':zoneid,
               'format':'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri), en_params, cookie, method=method)
     return result
예제 #11
0
 def guest_request(self, openid, path, data):
     """
     按照规定格式执行游客登录请求
     """
     timestamp = xtime.timestamp()
     sig = xid.md5(str(self.appkey) + str(timestamp))
     parmameters = {'timestamp':timestamp, 'appid':"G_%s"%self.appid, 'sig':sig, 'openid':openid, 'encode':1}
     url = 'http://%s/%s' % (self.host, path + urllib.urlencode(parmameters))
     return self.http.request(url, json.dumps(data))
예제 #12
0
 def guest_request(self, openid, path, data):
     """
     按照规定格式执行游客登录请求
     """
     timestamp = xtime.timestamp()
     sig = xid.md5(str(self.appkey) + str(timestamp))
     parmameters = {
         'timestamp': timestamp,
         'appid': "G_%s" % self.appid,
         'sig': sig,
         'openid': openid,
         'encode': 1
     }
     url = 'http://%s/%s' % (self.host,
                             path + urllib.urlencode(parmameters))
     return self.http.request(url, json.dumps(data))
예제 #13
0
def verify_login(sid):
    """
    登录校验
    """
    sign = hashlib.md5("sid=%s%s"%(sid,API_KEY)).hexdigest()
    body_data = {'id':xtime.timestamp(),
                 'data':{'sid':sid},
                 'game':{'gameId':GAME_ID},
                 'sign':sign}
    result = request_url(TEST_URL, json.dumps(body_data))
    if result:
        js = json.loads(result)
        if js['id'] == body_data['id'] and js['state']['code'] == 1:
            return js

    logger.error(result)
    return None
예제 #14
0
 def buy_goods_m(self,
                 platform,
                 openid,
                 pay_appid,
                 pay_appkey,
                 access_token,
                 pay_token,
                 pf,
                 pfkey,
                 zoneid,
                 payitem,
                 goodsmeta,
                 goodsurl,
                 appmode=1):
     """ 直接赠接口,可以用于赠送充值币
     @return: example,
     {"ret":0}
     ret:返回码
     """
     uri = '/mpay/buy_goods_m'
     cookie = common.create_cookie(platform, uri)
     params = {
         'openid': openid,
         'openkey': access_token,
         'pay_token': pay_token,
         'appid': pay_appid,
         'ts': xtime.timestamp(),
         'pf': pf,
         'pfkey': pfkey,
         'zoneid': zoneid,
         'payitem': payitem,
         'goodsmeta': goodsmeta,
         'goodsurl': goodsurl,
         'appmode': appmode,
         'format': 'json'
     }
     method = 'get'
     en_params = common.encoding_params(method, uri, params, pay_appkey)
     result = self.http.request(self._new_url(uri),
                                en_params,
                                cookie,
                                method=method)
     return result
예제 #15
0
    def activity_qualification(self, platform, openid, pay_appid, pay_appkey,
                               access_token, pay_token, pf, pfkey, zoneid,
                               req_from):
        """
        活动资格查询接口

        @return: example,
        {"ret" : 0,"first_save" : 0, "wx_pay" : 0, "kj_pay" : 0, "kj_pay" : 0, "qualified" :4, "qualified_info" : "", "is_show_act_page" : 4, "discounttype" : "", "discounturl" : ""}

        ret:返回码
        first_save:int 是否满足首次充值,1:满足,0:不满足。
        wx_pay:int 是否开通微信支付,1:开通,0:未开通。
        kj_pay:int 是否开通快捷支付,1:开通,0:未开通。
        qualified:int 是否有资格, 1:有;2:没有资格;
        qualified_info:string 资格校验信息
        is_show_act_page:int 是否弹出活动页面
        discounttype:string 活动类型,需要传给sdk
        discounturl:string 活动url,需要传给sdk
        """
        req_from = 'InGame' if req_from == 1 else 'Market'
        uri = '/mpay/query_qualify_m'
        cookie = common.create_cookie(platform, uri)
        params = {
            'openid': openid,
            'openkey': access_token,
            'pay_token': pay_token,
            'appid': pay_appid,
            'ts': xtime.timestamp(),
            'pf': pf,
            'pfkey': pfkey,
            'zoneid': zoneid,
            'req_from': req_from,
            'accounttype': 'save',
            'format': 'json'
        }
        method = 'get'
        en_params = common.encoding_params(method, uri, params, pay_appkey)
        result = self.http.request(self._new_url(uri),
                                   en_params,
                                   cookie,
                                   method=method)
        return result
예제 #16
0
def verify_login(sid):
    """
    登录校验
    """
    sign = hashlib.md5("sid=%s%s" % (sid, API_KEY)).hexdigest()
    body_data = {
        'id': xtime.timestamp(),
        'data': {
            'sid': sid
        },
        'game': {
            'gameId': GAME_ID
        },
        'sign': sign
    }
    result = request_url(TEST_URL, json.dumps(body_data))
    if result:
        js = json.loads(result)
        if js['id'] == body_data['id'] and js['state']['code'] == 1:
            return js

    logger.error(result)
    return None
예제 #17
0
    def activity_qualification(self, platform, openid, pay_appid, pay_appkey, access_token, pay_token, pf, pfkey, zoneid, req_from):
        """
        活动资格查询接口

        @return: example,
        {"ret" : 0,"first_save" : 0, "wx_pay" : 0, "kj_pay" : 0, "kj_pay" : 0, "qualified" :4, "qualified_info" : "", "is_show_act_page" : 4, "discounttype" : "", "discounturl" : ""}

        ret:返回码
        first_save:int 是否满足首次充值,1:满足,0:不满足。
        wx_pay:int 是否开通微信支付,1:开通,0:未开通。
        kj_pay:int 是否开通快捷支付,1:开通,0:未开通。
        qualified:int 是否有资格, 1:有;2:没有资格;
        qualified_info:string 资格校验信息
        is_show_act_page:int 是否弹出活动页面
        discounttype:string 活动类型,需要传给sdk
        discounturl:string 活动url,需要传给sdk
        """
        req_from = 'InGame' if req_from==1 else 'Market'
        uri = '/mpay/query_qualify_m'
        cookie = common.create_cookie(platform, uri)
        params = {
                  'openid':openid,
                  'openkey':access_token,
                  'pay_token':pay_token,
                  'appid':pay_appid,
                  'ts':xtime.timestamp(),
                  'pf':pf,
                  'pfkey':pfkey,
                  'zoneid':zoneid,
                  'req_from': req_from,
                  'accounttype': 'save',
                  'format':'json'
        }
        method = 'get'
        en_params = common.encoding_params(method, uri, params, pay_appkey)
        result = self.http.request(self._new_url(uri), en_params, cookie, method=method)
        return result