├── README.md ├── Snipaste_2021-04-24_13-44-31.png ├── oshwhub_autosign.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # oshwhub_autosign 2 | 请参考新仓库https://github.com/seishinkouki/next_oshwhub_autosignin 3 | -------------------------------------------------------------------------------- /Snipaste_2021-04-24_13-44-31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seishinkouki/oshwhub_autosign/27709be4ebb3803fd2bca7253a00cba06bd1ce30/Snipaste_2021-04-24_13-44-31.png -------------------------------------------------------------------------------- /oshwhub_autosign.py: -------------------------------------------------------------------------------- 1 | import json 2 | import math 3 | import random 4 | import re 5 | import time 6 | import requests 7 | import hashlib 8 | import os 9 | from bs4 import BeautifulSoup 10 | from loguru import logger 11 | 12 | 13 | def cookies2dict(_cookies): 14 | _cookieDict = {} 15 | _cookies = _cookies.split("; ") 16 | for co in _cookies: 17 | co = co.strip() 18 | p = co.split('=') 19 | value = co.replace(p[0] + '=', '').replace('"', '') 20 | _cookieDict[p[0]] = value 21 | return _cookieDict 22 | 23 | 24 | def uuid_generator(): 25 | uuid_pattern = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" 26 | uuid = "" 27 | now_t = int(round(time.time() * 1000000)) / 1000.0 28 | for i in uuid_pattern: 29 | e = (int(now_t + 16 * random.random()) % 16) | 0 30 | now_t = math.floor(now_t / 16) 31 | if i != "-": 32 | uuid = uuid + hex(e if i == "x" else 3 & e | 8)[-1:] 33 | else: 34 | uuid = uuid + "-" 35 | # print(uuid) 36 | return uuid 37 | 38 | 39 | def coolpush(token, msg): 40 | return json.loads(requests.post("https://push.xuthus.cc/send/" + token, data=msg).content)['message'] 41 | 42 | 43 | def weixinpush(corpid, corpsecret, agentid, msg): 44 | base_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?' 45 | req_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' 46 | data = { 47 | "touser": "@all", 48 | "toparty": "@all", 49 | "totag": "@all", 50 | "msgtype": "text", 51 | "agentid": agentid, 52 | "text": { 53 | "content": msg 54 | }, 55 | "safe": 0, 56 | "enable_id_trans": 0, 57 | "enable_duplicate_check": 0, 58 | "duplicate_check_interval": 1800 59 | } 60 | data = json.dumps(data) 61 | urls = base_url + 'corpid=' + corpid + '&corpsecret=' + corpsecret 62 | resp = requests.get(urls).json() 63 | access_token = resp['access_token'] 64 | req_urls = req_url + access_token 65 | res = requests.post(url=req_urls, data=data) 66 | return res.text 67 | 68 | 69 | class Oshwhub: 70 | sign_Statistics = "" 71 | three_reward_Statistics = "" 72 | seven_reward_Statistics = "" 73 | sign_flag = 1 74 | three_reward_flag = 1 75 | seven_reward_flag = 1 76 | User_Agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " \ 77 | "Chrome/86.0.4240.198 Safari/537.36 " 78 | cookies_Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng," \ 79 | "*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 " 80 | url_oshw = "https://oshwhub.com" 81 | url_oshw2passport = "https://oshwhub.com/login?from=https%3A%2F%2Foshwhub.com" 82 | url_login = "https://passport.szlcsc.com/login" 83 | url_signIn = "https://oshwhub.com/api/user/sign_in" 84 | url_threeDay = "https://oshwhub.com/api/user/sign_in/getTreeDayGift" 85 | url_sevenDay = "https://oshwhub.com/api/user/sign_in/getSevenDayGift" 86 | url_giftInfo = "https://oshwhub.com/api/user/sign_in/getUnbrokenGiftInfo" 87 | 88 | def __init__(self, phone, passwd): 89 | self.phone = phone 90 | self.passwd = passwd 91 | 92 | def auto_sign(self): 93 | oshw_res = requests.get(self.url_oshw) 94 | 95 | # 后面需要用到acw_tc oshwhub_session oshwhubReferer 96 | _oshw_cookies = cookies2dict(oshw_res.headers['Set-Cookie']) 97 | # print("未登录状态oshw网域的cookies:", _oshw_cookies) 98 | logger.info('开始获取未登录状态oshw cookies...') 99 | # print(str(_oshw_cookies).replace("'", "").split(",")[4][17:]) 100 | _acw_tc = _oshw_cookies['acw_tc'].split(";")[0] 101 | # _oshwhub_session = str(_oshw_cookies).replace("'", "").split(",")[1][17:] 102 | # _oshwhubReferer = str(_oshw_cookies).replace("'", "").split(",")[4][17:] 103 | # _CASAuth = _oshw_cookies['CASAuth'] 104 | 105 | oshw_headers = { 106 | # "X-Forwarded/-For": "8.8.8.8", 107 | "Accept": self.cookies_Accept, 108 | "Accept-Encoding": "gzip, deflate, br", 109 | "Accept-Language": "zh-CN,zh;q=0.9", 110 | "Cache-Control": "no-cache", 111 | "Connection": "keep-alive", 112 | "Cookie": requests.get(self.url_oshw).headers['Set-Cookie'], 113 | "Host": "oshwhub.com", 114 | "Pragma": "no-cache", 115 | "Referer": "https://oshwhub.com/", 116 | "Sec-Fetch-Dest": "document", 117 | "Sec-Fetch-Mode": "navigate", 118 | "Sec-Fetch-Site": "same-origin", 119 | "Sec-Fetch-User": "?1", 120 | "Upgrade-Insecure-Requests": "1", 121 | "User-Agent": self.User_Agent 122 | } 123 | login_res = requests.get(self.url_oshw2passport, headers=oshw_headers, allow_redirects=False) 124 | oshw2passport_cookies = cookies2dict(login_res.headers['Set-Cookie']) 125 | # print("跳转到PASSPORT过程中获取CASAuth:", oshw2passport_cookies['CASAuth']) 126 | logger.info('开始获取CASAuth...') 127 | 128 | passport_headers = { 129 | #"X-Forwarded-For": "8.8.8.8", 130 | "Accept": self.cookies_Accept, 131 | "Accept-Encoding": "gzip, deflate, br", 132 | "Accept-Language": "zh-CN,zh;q=0.9", 133 | "Cache-Control": "no-cache", 134 | "Connection": "keep-alive", 135 | "Host": "passport.szlcsc.com", 136 | "Pragma": "no-cache", 137 | "Referer": "https://oshwhub.com/", 138 | "Sec-Fetch-Dest": "document", 139 | "Sec-Fetch-Mode": "navigate", 140 | "Sec-Fetch-Site": "cross-site", 141 | "Sec-Fetch-User": "?1", 142 | "Upgrade-Insecure-Requests": "1", 143 | "User-Agent": self.User_Agent 144 | } 145 | passport_res = requests.get(login_res.headers['Location'], headers=passport_headers, allow_redirects=False) 146 | # print("PASSPORT网域下acw_tc:", passport_cookies['acw_tc']) 147 | 148 | passport_headers2 = { 149 | #"X-Forwarded-For": "8.8.8.8", 150 | "Accept": self.cookies_Accept, 151 | "Accept-Encoding": "gzip, deflate, br", 152 | "Accept-Language": "zh-CN,zh;q=0.9", 153 | "Cache-Control": "no-cache", 154 | "Connection": "keep-alive", 155 | "Cookie": passport_res.headers['Set-Cookie'], 156 | "Host": "passport.szlcsc.com", 157 | "Pragma": "no-cache", 158 | "Referer": "https://oshwhub.com/", 159 | "Sec-Fetch-Dest": "document", 160 | "Sec-Fetch-Mode": "navigate", 161 | "Sec-Fetch-Site": "cross-site", 162 | "Sec-Fetch-User": "?1", 163 | "Upgrade-Insecure-Requests": "1", 164 | "User-Agent": self.User_Agent 165 | } 166 | passport_res = requests.get(passport_res.headers['Location'], headers=passport_headers2) 167 | SESSION = passport_res.headers['Set-Cookie'].split(";")[-4].split("=")[-1] 168 | # print("获取新SESSION:", SESSION) 169 | logger.info('开始获取新SESSION...') 170 | 171 | LT = re.findall(r'', passport_res.text) 172 | # print("获取登录表单里lt参数:", LT[0]) 173 | logger.info('开始获取登录表单里lt参数...') 174 | 175 | login_headers = { 176 | #"X-Forwarded-For": "8.8.8.8", 177 | "Accept": self.cookies_Accept, 178 | "Accept-Encoding": "gzip, deflate, br", 179 | "Accept-Language": "zh-CN,zh;q=0.9", 180 | "Cache-Control": "no-cache", 181 | "Connection": "keep-alive", 182 | "Content-Length": "373", 183 | "Content-Type": "application/x-www-form-urlencoded", 184 | "Host": "passport.szlcsc.com", 185 | "Origin": "https://passport.szlcsc.com", 186 | "Pragma": "no-cache", 187 | "Referer": "https://passport.szlcsc.com/login?service=https%3A%2F%2Foshwhub.com%2Flogin%3Ff%3Doshwhub", 188 | "Sec-Fetch-Dest": "document", 189 | "Sec-Fetch-Mode": "navigate", 190 | "Sec-Fetch-Site": "same-origin", 191 | "Sec-Fetch-User": "?1", 192 | "Upgrade-Insecure-Requests": "1", 193 | "User-Agent": self.User_Agent 194 | } 195 | login_cookies = { 196 | "AGL_USER_ID": uuid_generator(), 197 | "fromWebSite": "oshwhub", 198 | "SESSION": SESSION 199 | } 200 | form_data = { 201 | "lt": LT[0], 202 | "execution": "e1s1", 203 | "_eventId": "submit", 204 | "loginUrl": "https://passport.szlcsc.com/login?service=https%3A%2F%2Foshwhub.com%2Flogin%3Ff%3Doshwhub", 205 | "afsId": "", 206 | "sig": "", 207 | "token": "", 208 | "scene": "login", 209 | "loginFromType": "shop", 210 | "showCheckCodeVal": "false", 211 | "pwdSource": "", 212 | "username": self.phone, 213 | "password": hashlib.md5(self.passwd.encode('utf-8')).hexdigest(), 214 | "rememberPwd": "yes", 215 | } 216 | logger.info('开始登陆...') 217 | try: 218 | passport_res = requests.post(self.url_login, data=form_data, headers=login_headers, cookies=login_cookies, 219 | allow_redirects=False) 220 | except KeyError: 221 | self.sign_Statistics = "签到结果: 登录失败, 可能原因1:用户密码错误2:登录需要验证" 222 | return 223 | # print(passport_res.headers['Location']) 224 | # print(passport_res.headers['Set-Cookie']) 225 | # print(passport_res.json) 226 | 227 | # 验证ticket 228 | oshw_headers = { 229 | #"X-Forwarded-For": "8.8.8.8", 230 | "Accept": self.cookies_Accept, 231 | "Accept-Encoding": "gzip, deflate, br", 232 | "Accept-Language": "zh-CN,zh;q=0.9", 233 | "Cache-Control": "no-cache", 234 | "Connection": "keep-alive", 235 | "Host": "oshwhub.com", 236 | "Pragma": "no-cache", 237 | "Referer": "https://passport.szlcsc.com/login?service=https%3A%2F%2Foshwhub.com%2Flogin%3Ff%3Doshwhub", 238 | "Sec-Fetch-Dest": "document", 239 | "Sec-Fetch-Mode": "navigate", 240 | "Sec-Fetch-Site": "same-origin", 241 | "Sec-Fetch-User": "?1", 242 | "Upgrade-Insecure-Requests": "1", 243 | "User-Agent": self.User_Agent 244 | } 245 | oshw_cookies = { 246 | "acw_tc": _acw_tc, 247 | # "oshwhubReferer": "_oshwhubReferer", 248 | # "oshwhub_session": "_oshwhub_session", 249 | "CASAuth": oshw2passport_cookies['CASAuth'] 250 | } 251 | # print(oshw_cookies['acw_tc']) 252 | # print(oshw_cookies['oshwhubReferer']) 253 | # print(oshw_cookies['oshwhub_session']) 254 | # print(oshw_cookies['CASAuth']) 255 | 256 | # print(oshw_cookies) 257 | # 验证ticket 258 | logger.info('开始验证ticket...') 259 | try: 260 | oshw_res = requests.get(passport_res.headers['Location'], headers=oshw_headers, cookies=oshw_cookies, 261 | allow_redirects=False) 262 | except KeyError: 263 | self.sign_Statistics = "签到结果: 登录失败, 可能原因1:用户密码错误2:登录需要验证" 264 | return 265 | # print(oshw_res.headers['Location']) 266 | # 更新session 267 | logger.info('更新SESSION...') 268 | oshw_res = requests.get(oshw_res.headers['Location'], headers=oshw_headers, cookies=oshw_cookies, 269 | allow_redirects=False) 270 | oshw_cookies['oshwhub_session'] = cookies2dict(oshw_res.headers['Set-Cookie'])['oshwhub_session'] 271 | # print(oshw_res.headers['Set-Cookie']) 272 | # print(oshw_cookies) 273 | 274 | # 跳转oshw主页 275 | oshw_res = requests.get(oshw_res.headers['Location'], headers=oshw_headers, cookies=oshw_cookies, 276 | allow_redirects=False) 277 | oshw_cookies['oshwhub_session'] = cookies2dict(oshw_res.headers['Set-Cookie'])['oshwhub_session'] 278 | # print(oshw_cookies) 279 | 280 | # 签到 281 | # 签到状态检查 282 | # 获取签到页面 283 | soup = BeautifulSoup( 284 | requests.get("https://oshwhub.com/sign_in", headers=oshw_headers, cookies=oshw_cookies).text, "html.parser") 285 | 286 | for tag in soup.find_all("button", attrs={'class': "btn btn-secondary"}): 287 | if tag.get_text() == "已签到": 288 | self.sign_Statistics = "已签到过,取消签到" 289 | self.sign_flag = 0 290 | 291 | # oshw_cookies = cookies2dict(oshw_res.headers['Set-Cookie']) 292 | if self.sign_flag: 293 | oshw_sign = requests.post(self.url_signIn, headers=oshw_headers, cookies=oshw_cookies) 294 | oshw_cookies['oshwhub_session'] = cookies2dict(oshw_res.headers['Set-Cookie'])['oshwhub_session'] 295 | # print(oshw_cookies) 296 | # print("签到结果:", json.loads(oshw_sign.content)) 297 | if not json.loads(oshw_sign.content)['code']: 298 | self.sign_Statistics = "签到成功" 299 | else: 300 | self.sign_Statistics = json.loads(oshw_sign.content)['message'] 301 | 302 | # 签到后刷新页面 303 | soup = BeautifulSoup( 304 | requests.get("https://oshwhub.com/sign_in", headers=oshw_headers, cookies=oshw_cookies).text, "html.parser") 305 | # 三天奖励状态 306 | for tag in soup.find_all("div", attrs={'class': "three-day"}): 307 | if tag.attrs['data-status'] == "0": 308 | self.three_reward_Statistics = "天数不够,取消领取" 309 | self.three_reward_flag = 0 310 | elif tag.attrs['data-status'] == "2": 311 | self.three_reward_Statistics = "已领取过,取消领取" 312 | self.three_reward_flag = 0 313 | 314 | if self.three_reward_flag: 315 | # 获取三天签到奖励 316 | oshw_res = requests.get(self.url_threeDay, headers=oshw_headers, cookies=oshw_cookies) 317 | oshw_cookies['oshwhub_session'] = cookies2dict(oshw_res.headers['Set-Cookie'])['oshwhub_session'] 318 | # print(oshw_cookies) 319 | # print("三天奖励结果:", json.loads(oshw_res.content)) 320 | if not json.loads(oshw_res.content)['code']: 321 | self.three_reward_Statistics = "三天奖励领取结果: 领取成功" 322 | else: 323 | # self.three_reward_Statistics = "三天奖励领取结果: " + json.loads(oshw_res.content)['message'] 324 | self.three_reward_Statistics = json.loads(oshw_res.content)['message'] 325 | 326 | # 七天奖励状态 327 | for tag in soup.find_all("div", attrs={'class': "seven-day"}): 328 | if tag.attrs['data-status'] == "0": 329 | self.seven_reward_Statistics = "天数不够,取消领取" 330 | self.seven_reward_flag = 0 331 | elif tag.attrs['data-status'] == "2": 332 | self.seven_reward_Statistics = "已领取过,取消领取" 333 | self.seven_reward_flag = 0 334 | 335 | if self.seven_reward_flag: 336 | # 获取七日奖品信息 337 | oshw_res = requests.get(self.url_giftInfo, headers=oshw_headers, cookies=oshw_cookies) 338 | oshw_cookies['oshwhub_session'] = cookies2dict(oshw_res.headers['Set-Cookie'])['oshwhub_session'] 339 | # print("七天奖品信息:", json.loads(oshw_res.content)) 340 | uuid = json.loads(oshw_res.content)['result']['sevenDay']['uuid'] 341 | coupon_uuid = json.loads(oshw_res.content)['result']['sevenDay']['coupon_uuid'] 342 | coupon_name = json.loads(oshw_res.content)['result']['sevenDay']['name'] 343 | 344 | coupon_data = { 345 | "gift_uuid": uuid, 346 | "coupon_uuid": coupon_uuid 347 | } 348 | # 领取七日奖励 349 | oshw_res = requests.post(self.url_sevenDay, data=coupon_data, headers=oshw_headers, cookies=oshw_cookies) 350 | # print("七天奖励结果:", json.loads(oshw_res.content)) 351 | if not json.loads(oshw_res.content)['code']: 352 | self.seven_reward_Statistics = "七天奖励领取成功, 奖品为: " + json.loads(oshw_res.content)['result']['info'] 353 | else: 354 | # self.seven_reward_Statistics = "七天奖励领取结果: " + json.loads(oshw_res.content)['message'] 355 | self.seven_reward_Statistics = json.loads(oshw_res.content)['message'] 356 | 357 | 358 | url_pushplus = "http://www.pushplus.plus/send" 359 | 360 | # 需修改部分 361 | OSHW = '{"1300000": "123"}' 362 | 363 | # 推送加 推送 364 | # pushplus token 365 | pushplus_token = "" 366 | 367 | # qq酷推 推送 368 | # coolpush token 369 | coolpush_token = "" 370 | 371 | # 微信推送 372 | corpid = 'wwxxxx' # 微信企业ID 373 | corpsecret = 'abcdef' # 企业微信应用的Secret 374 | agentid = 00000000 # 企业微信应用的id 375 | # #### 376 | 377 | if __name__ == '__main__': 378 | try: 379 | users = json.loads(OSHW) 380 | except json.decoder.JSONDecodeError: 381 | logger.error('用户名密码解析失败, 请检查secret OSHW 的格式') 382 | else: 383 | logger.info("需签到用户数量: " + str(len(users))) 384 | for key in users: 385 | logger.info("开始用户" + key[:3] + "*******" + key[-2:] + "的签到...") 386 | my_user = Oshwhub(key, users[key]) 387 | my_user.auto_sign() 388 | if '错误' in my_user.sign_Statistics: 389 | logger.error(my_user.sign_Statistics) 390 | else: 391 | logger.info(my_user.sign_Statistics) 392 | logger.info(my_user.three_reward_Statistics) 393 | logger.info(my_user.seven_reward_Statistics) 394 | Statistics_data = { 395 | "签到结果": my_user.sign_Statistics, 396 | "三天奖励结果": my_user.three_reward_Statistics, 397 | "七天奖励结果": my_user.seven_reward_Statistics 398 | } 399 | push_payload = { 400 | "token": pushplus_token, 401 | "title": "用户" + key[:3] + "*******" + key[-2:] + "签到结果", 402 | "content": str(Statistics_data), 403 | "template": "json" 404 | } 405 | coolpush_payload = key[:3] + "*******" + key[-2:] + "\r\n" + \ 406 | "签到结果: " + my_user.sign_Statistics + "\r\n" + \ 407 | "三天奖励结果: " + my_user.three_reward_Statistics + "\r\n" + \ 408 | "七天奖励结果: " + my_user.seven_reward_Statistics 409 | 410 | if my_user.sign_flag or my_user.three_reward_flag or my_user.seven_reward_flag: 411 | if len(coolpush_token) == 32: 412 | logger.info('推送结果: ' + coolpush(coolpush_token, coolpush_payload.encode('UTF-8'))) 413 | elif len(pushplus_token) == 32: 414 | # pushplus 的请求方式需要把信息json.dumps一下 415 | body = json.dumps(push_payload).encode(encoding='utf-8') 416 | headers = {'Content-Type': 'application/json'} 417 | # 推送结果返回改为msg,data目前只会返回流水号。 418 | logger.info('推送结果: ' + json.loads(requests.post(url_pushplus, data=body,headers=headers).content)['msg']) 419 | elif agentid != 0: 420 | logger.info( 421 | '推送结果: ' + json.loads(weixinpush(corpid, corpsecret, agentid, coolpush_payload))['errmsg']) 422 | else: 423 | logger.warning('未设置推送类型') 424 | else: 425 | logger.info('未发生新任务,不进行推送') 426 | logger.info('==程序执行结束==') 427 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests~=2.26.0 2 | beautifulsoup4~=4.9.3 3 | loguru~=0.5.3 4 | --------------------------------------------------------------------------------