1
0
mirror of https://github.com/okyyds/yyds.git synced 2026-07-13 22:11:18 +08:00
This commit is contained in:
yyds
2022-02-25 13:42:29 +08:00
parent afc5b097ba
commit 4b57e5c001

View File

@@ -3,7 +3,7 @@
''' '''
感谢Curtin提供的其他脚本供我参考 感谢Curtin提供的其他脚本供我参考
感谢aburd ch大佬的指导 感谢aburd ch大佬的指导
项目名称:jd_health_plant.py 项目名称:xF_jd_health_plant.py
Author: 一风一扬 Author: 一风一扬
功能:健康社区-种植园自动任务 功能:健康社区-种植园自动任务
Date: 2022-1-4 Date: 2022-1-4
@@ -127,35 +127,9 @@ except:
####################################################################### #######################################################################
if "plant_cookie" in os.environ:
if len (os.environ["plant_cookie"]) == 1:
is_ck = int(os.environ["plant_cookie"])
cookie1 = os.environ["JD_COOKIE"].split('&')
cookie = cookie1[is_ck-1]
printT ("已获取并使用Env环境cookie")
elif len (os.environ["plant_cookie"]) > 1:
cookies1 = [] cookies1 = []
cookies1 = os.environ["JD_COOKIE"] cookies1 = os.environ["JD_COOKIE"]
cookies1 = cookies1.split ('&') cookies = cookies1.split ('&')
is_ck = os.environ["plant_cookie"].split('&')
for i in is_ck:
cookies.append(cookies1[int(i)-1])
printT ("已获取并使用Env环境plant_cookies")
else:
if cookie == '':
printT ("变量plant_cookie未填写")
exit (0)
if "charge_targe_id" in os.environ:
if len (os.environ["charge_targe_id"]) > 8:
charge_targe_ids = os.environ["charge_targe_id"]
charge_targe_ids = charge_targe_ids.split ('&')
else:
charge_targe_id = os.environ["charge_targe_id"]
printT (f"已获取并使用Env环境 charge_targe_id={charge_targe_id}")
else:
printT("变量charge_targe_id未填写无法充能")
def userAgent(): def userAgent():
@@ -257,7 +231,7 @@ def get_ck(token,sid_ck,account):
"cookie": f"{token}", "cookie": f"{token}",
'host': 'api.m.jd.com', 'host': 'api.m.jd.com',
# 'User-Agent': 'jdapp;iPhone;9.4.8;14.3;809409cbd5bb8a0fa8fff41378c1afe91b8075ad;network/wifi;ADID/201EDE7F-5111-49E8-9F0D-CCF9677CD6FE;supportApplePay/0;hasUPPay/0;hasOCPay/0;model/iPhone13,4;addressid/2455696156;supportBestPay/0;appBuild/167629;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1', # 'User-Agent': 'jdapp;iPhone;9.4.8;14.3;809409cbd5bb8a0fa8fff41378c1afe91b8075ad;network/wifi;ADID/201EDE7F-5111-49E8-9F0D-CCF9677CD6FE;supportApplePay/0;hasUPPay/0;hasOCPay/0;model/iPhone13,4;addressid/2455696156;supportBestPay/0;appBuild/167629;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1',
'user-Agent': "JD4iPhone/167922%20(iPhone;%20iOS;%20Scale/2.00)", 'user-Agent': userAgent (),
'accept-Encoding': 'gzip, deflate, br', 'accept-Encoding': 'gzip, deflate, br',
'accept-Language': 'zh-Hans-CN;q=1', 'accept-Language': 'zh-Hans-CN;q=1',
"content-type":"application/x-www-form-urlencoded", "content-type":"application/x-www-form-urlencoded",
@@ -272,7 +246,7 @@ def get_ck(token,sid_ck,account):
result = response.json () result = response.json ()
# print(result) # print(result)
access_token = result['token'] access_token = result['token']
print(access_token) # print(access_token)
return access_token return access_token
except Exception as e: except Exception as e:
msg("账号【{0}】获取ck失败cookie过期".format(account)) msg("账号【{0}】获取ck失败cookie过期".format(account))
@@ -299,13 +273,13 @@ def get_Authorization(access_token,account):
# print(data) # print(data)
response = requests.post (url=url, verify=False, headers=headers,data=data) response = requests.post (url=url, verify=False, headers=headers,data=data)
result = response.json () result = response.json ()
print(result) # print(result)
access_token = result['access_token'] access_token = result['access_token']
access_token = r"Bearer " + access_token access_token = r"Bearer " + access_token
# print(access_token) # print(access_token)
return access_token return access_token
except Exception as e: except Exception as e:
msg("账号【{0}】获取Authorization失败cookie过期".format(account)) msg("账号【{0}】获取Authorization失败活动火爆,请稍后再试".format(account))
#获取已种植的信息 #获取已种植的信息
def get_planted_info(cookies,sid,account): def get_planted_info(cookies,sid,account):
@@ -332,11 +306,15 @@ def get_planted_info(cookies,sid,account):
try: try:
name = result['plant'][f'{i+1}']['data']['name'] name = result['plant'][f'{i+1}']['data']['name']
planted_id = result['plant'][f'{i+1}']['data']['id'] planted_id = result['plant'][f'{i+1}']['data']['id']
print(f"账号{account}所种植的",f"{name}","充能ID为:",planted_id) print(f"账号{account}所种植的",f"{name}","充能ID为:",planted_id)
name_list.append(name) name_list.append(name)
planted_id_list.append(planted_id) planted_id_list.append(planted_id)
global charge_targe_id
charge_targe_id=str(planted_id)
break
except Exception as e: except Exception as e:
pass pass
print('\n\n')
#获取早睡打卡 #获取早睡打卡
@@ -468,13 +446,13 @@ def do_task(cookies,taskName,taskId,taskToken,sid,account):
res = requests.post(url=url1, verify=False, headers=headers,data=data.encode()) res = requests.post(url=url1, verify=False, headers=headers,data=data.encode())
# print(res.status_code) # print(res.status_code)
if res.status_code == 200: if res.status_code == 200:
msg("账号【{0}正在执行任务请稍等10秒".format(account)) msg("正在执行任务请稍等10秒")
time.sleep(10) time.sleep(10)
response = requests.post(url=url, verify=False, headers=headers,data=data.encode()) #data中有汉字需要encode为utf-8 response = requests.post(url=url, verify=False, headers=headers,data=data.encode()) #data中有汉字需要encode为utf-8
result = response.json() result = response.json()
print(result) print(result)
score = result['score'] score = result['score']
msg ("账号【{0}执行任务【{1}】成功,获取【{2}】能量".format (account, taskName,score)) msg ("执行任务【{0}】成功,获取【{1}】能量".format (taskName,score))
except Exception as e: except Exception as e:
print(e) print(e)
@@ -503,13 +481,16 @@ def do_task2(cookies,taskName,taskId,taskToken,sid,account):
result = response.json() result = response.json()
# print(result) # print(result)
score = result['score'] score = result['score']
msg ("账号【{0}执行任务【{1}】成功,获取【{2}】能量".format (account, taskName,score)) msg ("执行任务【{0}】成功,获取【{1}】能量".format (taskName,score))
except Exception as e: except Exception as e:
print(e) print(e)
#充能 #充能
def charge(charge_targe_id,cookies,sid,account): def charge(charge_targe_id,cookies,sid,account):
if len(charge_targe_id)==0:
msg("账号【{0}】未种植".format(account))
return
try: try:
url = 'https://xinruismzd-isv.isvjcloud.com/api/add_growth_value' url = 'https://xinruismzd-isv.isvjcloud.com/api/add_growth_value'
headers = { headers = {
@@ -531,10 +512,10 @@ def charge(charge_targe_id,cookies,sid,account):
for i in range(10): for i in range(10):
response = requests.post(url=url, verify=False, headers=headers,data=data.encode()) #data中有汉字需要encode为utf-8 response = requests.post(url=url, verify=False, headers=headers,data=data.encode()) #data中有汉字需要encode为utf-8
result = response.json() result = response.json()
# print(result) print(result)
user_coins = result['user_coins'] #剩余能量 user_coins = result['user_coins'] #剩余能量
coins = result['plant_info']['coins'] #消耗能量 coins = result['plant_info']['coins'] #消耗能量
msg ("账号【{0}充能成功,消耗【{1}】能量,剩余能量【{2}".format (account, coins,user_coins)) msg ("充能成功,消耗【{0}】能量,剩余能量【{1}".format (coins,user_coins))
time.sleep(2) time.sleep(2)
except Exception as e: except Exception as e:
@@ -550,6 +531,7 @@ def start():
nowtime = datetime.datetime.now ().strftime ('%Y-%m-%d %H:%M:%S.%f8') nowtime = datetime.datetime.now ().strftime ('%Y-%m-%d %H:%M:%S.%f8')
if cookie != '': if cookie != '':
account = setName (cookie) account = setName (cookie)
msg ("★★★★★正在账号{}的任务★★★★★".format (account))
access_token = get_ck(cookie,sid_ck,account) access_token = get_ck(cookie,sid_ck,account)
cookie = get_Authorization (access_token, account) cookie = get_Authorization (access_token, account)
get_planted_info (cookie, sid,account) get_planted_info (cookie, sid,account)
@@ -566,14 +548,11 @@ def start():
do_task2 (cookie, taskName, taskId, i, sid,account) do_task2 (cookie, taskName, taskId, i, sid,account)
charge(charge_targe_id,cookie,sid, account) charge(charge_targe_id,cookie,sid, account)
elif cookies != '': elif cookies != '':
for cookie, charge_targe_id in zip (cookies, charge_targe_ids): for cookie in cookies:
account = setName (cookie)
access_token = get_ck (cookie, sid_ck, account)
cookie = get_Authorization (access_token, account)
get_planted_info (cookie, sid,account)
for cookie,charge_targe_id in zip(cookies,charge_targe_ids):
try: try:
account = setName (cookie) account = setName (cookie)
msg ("★★★★★正在账号{}的任务★★★★★".format (account))
charge_targe_id=''
access_token = get_ck (cookie, sid_ck,account) access_token = get_ck (cookie, sid_ck,account)
cookie = get_Authorization (access_token, account) cookie = get_Authorization (access_token, account)
get_planted_info (cookie,sid,account) get_planted_info (cookie,sid,account)
@@ -587,9 +566,10 @@ def start():
taskName, taskId, taskToken_list = get_task2 (cookie,sid, account) taskName, taskId, taskToken_list = get_task2 (cookie,sid, account)
for i in taskToken_list: for i in taskToken_list:
do_task2 (cookie, taskName, taskId, i, sid,account) do_task2 (cookie, taskName, taskId, i, sid,account)
charge (charge_targe_id, cookie,sid, account)
except Exception as e: except Exception as e:
pass pass
charge (charge_targe_id, cookie, sid, account)
else: else:
printT("请检查变量plant_cookie是否已填写") printT("请检查变量plant_cookie是否已填写")