1.购买服务器阿里云:服务器购买地址https://t.aliyun.com/U/W9mv4W若失效,可用地址
阿里云:
服务器购买地址
https://t.aliyun.com/U/W9mv4W
若失效,可用地址
https://www.aliyun.com/minisite/goods?source=5176.29345612&userCode=49hts92d
腾讯云:
https://curl.qcloud.com/wJpWmSfU
若失效,可用地址
https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console
华为云
https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905
2.部署教程
3.代码如下
"""
星星充电签到
每天运行一次即可
cron: 0 7 * * *
const $ = new Env("星星充电签到");
"""
import requests
import re
import os
import datetime
import hashlib
import time
if 'startoken' in os.environ:
startoken = re.split("@|&",os.environ.get("startoken"))
print(f'查找到{len(startoken)}个账号\n')
else:
startoken =['']
print('无startoken变量')
if 'starcityid' in os.environ:
cityid = os.environ.get("starcityid")
print(f'已填入cityid{cityid}')
else:
cityid = '440000'
print('没有填写cityid,系统默认使用440000')
def md5_encrypt(text):
md5_hash = hashlib.md5()
md5_hash.update(text.encode('utf-8'))
md5_result = md5_hash.hexdigest()
return md5_result
def time13():
now = datetime.datetime.now()
timestamp_ms = int(now.timestamp() * 1000) + (now.microsecond // 1000)
return str(timestamp_ms)
def signature_task(id):
return md5_encrypt('nonce=c4720525-d9fd-4db7-8420-736c0ef1c63b&taskId='+id+'&taskType=1×tamp='+time13()+'&userId=')[0:18].upper()
def find_task_ids(data):
this_week_task_id = None
this_month_task_id = None
for model in data:
for task in model['taskList']:
if task['taskName'] == '本周充电任务':
this_week_task_id = task['taskId']
elif task['taskName'] == '本月充电任务':
this_month_task_id = task['taskId']
return this_week_task_id, this_month_task_id
send_msg = ''
one_msg = ''
def Log(cont=''):
global send_msg, one_msg
if cont:
one_msg += f'{cont}\n'
send_msg += f'{cont}\n'
# 发送通知消息
def send_notification_message(title):
try:
from notify import send
print("加载通知服务成功!")
send(title, send_msg)
except Exception as e:
if e:
print('发送通知消息失败!')
def sign(token):
try:
signature = md5_encrypt('nonce=2b4aa7d9-4137-4e51-94e3-7b7355bf202a×tamp='+time13()+'&userId=')[0:18].upper()
headers = {
'Host': 'gateway.starcharge.com',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
'Referer': 'https://scm-app-h5.starcharge.com/',
'appVersion': '7.40.0',
'Origin': 'https://scm-app-h5.starcharge.com',
'signature': signature,
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Site': 'same-site',
'referrer': 'web',
'timestamp': time13(),
'positCity': cityid,
'Authorization': token,
'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
'Accept': 'application/json, text/plain, */*',
'channel-id': '98',
'Sec-Fetch-Mode': 'cors',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = "nonce=2b4aa7d9-4137-4e51-94e3-7b7355bf202a"
response = requests.post(url='https://gateway.starcharge.com/apph5/webApiV2/starPoint/sign',headers=headers, data=data)
dl_json = response.json()
if response.status_code == 200:
print(f"签到成功:获得{dl_json['data']['basePoint']}积分,已连续签到{dl_json['data']['continuousDay']}天")
Log(f"签到成功:获得{dl_json['data']['basePoint']}积分,已连续签到{dl_json['data']['continuousDay']}天")
except requests.exceptions.RequestException as e:
print("Failed to send POST request. Status Code:", response.status_code)
print("出错了:", response.text)
print(e)
def Get_list(token):
try:
signature = md5_encrypt(
'city=' + cityid + '&nonce=c4720525-d9fd-4db7-8420-736c0ef1c63b×tamp=' + time13() + '&userId=')[
0:18].upper()
headers = {'Connection': 'keep-alive',
'Authorization': token,
'Accept': 'application/json, text/plain, */*',
'positCity': cityid,
'timestamp': time13(),
'signature': signature,
'User-Agent': 'Mozilla/5.0 (Linux; Android 12; 2112123AC Build/SKQ1.211230.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/96.0.4664.104 Mobile Safari/537.36',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
}
response = requests.get(
"https://gateway.starcharge.com/apph5/webApiV2/userTask/model/list?city=" + cityid + "&nonce=c4720525-d9fd-4db7-8420-736c0ef1c63b",
headers=headers)
if response.status_code == 200:
try:
response_data = response.json()
# print("Response Data:", response_data)
return response_data['data']
except json.JSONDecodeError:
print("Response Content:", response.text)
else:
print("Failed to send POST request. Status Code:", response.status_code)
print("Response Content:", response.text)
except requests.exceptions.RequestException as e:
print("An error occurred:", e)
def Do_task(id,token):
try:
headers = {'Connection': 'keep-alive',
'Authorization': token,
'Accept': 'application/json, text/plain, */*',
'positCity': cityid,
'timestamp': time13(),
'signature': signature_task(id),
'User-Agent': 'Mozilla/5.0 (Linux; Android 12; 2112123AC Build/SKQ1.211230.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/96.0.4664.104 Mobile Safari/537.36',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
}
response = requests.get(
"https://gateway.starcharge.com/apph5/webApiV2/userTask/get?nonce=c4720525-d9fd-4db7-8420-736c0ef1c63b&taskId="+id+"&taskType=1×tamp="+time13()+"&userId=",
headers=headers)
if response.status_code == 200:
try:
response_data = response.json()
return response_data['text']
except json.JSONDecodeError:
print("Response Content:", response.text)
else:
print("Failed to send POST request. Status Code:", response.status_code)
print("Response Content:", response.text)
except requests.exceptions.RequestException as e:
print("An error occurred:", e)
def Get_info(token):
try:
signature = md5_encrypt('city=' + cityid + '&nonce=0f597ec8-f0af-48e5-bc39-473c17c3b7ae×tamp=' + time13() + '&userId=')[0:18].upper()
headers = {
'Host': 'gateway.starcharge.com',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148',
'Referer': 'https://scm-app-h5.starcharge.com/',
'appVersion': '7.40.0',
'Origin': 'https://scm-app-h5.starcharge.com',
'signature': signature,
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Site': 'same-site',
'referrer': 'web',
'timestamp': time13(),
'positCity': cityid,
'Authorization': token,
'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
'Accept': 'application/json, text/plain, */*',
'channel-id': '98',
'Sec-Fetch-Mode': 'cors',
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.get("https://gateway.starcharge.com/apph5/v2/webApiV2/star/point/user?city="+cityid+"&nonce=0f597ec8-f0af-48e5-bc39-473c17c3b7ae", headers=headers)
response_json = response.json()
if response_json['code'] == '200':
print(f'用户({response_json["data"]["nickName"]})目前金币:{response_json["data"]["points"]}')
Log(f'用户({response_json["data"]["nickName"]})目前金币:{response_json["data"]["points"]}\n')
return True
elif response_json['code'] == '402':
print('用户数据获取失败,重新尝试获取数据')
print(response.text)
return False
else:
print(response.text)
return False
except requests.exceptions.RequestException as e:
print("An error occurred:", e)
except Exception as e:
print("出错了:", e)
def main():
z = 1
for ck in startoken:
try:
print(f'登录第{z}个账号')
print('----------------------')
print('\n开始签到操作>>>>>>>>>>\n')
sign(ck)
print('\n完成日常任务>>>>>>>>>>\n')
this_week_id, this_month_id = find_task_ids(Get_list(ck))
print("本周充电任务:", Do_task(this_week_id,ck))
print("本月充电任务:", Do_task(this_month_id,ck))
print('\n获取用户信息>>>>>>>>>>\n')
while True:
if Get_info(ck):
break
time.sleep(3)
print('\n----------------------')
z = z + 1
except Exception as e:
print(e)
if __name__ == '__main__':
try:
main()
except Exception as e:
print(e)
try:
send_notification_message(title='星星充电') # 发送通知
except Exception as e:
print(e)
解析
该脚本为星星充电签到脚本,脚本主要作用如下:
使用从 App 抓到的 Authorization(环境变量
startoken
,可多账号)调用星星充电 H5 接口:每日签到获取积分;
拉取任务模型并执行 "本周充电任务 / 本月充电任务";
查询并展示当前用户积分;
可选通过本地
notify.send
进行统一消息推送。支持多账号(
startoken
用&
或@
分隔),可指定或默认城市 ID(starcityid
,默认440000
)。
主要方法
main() | startoken → sign() 签到 → Get_list() 拉任务 → Do_task() 完成"本周/本月任务" → Get_info() 查询积分并打印;最后尝试 send_notification_message() 推送汇总。 |
sign(token) | 每日签到/apph5/webApiV2/starPoint/sign ,解析返回的 basePoint (获得积分)、continuousDay (连续天数)。 |
Get_list(token) | 获取任务模型列表/apph5/webApiV2/userTask/model/list (带 city、nonce 等),返回 data 供后续筛选。 |
find_task_ids(data) | data 中定位 "本周充电任务" 和 "本月充电任务" 的 taskId 。 |
Do_task(taskId, token) | 执行单个任务/apph5/webApiV2/userTask/get (带 taskId 、taskType=1 ),返回任务处理结果文本。 |
Get_info(token) | 查询用户积分/apph5/v2/webApiV2/star/point/user ,打印并记录昵称与积分;若返回 402 则重试。 |
send_notification_message(title) | notify.send ,将累积日志内容一次性推送。 |
Log(cont) | |
md5_encrypt(text) | |
time13() | |
signature_task(id) | taskId 后 MD5,取前 18 位并转大写)。 |
环境变量
startoken
:必填,从 App 抓包得到的Authorization
,多账号用&
或@
分隔。starcityid
:可选,城市 ID,未填则默认440000
。
总流程:读 token → 签到 → 拉取并执行本周/本月任务 → 查积分 →(可选)推送。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论