# -*- coding: utf-8 -*-
import requests
import re
import json

default_timeout = 10

class Chaojt():
    def __init__(self):
        self.header = { 
                    'Accept-Encoding': 'gzip',
                    'Connection': 'Keep-Alive',
                    'Host': 'tao.lexiangquan.com',
                    'User-Agent': 'com.lexiangquan.supertao/1.9.0 (Linux; U; Android 4.4.2; zh-cn)',
                    'Accept': 'application/json; q=0.5',
                    'X-CHANNEL': 'huawei',
                    'X-TIMESTAMP': '1509949382391',
                    'UA-INFO': '<KEY>
                    'X-CID': 'a251f10b37552d311adf5c425a23e5ab',
                    'X-TOKEN': '6<PASSWORD>',
                    'X-M': 'm_37ba4060168cdc98fa3de07fc2566b94'
                    }
                 
    # 模拟 http 请求
    def httpRequest(self, method, action, query=None, urlencoded=None, callback=None, timeout=None):
        if (method == 'GET'):
            ## url = action if (query == None) else (action + '?' + query)
            connection = requests.get(action, headers=self.header, timeout=default_timeout, params=query)

        elif (method == 'POST'):
            connection = requests.post(
                action,
                data=query,
                headers=self.header,
                timeout=default_timeout
            )

        connection.encoding = "UTF-8"
        connection = json.loads(connection.text)
        return connection
                 
    # 登录
    def login(self, username, password):
        action = 'http://tao.lexiangquan.com/?act=login'
        data = {
            'm': username,
            'p': password,
            'ClientID': 'a151f10b37552d311adf5c425a23e5ab'
        }
        return self.httpRequest('POST', action, data)
        # try:
        #     return self.httpRequest('POST', action, data)
        # except Exception as e:
        #     print('except:', e)
        #     return {'code': 501}
            

CJT = Chaojt()

data = CJT.httpRequest('GET', 'http://tao.lexiangquan.com/?act=shake&op=index', '')
print(str(data))
print('=' * 50)

prizeId = str(data['data']['prizeInfo']['prizeId'])

print('prizeId=%s' % prizeId)
data = CJT.httpRequest('GET', 'http://tao.lexiangquan.com/?act=shake&op=receive&prize_id=' + prizeId, '')
print(str(data))
print('=' * 50)

# data = CJT.login('13656178592','<PASSWORD>')
# if data['code']==0:
#     print('登录成功， Id：'+str(data['data']['uid']))
#     print(str(data))
#     print('=' * 50)

#     data = CJT.httpRequest('POST', 'http://tao.lexiangquan.com/?act=shake&op=index', '')
#     print(str(data))
#     print('=' * 50)
    

# else:
#     print('登录错误，错误Code：'+str(data['code']))

# -*- coding: utf-8 -*-
import requests
import re
import json

default_timeout = 10

class Chaojt():
    def __init__(self):
        self.header = { 
                    'Accept-Encoding': 'gzip',
                    'Connection': 'Keep-Alive',
                    'Host': 'tao.lexiangquan.com',
                    'User-Agent': 'com.lexiangquan.supertao/1.9.0 (Linux; U; Android 4.4.2; zh-cn)',
                    'Accept': 'application/json; q=0.5',
                    'X-CHANNEL': 'huawei',
                    'X-TIMESTAMP': '1509949382391',
                    'UA-INFO': '<KEY>
                    'X-CID': 'a251f10b37552d311adf5c425a23e5ab',
                    'X-TOKEN': '6<PASSWORD>',
                    'X-M': 'm_37ba4060168cdc98fa3de07fc2566b94'
                    }
                 
    # 模拟 http 请求
    def httpRequest(self, method, action, query=None, urlencoded=None, callback=None, timeout=None):
        if (method == 'GET'):
            ## url = action if (query == None) else (action + '?' + query)
            connection = requests.get(action, headers=self.header, timeout=default_timeout, params=query)

        elif (method == 'POST'):
            connection = requests.post(
                action,
                data=query,
                headers=self.header,
                timeout=default_timeout
            )

        connection.encoding = "UTF-8"
        connection = json.loads(connection.text)
        return connection
                 
    # 登录
    def login(self, username, password):
        action = 'http://tao.lexiangquan.com/?act=login'
        data = {
            'm': username,
            'p': password,
            'ClientID': 'a151f10b37552d311adf5c425a23e5ab'
        }
        return self.httpRequest('POST', action, data)
        # try:
        #     return self.httpRequest('POST', action, data)
        # except Exception as e:
        #     print('except:', e)
        #     return {'code': 501}
            

CJT = Chaojt()

data = CJT.httpRequest('GET', 'http://tao.lexiangquan.com/?act=shake&op=index', '')
print(str(data))
print('=' * 50)

prizeId = str(data['data']['prizeInfo']['prizeId'])

print('prizeId=%s' % prizeId)
data = CJT.httpRequest('GET', 'http://tao.lexiangquan.com/?act=shake&op=receive&prize_id=' + prizeId, '')
print(str(data))
print('=' * 50)

# data = CJT.login('13656178592','<PASSWORD>')
# if data['code']==0:
#     print('登录成功， Id：'+str(data['data']['uid']))
#     print(str(data))
#     print('=' * 50)

#     data = CJT.httpRequest('POST', 'http://tao.lexiangquan.com/?act=shake&op=index', '')
#     print(str(data))
#     print('=' * 50)
    

# else:
#     print('登录错误，错误Code：'+str(data['code']))

# -*- coding: utf-8 -*- # 模拟 http 请求 ## url = action if (query == None) else (action + '?' + query) # 登录 # try: #     return self.httpRequest('POST', action, data) # except Exception as e: #     print('except:', e) #     return {'code': 501} # data = CJT.login('13656178592','<PASSWORD>') # if data['code']==0: #     print('登录成功， Id：'+str(data['data']['uid'])) #     print(str(data)) #     print('=' * 50) #     data = CJT.httpRequest('POST', 'http://tao.lexiangquan.com/?act=shake&op=index', '') #     print(str(data)) #     print('=' * 50) # else: #     print('登录错误，错误Code：'+str(data['code']))