From 96dfa4b9791e1a5f9393dff8eae1fda508fb4e43 Mon Sep 17 00:00:00 2001 From: KingRan Date: Sat, 12 Feb 2022 20:00:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jd_beauty_plant.py | 999 --------------------------------------------- jd_xinruimz.js | 480 ++++++++++++++++++++++ 2 files changed, 480 insertions(+), 999 deletions(-) delete mode 100644 jd_beauty_plant.py create mode 100644 jd_xinruimz.js diff --git a/jd_beauty_plant.py b/jd_beauty_plant.py deleted file mode 100644 index b7b5923..0000000 --- a/jd_beauty_plant.py +++ /dev/null @@ -1,999 +0,0 @@ -#!/bin/env python3 -# -*- coding: utf-8 -* -''' -感谢Curtin提供的其他脚本供我参考 -感谢aburd ch大佬的指导 -项目名称:xF_jd_beauty_plant.py -Author: 一风一扬 -功能:健康社区-种植园自动任务 -Date: 2022-1-4 -cron: 10 9,11,15,21 * * * jd_beauty_plant.py -new Env('化妆馆-种植园自动任务'); - - -活动入口:25:/¥2EaeU74Gz07gJ% - -教程:该活动与京东的ck通用,所以只需要填写第几个号运行改脚本就行了。 - -青龙变量填写export plant_cookie="1",代表京东CK的第一个号执行该脚本 - -多账号用&隔开,例如export plant_cookie="1&2",代表京东CK的第一、二个号执行该脚本。这样做,JD的ck过期就不用维护两次了,所以做出了更新。 - -青龙变量export choose_plant_id="true",表示自己选用浇水的ID,适用于种植了多个产品的人,默认为false,如果是false仅适用于种植了一个产品的人。 -对于多账号的,只要有一个账号种植多个产品,都必须为true才能浇水。如果choose_plant_id="false",planted_id可以不填写变量值。 -青龙变量export planted_id = 'xxxx',表示需要浇水的id,单账号可以先填写export planted_id = '111111',export choose_plant_id="true",运行一次脚本 -日志输出会有planted_id,然后再重新修改export planted_id = 'xxxxxx'。多个账号也一样,如果2个账号export planted_id = '111111&111111' -3个账号export planted_id = '111111&111111&111111',以此类推。 -注意:planted_id和ck位置要对应。而且你有多少个账号,就得填多少个planted_id,首次111111填写时,为6位数。 -例如export plant_cookie="xxxx&xxxx&xxx",那export planted_id = "111111&111111&111111",也要写满3个id,这样才能保证所有账号都能跑 - -''' - -######################################################以下代码请不要乱改###################################### - -UserAgent = '' -account = '' -cookie = '' -cookies = [] -choose_plant_id = 'false' -planted_id = '' -shop_id = '' -beauty_plant_exchange = 'false' -planted_ids = [] - -import requests -import time, datetime -import requests, re, os, sys, random, json -from urllib.parse import quote, unquote -import threading -import urllib3 - -# urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - -requests.packages.urllib3.disable_warnings () - -today = datetime.datetime.now ().strftime ('%Y-%m-%d') -tomorrow = (datetime.datetime.now () + datetime.timedelta (days=1)).strftime ('%Y-%m-%d') - -nowtime = datetime.datetime.now ().strftime ('%Y-%m-%d %H:%M:%S.%f8') - -time1 = '21:00:00.00000000' -time2 = '23:00:00.00000000' - -flag_time1 = '{} {}'.format (today, time1) -flag_time2 = '{} {}'.format (today, time2) - -pwd = os.path.dirname (os.path.abspath (__file__)) + os.sep -path = pwd + "env.sh" - -sid = ''.join (random.sample ('123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 32)) - -sid_ck = ''.join (random.sample ('123456789abcdef123456789abcdef123456789abcdef123456789abcdefABCDEFGHIJKLMNOPQRSTUVWXYZ', 43)) - - -def printT(s): - print ("[{0}]: {1}".format (datetime.datetime.now ().strftime ("%Y-%m-%d %H:%M:%S"), s)) - sys.stdout.flush () - - -def getEnvs(label): - try: - if label == 'True' or label == 'yes' or label == 'true' or label == 'Yes': - return True - elif label == 'False' or label == 'no' or label == 'false' or label == 'No': - return False - except: - pass - try: - if '.' in label: - return float (label) - elif '&' in label: - return label.split ('&') - elif '@' in label: - return label.split ('@') - else: - return int (label) - except: - return label - - -# 获取v4环境 特殊处理 -try: - with open (v4f, 'r', encoding='utf-8') as v4f: - v4Env = v4f.read () - r = re.compile (r'^export\s(.*?)=[\'\"]?([\w\.\-@#&=_,\[\]\{\}\(\)]{1,})+[\'\"]{0,1}$', - re.M | re.S | re.I) - r = r.findall (v4Env) - curenv = locals () - for i in r: - if i[0] != 'JD_COOKIE': - curenv[i[0]] = getEnvs (i[1]) -except: - pass - -############# 在pycharm测试ql环境用,实际用下面的代码运行 ######### -# with open(path, "r+", encoding="utf-8") as f: -# ck = f.read() -# if "JD_COOKIE" in ck: -# r = re.compile (r"pt_key=.*?pt_pin=.*?;", re.M | re.S | re.I) -# cookies = r.findall (ck) -# # print(cookies) -# # cookies = cookies[0] -# # print(cookies) -# # cookies = cookies.split ('&') -# printT ("已获取并使用ck环境 Cookie") -####################################################################### - - -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 = os.environ["JD_COOKIE"] - cookies1 = 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: - printT ("变量plant_cookie未填写") - exit (0) - -if "choose_plant_id" in os.environ: - choose_plant_id = os.environ["choose_plant_id"] - printT (f"已获取并使用Env环境choose_plant_id={choose_plant_id}") -else: - printT ("变量choose_plant_id未填写,默认为false只种植了一个,如果种植了多个,请填写改变量planted_id") - -if "planted_id" in os.environ: - if len (os.environ["planted_id"]) > 8: - planted_ids = os.environ["planted_id"] - planted_ids = planted_ids.split ('&') - else: - planted_id = os.environ["planted_id"] - printT (f"已获取并使用Env环境planted_id={planted_id}") -else: - printT ("变量planted_id未填写,默认为false只种植了一个,如果种植了多个,请填写改变量planted_id") - -if "beauty_plant_exchange" in os.environ: - beauty_plant_exchange = os.environ["beauty_plant_exchange"] - printT (f"已获取并使用Env环境beauty_plant_exchange={beauty_plant_exchange}") -else: - printT ("变量beauty_plant_exchange未填写,默认为false,不用美妆币兑换肥料") - - -def userAgent(): - """ - 随机生成一个UA - :return: jdapp;iPhone;9.4.8;14.3;xxxx;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 - """ - if not UserAgent: - uuid = ''.join (random.sample ('123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 40)) - addressid = ''.join (random.sample ('1234567898647', 10)) - iosVer = ''.join ( - random.sample (["14.5.1", "14.4", "14.3", "14.2", "14.1", "14.0.1", "13.7", "13.1.2", "13.1.1"], 1)) - iosV = iosVer.replace ('.', '_') - iPhone = ''.join (random.sample (["8", "9", "10", "11", "12", "13"], 1)) - ADID = ''.join (random.sample ('0987654321ABCDEF', 8)) + '-' + ''.join ( - random.sample ('0987654321ABCDEF', 4)) + '-' + ''.join ( - random.sample ('0987654321ABCDEF', 4)) + '-' + ''.join ( - random.sample ('0987654321ABCDEF', 4)) + '-' + ''.join (random.sample ('0987654321ABCDEF', 12)) - return f'jdapp;iPhone;10.0.4;{iosVer};{uuid};network/wifi;ADID/{ADID};supportApplePay/0;hasUPPay/0;hasOCPay/0;model/iPhone{iPhone},1;addressid/{addressid};supportBestPay/0;appBuild/167629;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS {iosV} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1' - else: - return UserAgent - - -## 获取通知服务 -class msg (object): - def __init__(self, m=''): - self.str_msg = m - self.message () - - def message(self): - global msg_info - printT (self.str_msg) - try: - msg_info = "{}\n{}".format (msg_info, self.str_msg) - except: - msg_info = "{}".format (self.str_msg) - sys.stdout.flush () # 这代码的作用就是刷新缓冲区。 - # 当我们打印一些字符时,并不是调用print函数后就立即打印的。一般会先将字符送到缓冲区,然后再打印。 - # 这就存在一个问题,如果你想等时间间隔的打印一些字符,但由于缓冲区没满,不会打印。就需要采取一些手段。如每次打印后强行刷新缓冲区。 - - def getsendNotify(self, a=0): - if a == 0: - a += 1 - try: - url = 'https://gitee.com/curtinlv/Public/raw/master/sendNotify.py' - response = requests.get (url) - if 'curtinlv' in response.text: - with open ('sendNotify.py', "w+", encoding="utf-8") as f: - f.write (response.text) - else: - if a < 5: - a += 1 - return self.getsendNotify (a) - else: - pass - except: - if a < 5: - a += 1 - return self.getsendNotify (a) - else: - pass - - def main(self): - global send - cur_path = os.path.abspath (os.path.dirname (__file__)) - sys.path.append (cur_path) - if os.path.exists (cur_path + "/sendNotify.py"): - try: - from sendNotify import send - except: - self.getsendNotify () - try: - from sendNotify import send - except: - printT ("加载通知服务失败~") - else: - self.getsendNotify () - try: - from sendNotify import send - except: - printT ("加载通知服务失败~") - ################### - - -msg ().main () - - -def setName(cookie): - try: - r = re.compile (r"pt_pin=(.*?);") # 指定一个规则:查找pt_pin=与;之前的所有字符,但pt_pin=与;不复制。r"" 的作用是去除转义字符. - userName = r.findall (cookie) # 查找pt_pin=与;之前的所有字符,并复制给r,其中pt_pin=与;不复制。 - # print (userName) - userName = unquote (userName[0]) # r.findall(cookie)赋值是list列表,这个赋值为字符串 - # print(userName) - return userName - except Exception as e: - print (e, "cookie格式有误!") - exit (2) - - -# 获取ck -def get_ck(token, sid_ck, account): - try: - url = 'https://api.m.jd.com/client.action?functionId=isvObfuscator' - headers = { - # 'Connection': 'keep-alive', - 'accept': '*/*', - "cookie": f"{token}", - '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': "JD4iPhone/167922%20(iPhone;%20iOS;%20Scale/2.00)", - 'accept-Encoding': 'gzip, deflate, br', - 'accept-Language': 'zh-Hans-CN;q=1', - "content-type": "application/x-www-form-urlencoded", - # "content-length":"1348", - } - timestamp = int (round (time.time () * 1000)) - timestamp1 = int (timestamp / 1000) - data = r'body=%7B%22url%22%3A%22https%3A%5C/%5C/xinruismzd-isv.isvjcloud.com%22%2C%22id%22%3A%22%22%7D&build=167922&client=apple&clientVersion=10.3.2&d_brand=apple&d_model=iPhone12%2C1&ef=1&eid=eidI4a9081236as4w7JpXa5zRZuwROIEo3ORpcOyassXhjPBIXtrtbjusqCxeW3E1fOtHUlGhZUCur1Q1iocDze1pQ9jBDGfQs8UXxMCTz02fk0RIHpB&ep=%7B%22ciphertype%22%3A5%2C%22cipher%22%3A%7B%22screen%22%3A%22ENS4AtO3EJS%3D%22%2C%22wifiBssid%22%3A%22' + f"{sid_ck}" + r'%3D%22%2C%22osVersion%22%3A%22CJUkCK%3D%3D%22%2C%22area%22%3A%22CJvpCJY1DV80ENY2XzK%3D%22%2C%22openudid%22%3A%22Ytq3YtKyDzO5CJuyZtu4CWSyZtC0Ytc1CJLsDwC5YwO0YtS5CNrsCK%3D%3D%22%2C%22uuid%22%3A%22aQf1ZRdxb2r4ovZ1EJZhcxYlVNZSZz09%22%7D%2C%22ts%22%3A1642002985%2C%22hdid%22%3A%22JM9F1ywUPwflvMIpYPok0tt5k9kW4ArJEU3lfLhxBqw%3D%22%2C%22version%22%3A%221.0.3%22%2C%22appname%22%3A%22com.360buy.jdmobile%22%2C%22ridx%22%3A-1%7D&ext=%7B%22prstate%22%3A%220%22%2C%22pvcStu%22%3A%221%22%7D&isBackground=N&joycious=88&lang=zh_CN&networkType=wifi&networklibtype=JDNetworkBaseAF&partner=apple&rfs=0000&scope=01&sign=946db60626658b250cf47aafb6f67691&st=1642002999847&sv=112&uemps=0-0&uts=0f31TVRjBSu3kkqwe7t25AkQCKuzV3pz8JrojVuU0630g%2BkZigs9kTwRghT26sE72/e92RRKan/%2B9SRjIJYCLuhew91djUwnIY47k31Rwne/U1fOHHr9FmR31X03JKJjwao/EC1gy4fj7PV1Co0ZOjiCMTscFo/8id2r8pCHYMZcaeH3yPTLq1MyFF3o3nkStM/993MbC9zim7imw8b1Fg%3D%3D' - # data = '{"token":"AAFh3ANjADAPSunyKSzXTA-UDxrs3Tn9hoy92x4sWmVB0Kv9ey-gAMEdJaSDWLWtnMX8lqLujBo","source":"01"}' - # print(data) - response = requests.post (url=url, verify=False, headers=headers, data=data) - result = response.json () - # print(result) - access_token = result['token'] - # print(access_token) - return access_token - except Exception as e: - msg ("账号【{0}】获取ck失败,cookie过期".format (account)) - - -# 获取Authorization -def get_Authorization(access_token, account): - try: - url = 'https://xinruimz-isv.isvjcloud.com/papi/auth' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": 'Bearer undefined', - 'Referer': 'https://xinruimz-isv.isvjcloud.com/plantation/logined_jd/', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Origin": "https://xinruimz-isv.isvjcloud.com", - "Content-Type": "application/json;charset=utf-8", - - } - data = '{"token":"' + f"{access_token}" + r'","source":"01"}' - # print(data) - response = requests.post (url=url, verify=False, headers=headers, data=data) - result = response.json () - print (result) - access_token = result['access_token'] - access_token = r"Bearer " + access_token - # print(access_token) - return access_token - except Exception as e: - msg ("账号【{0}】获取Authorization失败,cookie过期".format (account)) - - -# 获取已种植的信息 -def get_planted_info(cookie, sid, account): - name_list = [] - planted_id_list = [] - position_list = [] - shop_id_list = [] - url = 'https://xinruimz-isv.isvjcloud.com/papi/get_home_info' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/?sid={sid}&un_area=19_1655_4866_0', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9' - } - response = requests.get (url=url, verify=False, headers=headers) - result = response.json () - # print(result) - planted_list = result['plant_info'] - # print(planted_list) - for i in range (len (planted_list)): - try: - name = result['plant_info'][f'{i + 1}']['data']['name'] - planted_id = result['plant_info'][f'{i + 1}']['data']['id'] - position = result['plant_info'][f'{i + 1}']['data']['position'] - shop_id = result['plant_info'][f'{i + 1}']['data']['shop_id'] - # print(name,planted_id,position,shop_id) - name_list.append (name) - planted_id_list.append (planted_id) - position_list.append (position) - shop_id_list.append (shop_id) - print (f"账号{account}种植的种子为", name, "planted_id:", planted_id, ",shop_id:", shop_id) - except Exception as e: - pass - return name_list, position_list, shop_id_list, planted_id_list - - -# 领取每日水滴 -def get_water(cookie, position, sid, account): - try: - j = 0 - url = 'https://xinruimz-isv.isvjcloud.com/papi/collect_water' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/?sid={sid}&un_area=19_1655_4866_0', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Content-Type": "application/json;charset=utf-8", - } - for i in position: - data = r'{"position":' + f"{i}" + r'}' - response = requests.post (url=url, verify=False, headers=headers, data=data) - # print(response.status_code) - if response.status_code == 204: - j += 1 - total = j * 10 - if response.status_code == 204: - msg ("账号【{0}】成功领取每日水滴{1}".format (account, total)) - - except Exception as e: - msg ("账号【{0}】领取每日水滴失败,可能是cookie过期".format (account)) - - -# 领取每日肥料 -def get_fertilizer(cookie, shop_id, account): - try: - j = 0 - url = 'https://xinruimz-isv.isvjcloud.com/papi/collect_fertilizer' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': 'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id=12&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Content-Type": "application/json;charset=utf-8", - } - for i in shop_id: - data = r'{"shop_id":' + f"{i}" + r'}' - response = requests.post (url=url, verify=False, headers=headers, data=data) - if response.status_code == 204: - j += 1 - total = j * 10 - if response.status_code == 204: - msg ("账号【{0}】成功领取每日肥料{1}".format (account, total)) - - except Exception as e: - msg ("账号【{0}】领取每日肥料失败,可能是cookie过期".format (account)) - - -# 获取任务信息 -def get_task(cookie, account): - try: - taskName_list = [] - taskId_list = [] - taskName_list2 = [] - taskId_list2 = [] - taskName_list3 = [] - taskId_list3 = [] - url = 'https://xinruimz-isv.isvjcloud.com/papi/water_task_info' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': 'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id=12&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) - result = response.json () - # print(result) - task_list = result['shops'] - task_list2 = result['meetingplaces'] - task_list3 = result['prodcuts'] # 浏览加购 - # print(task_list) - for i in range (len (task_list)): - try: - taskName = task_list[i]['name'] - taskId = task_list[i]['id'] - taskId_list.append (taskId) - taskName_list.append (taskName) - except Exception as e: - print (e) - for i in range (len (task_list2)): - try: - taskName2 = task_list2[i]['name'] - taskId2 = task_list2[i]['id'] - taskId_list2.append (taskId2) - taskName_list2.append (taskName2) - except Exception as e: - print (e) - for i in range (len (task_list3)): - try: - taskName3 = task_list3[i]['name'] - taskId3 = task_list3[i]['id'] - taskId_list3.append (taskId3) - taskName_list3.append (taskName3) - except Exception as e: - print (e) - # print(taskName_list,taskId_list,taskName_list2,taskId_list2,taskName_list3,taskId_list3) - return taskName_list, taskId_list, taskName_list2, taskId_list2, taskName_list3, taskId_list3 - except Exception as e: - print (e) - message = result['message'] - if "非法店铺" in message: - msg ("【账号{0}】种子过期,请重新种植".format (account)) - - -# 获取任务信息 -def get_fertilizer_task(cookie, shop_id, account): - try: - # taskName_list = [] - # taskId_list = [] - taskName_list2 = [] - taskId_list2 = [] - taskName_list3 = [] - taskId_list3 = [] - taskName_list4 = [] - taskId_list4 = [] - url = f'https://xinruimz-isv.isvjcloud.com/papi/fertilizer_task_info?shop_id={shop_id}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) - result = response.json () - # print(result) - # task_list = result['shops'] - task_list2 = result['meetingplaces'] - task_list3 = result['prodcuts'] # 浏览加购 - task_list4 = result['live'] # 浏览直播 - # print(task_list) - # for i in range (len (task_list)): - # try: - # taskName = task_list[i]['name'] - # taskId = task_list[i]['id'] - # taskId_list.append(taskId) - # taskName_list.append(taskName) - # except Exception as e: - # print(e) - for i in range (len (task_list2)): - try: - taskName2 = task_list2[i]['name'] - taskId2 = task_list2[i]['id'] - taskId_list2.append (taskId2) - taskName_list2.append (taskName2) - except Exception as e: - print (e) - for i in range (len (task_list3)): - try: - taskName3 = task_list3[i]['name'] - taskId3 = task_list3[i]['id'] - taskId_list3.append (taskId3) - taskName_list3.append (taskName3) - except Exception as e: - print (e) - for i in range (len (task_list4)): - try: - taskName4 = task_list4[i]['name'] - taskId4 = task_list4[i]['id'] - taskId_list4.append (taskId4) - taskName_list4.append (taskName4) - except Exception as e: - print (e) - # print(taskName_list,taskId_list,taskName_list2,taskId_list2,taskName_list3,taskId_list3) - return taskName_list2, taskId_list2, taskName_list3, taskId_list3, taskName_list4, taskId_list4 - except Exception as e: - print (e) - message = result['message'] - if "非法店铺" in message: - msg ("【账号{0}】种子过期,请重新种植".format (account)) - - -# 做任务1 -def do_task1(cookie, taskName, taskId, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/water_shop_view?shop_id={taskId}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': 'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id=12&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行浏览任务【{1}】等待10秒".format (account, taskName)) - msg ("账号【{0}】执行浏览任务【{1}】成功,获取【{2}】水滴".format (account, taskName, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 做浏览任务 -def do_task2(cookie, taskName, taskId, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/water_meetingplace_view?meetingplace_id={taskId}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': 'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id=12&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行浏览任务【{1}】等待10秒".format (account, taskName)) - msg ("账号【{0}】执行浏览任务【{1}】成功,获取【{2}】水滴".format (account, taskName, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 浏览加购 -def do_task3(cookie, taskName, taskId, sid, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/water_product_view?product_id={taskId}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/?sid={sid}&un_area=19_1655_4866_0', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行浏览加购【{1}】等待10秒".format (account, taskName)) - msg ("账号【{0}】执行浏览加购【{1}】成功,获取【{2}】水滴".format (account, taskName, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 施肥中的任务-浏览关注 -def do_fertilizer_task(cookie, shop_id, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/fertilizer_shop_view?shop_id={shop_id}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - while True: - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行【浏览关注】等待10秒".format (account)) - msg ("账号【{0}】执行【浏览关注】任务成功,获取【{1}】肥料".format (account, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 施肥中的任务-浏览 -def do_fertilizer_task2(cookie, name, meetingplace_id, shop_id, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/fertilizer_meetingplace_view?meetingplace_id={meetingplace_id}&shop_id={shop_id}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行浏览关注{1}等待10秒".format (account, name)) - msg ("账号【{0}】执行浏览关注{1}任务成功,获取【{2}】肥料".format (account, name, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 施肥中的任务-加购 -def do_fertilizer_task3(cookie, name, product_id, shop_id, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/fertilizer_product_view?product_id={product_id}&shop_id={shop_id}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - while True: - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行浏览并加购{1}等待10秒".format (account, name)) - msg ("账号【{0}】执行浏览并加购{1}任务成功,获取【{2}】肥料".format (account, name, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 施肥中的任务-观看其他小样 -def do_fertilizer_task4(cookie, shop_id, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/fertilizer_sample_view?shop_id={shop_id}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行【观看其他小样】等待10秒".format (account)) - msg ("账号【{0}】执行【观看其他小样】任务成功,获取【{1}】肥料".format (account, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 施肥中的任务-浏览化妆馆 -def do_fertilizer_task5(cookie, shop_id, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/fertilizer_chanel_view?shop_id={shop_id}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - print (result) - score = result['inc'] - print ("账号【{0}】执行【浏览化妆馆】等待10秒".format (account)) - msg ("账号【{0}】执行【浏览化妆馆】任务成功,获取【{1}】肥料".format (account, score)) - time.sleep (10) - except Exception as e: - print (e) - time.sleep (1) - - -# 施肥中的任务-美妆币兑换,每天5次 -def do_fertilizer_task6(cookie, shop_id, account): - try: - url = f'https://xinruimz-isv.isvjcloud.com/papi/fertilizer_exchange?shop_id={shop_id}' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - # "Content-Type": "application/json;charset=utf-8", - } - for i in range (5): - response = requests.get (url=url, verify=False, headers=headers) # data中有汉字,需要encode为utf-8 - result = response.json () - # print(result) - score = result['inc'] - print ("账号【{0}】【shop_id:{1}】正在【兑换肥料】等待10秒".format (account, shop_id)) - msg ("账号【{0}】【shop_id:{2}】执行【兑换肥料】任务成功,获取【{1}】肥料".format (account, score, shop_id)) - time.sleep (10) - except Exception as e: - print (e) - msg ("账号【{0}】【shop_id:{1}】肥料兑换已达上限".format (account, shop_id)) - time.sleep (1) - - -# 浇水 -def watering(cookie, plant_id, sid, account): - try: - url = 'https://xinruimz-isv.isvjcloud.com/papi/watering' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/?sid={sid}&un_area=19_1655_4866_0', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Content-Type": "application/json;charset=utf-8", - } - data = r'{"plant_id":' + f"{plant_id}" + r'}' - while True: - response = requests.post (url=url, verify=False, headers=headers, - data=data.encode ()) # data中有汉字,需要encode为utf-8 - result = response.json () - # print(result) - level = result['level'] # 当前等级 - complete_level = result['complete_level'] # 完成等级 - msg ("【账号{0}】【plant_id:{3}】成功浇水10g,当前等级{1},种子成熟等级为{2}".format (account, level, complete_level, plant_id)) - time.sleep (5) - - except Exception as e: - print(e) - # pass - - -# 施肥 -def fertilization(cookie, plant_id, shop_id, account): - url = 'https://xinruimz-isv.isvjcloud.com/papi/fertilization' - headers = { - 'Connection': 'keep-alive', - 'Accept': 'application/x.jd-school-raffle.v1+json', - "Authorization": cookie, - 'Referer': f'https://xinruimz-isv.isvjcloud.com/plantation/shop_index/?shop_id={shop_id}&channel=index', - 'Host': 'xinruimz-isv.isvjcloud.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': userAgent (), - # 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - "Content-Type": "application/json;charset=utf-8", - } - data = r'{"plant_id":' + f"{plant_id}" + r'}' - i = 1 - while True: - try: - response = requests.post (url=url, verify=False, headers=headers, data=data) # data中有汉字,需要encode为utf-8 - result = response.json () - # print(result) - level = result['level'] # 当前等级 - complete_level = result['complete_level'] # 完成等级 - printT ("【账号{0}】【plant_id:{3}】成功施肥10g,当前等级{1},种子成熟等级为{2}".format (account, level, complete_level, plant_id)) - time.sleep (5) - i += 1 - - except Exception as e: - # print(e) - message = result['message'] - total = i * 10 - if "肥料不足" in message: - msg("【账号{0}】【plant_id:{1}】本次一共施肥{2}g".format (account, plant_id,total)) - printT ("【账号{0}】【plant_id:{1}】肥料不足10g".format (account, plant_id)) - break - - -def start(): - global cookie, cookies - print (f"\n【准备开始...】\n") - nowtime = datetime.datetime.now ().strftime ('%Y-%m-%d %H:%M:%S.%f8') - if cookie != '': - account = setName (cookie) - access_token = get_ck (cookie, sid_ck, account) - cookie = get_Authorization (access_token, account) - name_list, position_list, shop_id_list, planted_id_list = get_planted_info (cookie, sid, account) - taskName_list, taskId_list, taskName_list2, taskId_list2, taskName_list3, taskId_list3 = get_task (cookie,account) - get_water (cookie, position_list, sid, account) - get_fertilizer (cookie, shop_id_list, account) - for i, j in zip (taskName_list, taskId_list): - do_task1 (cookie, i, j, account) - for i, j in zip (taskName_list2, taskId_list2): - do_task2 (cookie, i, j, account) - for i, j in zip (taskName_list3, taskId_list3): - do_task3 (cookie, i, j, sid, account) - - flag = 0 - for i in shop_id_list: - do_fertilizer_task (cookie, i, account) # 浏览关注 - for k in shop_id_list: - taskName_list2, taskId_list2, taskName_list3, taskId_list3, taskName_list4, taskId_list4 = get_fertilizer_task (cookie, k, account) - do_fertilizer_task4 (cookie, k, account) - do_fertilizer_task5 (cookie, k, account) - if beauty_plant_exchange == 'true': - do_fertilizer_task6 (cookie, k, account) - for i, j in zip (taskName_list2, taskId_list2): - print (i, j, k) - do_fertilizer_task2 (cookie, i, j, k, account) # 浏览 - for i, j in zip (taskName_list3, taskId_list3): - print (i, j, k) - do_fertilizer_task3 (cookie, i, j, k, account) # 加购 - - if choose_plant_id == 'false': - for i in planted_id_list: - watering (cookie, i, sid, account) - fertilization (cookie, i, k, account) - else: - fertilization (cookie, planted_id_list[flag], k, account) - watering (cookie, planted_id, sid, account) - flag += 1 - - elif cookies != '': - for cookie, planted_id in zip (cookies, planted_ids): - try: - account = setName (cookie) - access_token = get_ck (cookie, sid_ck, account) - cookie = get_Authorization (access_token, account) - name_list, position_list, shop_id_list, planted_id_list = get_planted_info (cookie, sid, account) - except Exception as e: - pass - for cookie, planted_id in zip (cookies, planted_ids): - try: - account = setName (cookie) - access_token = get_ck (cookie, sid_ck, account) - cookie = get_Authorization (access_token, account) - name_list, position_list, shop_id_list, planted_id_list = get_planted_info (cookie, sid, account) - taskName_list, taskId_list, taskName_list2, taskId_list2, taskName_list3, taskId_list3 = get_task (cookie, account) - get_water (cookie, position_list, sid, account) - get_fertilizer (cookie, shop_id_list, account) - for i, j in zip (taskName_list, taskId_list): - do_task1 (cookie, i, j, account) - for i, j in zip (taskName_list2, taskId_list2): - do_task2 (cookie, i, j, account) - for i, j in zip (taskName_list3, taskId_list3): - do_task3 (cookie, i, j, sid, account) - - flag = 0 - for i in shop_id_list: - do_fertilizer_task (cookie, i, account) # 浏览关注 - for k in shop_id_list: - taskName_list2, taskId_list2, taskName_list3, taskId_list3, taskName_list4, taskId_list4 = get_fertilizer_task ( - cookie, k, account) - do_fertilizer_task4 (cookie, k, account) - do_fertilizer_task5 (cookie, k, account) - if beauty_plant_exchange == 'true': - do_fertilizer_task6 (cookie, k, account) - for i, j in zip (taskName_list2, taskId_list2): - print (i, j, k) - do_fertilizer_task2 (cookie, i, j, k, account) # 浏览 - for i, j in zip (taskName_list3, taskId_list3): - print (i, j, k) - do_fertilizer_task3 (cookie, i, j, k, account) # 加购 - - if choose_plant_id == 'false': - for i in planted_id_list: - fertilization (cookie, i, k, account) - watering (cookie, i, sid, account) - else: - print("【账号{}现在开始施肥】".format(account)) - fertilization (cookie, planted_id_list[flag], k, account) - print ("【账号{}现在开始浇水】".format (account)) - watering (cookie, planted_id, sid, account) - flag += 1 - except Exception as e: - pass - else: - printT ("请检查变量plant_cookie是否已填写") - - -if __name__ == '__main__': - printT ("美丽研究院-种植园") - start () - # if '成熟' in msg_info: - # send ("美丽研究院-种植园", msg_info) - if '成功' in msg_info: - send ("美丽研究院-种植园", msg_info) diff --git a/jd_xinruimz.js b/jd_xinruimz.js new file mode 100644 index 0000000..26d6d03 --- /dev/null +++ b/jd_xinruimz.js @@ -0,0 +1,480 @@ +/* +cron 30 6-20/3 * * * jd_xinruimz.js +TG https://t.me/duckjobs +Rpeo https://github.com/okyyds +需要手动选 +入口: https://xinruimz-isv.isvjcloud.com/plantation + +无助力 +*/ + +const $ = new Env("颜究种植园"); +const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; +const notify = $.isNode() ? require('./sendNotify') : ''; +let cookiesArr = [], cookie = '', message = ''; +let waternum = 0; +let exfertilizer = true; +if ($.isNode()) { + Object.keys(jdCookieNode).forEach((item) => { + cookiesArr.push(jdCookieNode[item]) + }) + if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => { }; +} else { + let cookiesData = $.getdata('CookiesJD') || "[]"; + cookiesData = JSON.parse(cookiesData); + cookiesArr = cookiesData.map(item => item.cookie); + cookiesArr.reverse(); + cookiesArr.push(...[$.getdata('CookieJD2'), $.getdata('CookieJD')]); + cookiesArr.reverse(); + cookiesArr = cookiesArr.filter(item => !!item); +} +!(async () => { + if (!cookiesArr[0]) { + $.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/bean/signIndex.action', { "open-url": "https://bean.m.jd.com/bean/signIndex.action" }); + return; + } + UUID = getUUID('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); + for (let i = 0; i < cookiesArr.length; i++) { + UA = `jdapp;iPhone;10.1.6;13.5;${UUID};network/wifi;model/iPhone11,6;addressid/4596882376;appBuild/167841;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1`; + if (cookiesArr[i]) { + cookie = cookiesArr[i]; + $.UserName = decodeURIComponent(cookie.match(/pt_pin=(.+?);/) && cookie.match(/pt_pin=(.+?);/)[1]) + $.index = i + 1; + $.isLogin = true; + $.nickName = ''; + $.hotFlag = false; + await TotalBean(); + console.log(`\n******开始【京东账号${$.index}】${$.nickName || $.UserName}*********\n`); + if (!$.isLogin) { + $.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action`, { "open-url": "https://bean.m.jd.com/bean/signIndex.action" }); + if ($.isNode()) { + await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`); + } + continue + } + await main(); + } + } + if (message !== "") { + if ($.isNode()) { + await notify.sendNotify($.name, message) + } else { + $.msg($.name, '', message) + } + } +})().catch((e) => { $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') }).finally(() => { $.done(); }) + +async function main() { + $.tasklist = []; + $.infoArr = []; + $.token = ''; + $.accessToken = ''; + await getToken(); + if ($.token) { + await taskPost('auth', `{ "token": "${$.token}", "source": "01" }`); + // await taskPost('bind_friend_relation', `{"shop_id":0,"invite_user_id":"1612705"}`); + if ($.accessToken) { + await task('get_home_info'); + if (!$.hotFlag) { + $.log(`去执行水滴任务\n`) + await waterdotask(); + if ($.plantinfo) { + await plantinfo(); + if ($.infoArr != '') { + for (const vo of $.infoArr) { + $.storefertilizer = ''; + $.storewater = ''; + if (vo.status === 1) { + console.log(`${vo.name}已经可以收取啦!`) + message += `\n【京东账号${$.index}】${$.nickName || $.UserName}\n${vo.name}已经可以收取啦!` + } + await task('fertilizer_state', `shop_id=${vo.shopid}`); + await task('fertilizer_task_info', `shop_id=${vo.shopid}`); + $.log(`\n去执行${vo.name}小样任务`) + await fertilizerdotask(); + $.log(`\n去收取${vo.name}的水滴`) + await taskPost('collect_water', `{"position": ${vo.position}}`); + $.log(`\n去收取${vo.name}的肥料`) + await taskPost('collect_fertilizer', `{"shop_id": ${vo.shopid}}`); + await task('merchant_secondary_pages', `shop_id=${vo.shopid}&channel=index`); + if ($.storefertilizer > 0) { + if (vo.status === 0) { + for (i = 0; i < $.storefertilizer / 10; i++) { + $.log(`去执行${vo.name}施肥..`) + await $.wait(1000); + await taskPost('fertilization', `{"plant_id": ${vo.id}}`); + } + } else { + console.log('该植物不能施肥') + } + } else { + console.log('肥料不足,不施肥!') + } + } + console.log(`\n去执行浇水,共种植${$.infoArr.length}个小样,默认浇水第一个小样,如需浇其他小样,请设置waternum对应数组`) + for (i = 0; i < $.infoArr.length; i++) { + index = i + 1; + console.log(`第${index}个小样,${$.infoArr[i].name}`) + } + if ($.storewater > 0) { + for (x = 0; x < $.storewater / 10; x++) { + $.waterstatus = true; + water = $.infoArr[waternum]; + $.log(`去执行${water.name}浇水..`) + await $.wait(1000); + await taskPost('watering', `{"plant_id": ${water.id}}`); + if (!$.waterstatus) { break } + } + } else { + console.log('水资源不足,不浇水!') + } + } else { + $.log('你还没有种植小样!') + } + } + } else { + $.log('风险用户,快去买买买吧') + } + } else { + $.log('获取accessToken失败') + } + } else { + $.log('获取Token失败') + } +} +async function plantinfo() { + plantinfoX = []; + let plantinfo = $.plantinfo; + for (const vo in plantinfo) { + plantinfoX.push({ + id: plantinfo[vo].data.id, + name: plantinfo[vo].data.name, + position: plantinfo[vo].data.position, + shopid: plantinfo[vo].data.shop_id, + status: plantinfo[vo].data.status, + }); + } + $.infoArr = plantinfoX.filter(item => item.id != undefined); +} +async function fertilizerdotask() { + $.goldstatus = true; + if ($.fertilizerlist && $.fertilizertasklist) { + if ($.fertilizertasklist.shop) { + $.log("去完成关注店铺任务..") + if ($.fertilizerlist.view_shop === 0) { + await task('fertilizer_shop_view', `shop_id=${$.fertilizertasklist.shop.id}`); + await $.wait(2000); + } else { + $.log("任务完成") + } + $.log("去完成去看小样任务..") + if ($.fertilizerlist.sample_view === 0) { + await task('fertilizer_sample_view', `shop_id=${$.fertilizertasklist.shop.id}`); + await $.wait(2000); + } else { + $.log("任务完成") + } + $.log("去完成关注并浏览美妆馆任务..") + if ($.fertilizerlist.chanel_view === 0) { + await task('fertilizer_chanel_view', `shop_id=${$.fertilizertasklist.shop.id}`); + await $.wait(2000); + } else { + $.log("任务完成") + } + if (exfertilizer) { + $.log("美妆币兑换肥料..") + if ($.fertilizerlist.exchange === null || $.fertilizerlist.exchange != '5') { + for (let i = 0; i < 5; i++) { + await task('fertilizer_exchange', `shop_id=${$.fertilizertasklist.shop.id}`); + await $.wait(2000); + if (!$.goldstatus) { break } + } + } else { + console.log("今日美妆币兑换肥料已经达到最大次数") + } + } else { + $.log('你设置了美妆币不兑换肥料,如需开启请exfertilizer设置为true') + } + } + if ($.fertilizertasklist.meetingplaces) { + $.log("去完成逛会员页任务..") + if ($.fertilizertasklist.meetingplaces.length != $.fertilizerlist.view_meetingplace.length) { + for (const vo of $.fertilizertasklist.meetingplaces) { + await task('fertilizer_meetingplace_view', `meetingplace_id=${vo.id}&shop_id=${vo.shop_id}`); + await $.wait(2000); + } + } else { + $.log("任务完成") + } + } + if ($.fertilizertasklist.prodcuts) { + $.log("去完成加购任务..") + if ($.fertilizertasklist.prodcuts.length != $.fertilizerlist.view_product.length) { + for (const vo of $.fertilizertasklist.prodcuts) { + await task('fertilizer_product_view', `product_id=${vo.id}&shop_id=${vo.shop_id}`); + await $.wait(2000); + } + } else { + $.log("任务完成") + } + } + } +} +async function waterdotask() { + await task('water_task_info'); + await task('water_task_state'); + if ($.tasklist && $.viewlist) { + if ($.tasklist.shops) { + $.log("去完成浏览店铺任务..") + if ($.tasklist.shops.length != $.viewlist.view_shop.length) { + for (const vo of $.tasklist.shops) { + await task('water_shop_view', `shop_id=${vo.id}`); + await $.wait(2000); + } + } else { + $.log("任务完成") + } + } + if ($.tasklist.meetingplaces) { + $.log("去完成浏览会场任务..") + if ($.tasklist.meetingplaces.length != $.viewlist.view_meetingplace.length) { + for (const vo of $.tasklist.meetingplaces) { + await task('water_meetingplace_view', `meetingplace_id=${vo.id}`); + await $.wait(2000); + } + } else { + $.log("任务完成") + } + } + if ($.tasklist.prodcuts) { + $.log("去完成加购任务..") + if ($.tasklist.prodcuts.length != $.viewlist.view_product.length) { + for (const vo of $.tasklist.prodcuts) { + await task('water_product_view', `product_id=${vo.id}`); + await $.wait(2000); + } + } else { + $.log("任务完成") + } + } + } else { + $.log('没有获取到任务列表!') + } +} +async function task(function_id, body) { + return new Promise(async resolve => { + $.get(taskUrl(function_id, body), async (err, resp, data) => { + try { + if (data) { + data = JSON.parse(data); + switch (function_id) { + case 'get_home_info': + if (data) { + $.plantinfo = data.plant_info; + } + if (data.status_code === 403) { + $.hotFlag = true; + } + break; + case 'water_task_info': + $.tasklist = data; + break; + case 'water_task_state': + $.viewlist = data; + break; + case 'fertilizer_state': + $.fertilizerlist = data; + break; + case 'fertilizer_task_info': + $.fertilizertasklist = data; + break; + case 'merchant_secondary_pages': + if (data.shop) { + $.storefertilizer = data.user.store_fertilizer; + $.storewater = data.user.store_water; + } + if (data.status_code === 422) { + console.log(data.message) + } + break; + case 'water_shop_view': + console.log(`浏览成功,获得:${data.inc}水滴,总水滴:${data.store_water}滴水`) + break; + case 'water_meetingplace_view': + console.log(`浏览成功,获得:${data.inc}水滴,总水滴:${data.store_water}滴水`) + break; + case 'water_product_view': + console.log(`浏览成功,获得:${data.inc}水滴,总水滴:${data.store_water}滴水`) + break; + case 'fertilizer_shop_view': + console.log(`浏览成功,获得:${data.inc}肥料,总肥料:${data.store_fertilizer}肥料`) + break; + case 'fertilizer_meetingplace_view': + console.log(`浏览成功,获得:${data.inc}肥料,总肥料:${data.store_fertilizer}肥料`) + break; + case 'fertilizer_product_view': + console.log(`浏览成功,获得:${data.inc}肥料,总肥料:${data.store_fertilizer}肥料`) + break; + case 'fertilizer_sample_view': + console.log(`浏览成功,获得:${data.inc}肥料,总肥料:${data.store_fertilizer}肥料`) + break; + case 'fertilizer_chanel_view': + console.log(`浏览成功,获得:${data.inc}肥料,总肥料:${data.store_fertilizer}肥料`) + break; + case 'fertilizer_exchange': + if (data.inc) { + console.log(`兑换成功,获得:${data.inc}肥料,总肥料:${data.store_fertilizer}肥料`) + } + if (data.status_code === 422) { + console.log(data.message) + $.goldstatus = false; + } + break; + default: + $.log(JSON.stringify(data)) + break; + } + } else { + $.log(JSON.stringify(data)) + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +function taskPost(function_id, body) { + return new Promise(async resolve => { + $.post(taskPostUrl(function_id, body), async (err, resp, data) => { + try { + if (data) { + data = JSON.parse(data); + if (data) { + switch (function_id) { + case 'auth': + $.accessToken = data.access_token; + $.tokenType = data.token_type; + break; + case 'bind_friend_relation': + $.log(JSON.stringify(data)) + break; + case 'collect_water': + if (data.status_code === 422) { + console.log(data.message) + } + break; + case 'collect_fertilizer': + if (data.status_code === 422) { + console.log(data.message) + } + break; + case 'watering': + if (data.water) { + console.log(`浇水成功,目前总浇水:${data.water}滴,目前等级:${data.level}`) + } + if (data.status_code === 422) { + console.log(data.message) + $.waterstatus = false; + } + break; + case 'fertilization': + if (data.status_code === 422) { + console.log(data.message) + } else { + console.log(`施肥成功,目前总施肥:${data.fertilizer}滴,目前等级:${data.level}`) + } + break; + default: + $.log(JSON.stringify(data)) + break; + } + } else { + $.log(JSON.stringify(data)) + } + } + } catch (error) { + $.log(error) + } finally { + resolve(); + } + }) + }) +} + +function taskPostUrl(function_id, body) { + return { + url: `https://xinruimz-isv.isvjcloud.com/papi/${function_id}`, + body: body, + headers: { + "Host": "xinruimz-isv.isvjcloud.com", + "Accept": "application/x.jd-school-raffle.v1+json", + "Authorization": `Bearer undefined` ? `${$.tokenType} ${$.accessToken}` : '', + "Content-Type": "application/json;charset=utf-8", + "Origin": "https://xinruimz-isv.isvjcloud.com", + "User-Agent": UA, + "Referer": "https://xinruimz-isv.isvjcloud.com/plantation/logined_jd/", + "Connection": "keep-alive", + } + } +} + +function taskUrl(function_id, body) { + return { + url: `https://xinruimz-isv.isvjcloud.com/papi/${function_id}?${body}`, + headers: { + "Host": "xinruimz-isv.isvjcloud.com", + "Accept-Encoding": "gzip, deflate, br", + "Connection": "keep-alive", + "Accept": "application/x.jd-school-raffle.v1+json", + "User-Agent": UA, + "Authorization": `${$.tokenType} ${$.accessToken}`, + "Referer": "https://xinruimz-isv.isvjcloud.com/plantation", + 'Content-Type': 'application/json;charset=UTF-8', + } + } +} + +function getToken() { + let opt = { + url: 'https://api.m.jd.com/client.action?functionId=isvObfuscator', + body: 'body=%7B%22url%22%3A%20%22https%3A//xinruimz-isv.isvjcloud.com%22%2C%20%22id%22%3A%20%22%22%7D&uuid=5c0ee2d33a0d480b81583331a507d7fe&client=apple&clientVersion=10.1.2&st=1633632251000&sv=102&sign=3f9d552890b9c04e8602081bec67a4c7', + headers: { + "Host": "api.m.jd.com", + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "*/*", + "Connection": "keep-alive", + "User-Agent": "JD4iPhone/167541 (iPhone; iOS 13.5; Scale/3.00)", + "Accept-Encoding": "gzip, deflate, br", + "Cookie": cookie, + } + } + return new Promise(resolve => { + $.post(opt, (err, resp, data) => { + try { + if (err) { + console.log(err) + } else { + data = JSON.parse(data); + if (data) { + $.token = data.token; + } else { + $.log('京东返回了空数据') + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +function random(min, max) { + return Math.floor(Math.random() * (max - min)) + min; +} +// prettier-ignore +function getUUID(x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", t = 0) { return x.replace(/[xy]/g, function (x) { var r = 16 * Math.random() | 0, n = "x" == x ? r : 3 & r | 8; return uuid = t ? n.toString(36).toUpperCase() : n.toString(36), uuid }) } +function TotalBean() { return new Promise(async e => { const n = { url: "https://wq.jd.com/user_new/info/GetJDUserInfoUnion?sceneval=2", headers: { Host: "wq.jd.com", Accept: "*/*", Connection: "keep-alive", Cookie: cookie, "User-Agent": UA, "Accept-Language": "zh-cn", Referer: "https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&", "Accept-Encoding": "gzip, deflate, br" } }; $.get(n, (n, o, a) => { try { if (n) $.logErr(n); else if (a) { if (1001 === (a = JSON.parse(a))["retcode"]) return void ($.isLogin = !1); 0 === a["retcode"] && a.data && a.data.hasOwnProperty("userInfo") && ($.nickName = a.data.userInfo.baseInfo.nickname), 0 === a["retcode"] && a.data && a.data["assetInfo"] && ($.beanCount = a.data && a.data["assetInfo"]["beanNum"]) } else console.log("京东服务器返回空数据") } catch (e) { $.logErr(e) } finally { e() } }) }) } +function Env(t, e) { "undefined" != typeof process && JSON.stringify(process.env).indexOf("GITHUB") > -1 && process.exit(0); class s { constructor(t) { this.env = t } send(t, e = "GET") { t = "string" == typeof t ? { url: t } : t; let s = this.get; return "POST" === e && (s = this.post), new Promise((e, i) => { s.call(this, t, (t, s, r) => { t ? i(t) : e(s) }) }) } get(t) { return this.send.call(this.env, t) } post(t) { return this.send.call(this.env, t, "POST") } } return new class { constructor(t, e) { this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `🔔${this.name}, 开始!`) } isNode() { return "undefined" != typeof module && !!module.exports } isQuanX() { return "undefined" != typeof $task } isSurge() { return "undefined" != typeof $httpClient && "undefined" == typeof $loon } isLoon() { return "undefined" != typeof $loon } toObj(t, e = null) { try { return JSON.parse(t) } catch { return e } } toStr(t, e = null) { try { return JSON.stringify(t) } catch { return e } } getjson(t, e) { let s = e; const i = this.getdata(t); if (i) try { s = JSON.parse(this.getdata(t)) } catch { } return s } setjson(t, e) { try { return this.setdata(JSON.stringify(t), e) } catch { return !1 } } getScript(t) { return new Promise(e => { this.get({ url: t }, (t, s, i) => e(i)) }) } runScript(t, e) { return new Promise(s => { let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); i = i ? i.replace(/\n/g, "").trim() : i; let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r; const [o, h] = i.split("@"), n = { url: `http://${h}/v1/scripting/evaluate`, body: { script_text: t, mock_type: "cron", timeout: r }, headers: { "X-Key": o, Accept: "*/*" } }; this.post(n, (t, e, i) => s(i)) }).catch(t => this.logErr(t)) } loaddata() { if (!this.isNode()) return {}; { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e); if (!s && !i) return {}; { const i = s ? t : e; try { return JSON.parse(this.fs.readFileSync(i)) } catch (t) { return {} } } } } writedata() { if (this.isNode()) { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data); s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r) } } lodash_get(t, e, s) { const i = e.replace(/\[(\d+)\]/g, ".$1").split("."); let r = t; for (const t of i) if (r = Object(r)[t], void 0 === r) return s; return r } lodash_set(t, e, s) { return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t) } getdata(t) { let e = this.getval(t); if (/^@/.test(t)) { const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), r = s ? this.getval(s) : ""; if (r) try { const t = JSON.parse(r); e = t ? this.lodash_get(t, i, "") : e } catch (t) { e = "" } } return e } setdata(t, e) { let s = !1; if (/^@/.test(e)) { const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), o = this.getval(i), h = i ? "null" === o ? null : o || "{}" : "{}"; try { const e = JSON.parse(h); this.lodash_set(e, r, t), s = this.setval(JSON.stringify(e), i) } catch (e) { const o = {}; this.lodash_set(o, r, t), s = this.setval(JSON.stringify(o), i) } } else s = this.setval(t, e); return s } getval(t) { return this.isSurge() || this.isLoon() ? $persistentStore.read(t) : this.isQuanX() ? $prefs.valueForKey(t) : this.isNode() ? (this.data = this.loaddata(), this.data[t]) : this.data && this.data[t] || null } setval(t, e) { return this.isSurge() || this.isLoon() ? $persistentStore.write(t, e) : this.isQuanX() ? $prefs.setValueForKey(t, e) : this.isNode() ? (this.data = this.loaddata(), this.data[e] = t, this.writedata(), !0) : this.data && this.data[e] || null } initGotEnv(t) { this.got = this.got ? this.got : require("got"), this.cktough = this.cktough ? this.cktough : require("tough-cookie"), this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar, t && (t.headers = t.headers ? t.headers : {}, void 0 === t.headers.Cookie && void 0 === t.cookieJar && (t.cookieJar = this.ckjar)) } get(t, e = (() => { })) { t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]), this.isSurge() || this.isLoon() ? (this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient.get(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) })) : this.isQuanX() ? (this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t))) : this.isNode() && (this.initGotEnv(t), this.got(t).on("redirect", (t, e) => { try { if (t.headers["set-cookie"]) { const s = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString(); s && this.ckjar.setCookieSync(s, null), e.cookieJar = this.ckjar } } catch (t) { this.logErr(t) } }).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) })) } post(t, e = (() => { })) { if (t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.headers && delete t.headers["Content-Length"], this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient.post(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) }); else if (this.isQuanX()) t.method = "POST", this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t)); else if (this.isNode()) { this.initGotEnv(t); const { url: s, ...i } = t; this.got.post(s, i).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) }) } } time(t, e = null) { const s = e ? new Date(e) : new Date; let i = { "M+": s.getMonth() + 1, "d+": s.getDate(), "H+": s.getHours(), "m+": s.getMinutes(), "s+": s.getSeconds(), "q+": Math.floor((s.getMonth() + 3) / 3), S: s.getMilliseconds() }; /(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length))); for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length))); return t } msg(e = t, s = "", i = "", r) { const o = t => { if (!t) return t; if ("string" == typeof t) return this.isLoon() ? t : this.isQuanX() ? { "open-url": t } : this.isSurge() ? { url: t } : void 0; if ("object" == typeof t) { if (this.isLoon()) { let e = t.openUrl || t.url || t["open-url"], s = t.mediaUrl || t["media-url"]; return { openUrl: e, mediaUrl: s } } if (this.isQuanX()) { let e = t["open-url"] || t.url || t.openUrl, s = t["media-url"] || t.mediaUrl; return { "open-url": e, "media-url": s } } if (this.isSurge()) { let e = t.url || t.openUrl || t["open-url"]; return { url: e } } } }; if (this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(e, s, i, o(r)) : this.isQuanX() && $notify(e, s, i, o(r))), !this.isMuteLog) { let t = ["", "==============📣系统通知📣=============="]; t.push(e), s && t.push(s), i && t.push(i), console.log(t.join("\n")), this.logs = this.logs.concat(t) } } log(...t) { t.length > 0 && (this.logs = [...this.logs, ...t]), console.log(t.join(this.logSeparator)) } logErr(t, e) { const s = !this.isSurge() && !this.isQuanX() && !this.isLoon(); s ? this.log("", `❗️${this.name}, 错误!`, t.stack) : this.log("", `❗️${this.name}, 错误!`, t) } wait(t) { return new Promise(e => setTimeout(e, t)) } done(t = {}) { const e = (new Date).getTime(), s = (e - this.startTime) / 1e3; this.log("", `🔔${this.name}, 结束! 🕛 ${s} 秒`), this.log(), (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t) } }(t, e) }