Skip to content

Commit

Permalink
修复因页面调整不能签到的问题. Fix CaoZ#76.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoZ committed Jan 13, 2019
1 parent 437b80b commit 9676afa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
42 changes: 10 additions & 32 deletions app/job/bean_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import json
import random

from .common import RequestError
from .daka import Daka

Expand All @@ -12,10 +9,9 @@ class BeanApp(Daka):
job_name = '京东客户端签到领京豆'

index_url = 'https://bean.m.jd.com'
info_url = 'https://api.m.jd.com/client.action?functionId=queryBeanIndex'
sign_url = 'https://api.m.jd.com/client.action?functionId=signBeanStart'
info_url = 'https://api.m.jd.com/client.action?functionId=findBeanIndex'
sign_url = 'https://api.m.jd.com/client.action?functionId=signBeanIndex'
test_url = 'https://home.m.jd.com'
poker_url = 'https://api.m.jd.com/client.action?functionId=getCardResult'

client_info = {
'client': 'ld',
Expand All @@ -29,8 +25,8 @@ def is_signed(self):
self.logger.error('签到信息获取失败: {}'.format(e.message))
return False

# 根据测试, 2 表示已签到, 4 表示未签到, 5 表示未登录
signed = (data['status'] == '2')
# 根据测试, 1 表示已签到, 2 表示未签到, 3 表示未登录
signed = (data['status'] == '1')
sign_days = int(data['continuousDays'])
beans_count = int(data['totalUserBean'])

Expand All @@ -45,35 +41,17 @@ def sign(self):
return False

sign_success = (data['status'] == '1')
message = data['signShowBean']['signText']
message = message.replace('signAward', data['signShowBean']['signAward'])
self.logger.info('签到成功: {}; Message: {}'.format(sign_success, message))

if 'awardList' in data['signShowBean']:
# "complated": 原文如此, 服务端的拼写错误...
poker_picked = data['signShowBean']['complated']
if sign_success:
bean_count = data['dailyAward']['beanAward']['beanCount']
message = '获得京豆 {} 个.'.format(bean_count)
else:
message = data['dailyAward']['title']

if not poker_picked:
pick_success = self.pick_poker(data['signShowBean'])
# 同时成功才视为签到成功
sign_success &= pick_success
self.logger.info('签到成功: {}; Message: {}'.format(sign_success, message))

return sign_success

def pick_poker(self, poker):
poker_to_pick = random.randint(1, len(poker['awardList']))

try:
payload = {'body': json.dumps({'index': poker_to_pick})}
data = self.fetch_data(self.poker_url, payload=payload)
except RequestError as e:
self.logger.error('翻牌失败: {}'.format(e.message))
return False

message = data['signText'].replace('signAward', data['signAward'])
self.logger.info('翻牌成功: {}'.format(message))
return True

def fetch_data(self, url, payload=None):
payload = {**payload, **self.client_info} if payload else self.client_info

Expand Down
2 changes: 1 addition & 1 deletion app/job/daka.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run(self):
def is_login(self):
r = self.session.get(self.test_url, allow_redirects=False)

if r.is_redirect and 'passport' in r.headers['Location']:
if r.is_redirect and '/login' in r.headers['Location']:
return False
else:
return True
Expand Down

0 comments on commit 9676afa

Please sign in to comment.