Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #15 from Limourli-liu/master
Browse files Browse the repository at this point in the history
Limourli-liu:master添加验证码识别功能
  • Loading branch information
potatoshred authored Oct 26, 2021
2 parents d93b74f + b34d2eb commit 6930960
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 24 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Daily Fudan"

on:
schedule:
- cron: "0 22 * * *" # scheduled at 06:00 (UTC+8) everyday
- cron: "17 22,5 * * *" # scheduled at 06:17 & 13:17 (UTC+8) everyday
workflow_dispatch:

env:
Expand All @@ -28,9 +28,10 @@ jobs:
run: |
git config --global user.name github-actions
git config --global user.email github-actions@github.com
git remote add upstream https://github.com/k652/daily_fudan
git config --global pull.rebase true
git remote add upstream https://github.com/Limourli-liu/daily_fudan.git
git pull upstream master --allow-unrelated-histories
git push origin master
git push origin master --force
- name: Set up python
uses: actions/setup-python@v2
with:
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# 免责声明
郑重声明:本人只是使用该脚本测试微信通知功能,并不了解脚本本身功能,未参与脚本开发,不承担一切相关与连带责任。
以下大部分为原作者的内容

# Daily_Fudan
> 一键平安复旦小脚本
>
Expand Down Expand Up @@ -26,7 +31,7 @@
<details>
<summary>查看教程</summary>

- 项目地址:[github/daily_fudan](https://github.com/k652/daily_fudan)
- 项目地址:[github/daily_fudan](https://github.com/Limourli-liu/daily_fudan)
- 点击右上角`Fork`到自己的账号下

![fork](https://i.loli.net/2020/10/28/qpXowZmIWeEUyrJ.png)
Expand All @@ -41,10 +46,14 @@
![new-secret.png](https://i.loli.net/2020/10/28/sxTuBFtRvzSgUaA.png)

- 建立名为`FUDAN`的 secret,值为`学号`+`(空格)`+`密码`,最后点击`Add secret`

- secret名字必须为`FUDAN`
- secret名字必须为`FUDAN`
- secret名字必须为`FUDAN`
- 如果要开启成功填写的通知,在 http://iyuu.cn/ 申请token 然后在密码后面+ `(空格)`+`token`
- `学号`+`(空格)`+`密码`+ `(空格)`+`token`
- 如果要开启验证码识别,在 http://www.kuaishibie.cn/ 注册账号
然后在token后面 + `(空格)`+`uname` + `(空格)`+`pwd`
- `学号`+`(空格)`+`密码`+ `(空格)`+`token`+`(空格)`+`uname` + `(空格)`+`pwd`

### 4. 启用 Actions

Expand Down
Binary file added __pycache__/captcha_break.cpython-39.pyc
Binary file not shown.
92 changes: 92 additions & 0 deletions captcha_break.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import base64
import json
import sys
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def base64_api(uname, pwd, img, typeid):
base64_data = base64.b64encode(img)
b64 = base64_data.decode()
data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
return result

def reportError(id):
data = {"id": id}
result = json.loads(requests.post("http://api.kuaishibie.cn/reporterror.json", json=data).text)
if result['success']:
return "报错成功"
else:
return result["message"]

from sys import exit as sys_exit
def getCaptchaData(zlapp):
url = 'https://zlapp.fudan.edu.cn/backend/default/code'
headers = {'accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
'accept-encoding': 'gzip',
'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'dnt': '1',
'referer': 'https://zlapp.fudan.edu.cn/site/ncov/fudanDaily',
'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
'sec-ch-ua-mobile': '?0',
'sec-fetch-dest': 'image',
'sec-fetch-mode': 'no-cors',
'sec-fetch-site': 'same-origin',
"User-Agent": zlapp.UA}
res = zlapp.session.get(url, headers=headers)
return res.content

class DailyFDCaptcha:
zlapp = None
uname = ''
pwd = ''
typeid = 2 # 纯英文
info = lambda x: x
id = 0
def __init__(self,
uname, pwd,
zlapp,
info_callback):
self.zlapp = zlapp
self.uname = uname
self.pwd = pwd
self.info = info_callback
def __call__(self):
img = getCaptchaData(self.zlapp)
result = base64_api(self.uname,self.pwd,img,self.typeid)
print(result)
if result['success']:
self.id = result["data"]["id"]
return result["data"]["result"]
else:
self.info(result["message"])
def reportError(self):
if self.id != 0:
self.info(reportError(self.id))

if __name__ == "__main__":
def base64_api(uname, pwd, img, typeid):
return {
"success": False,
"code": "-1",
"message": "用户名或密码错误",
"data": ""
}
print(base64_api(0,0,0,0))
test = DailyFDCaptcha(0,0,0,print)
test(0)
def base64_api(uname, pwd, img, typeid):
return {
"success": True,
"code": "0",
"message": "success",
"data": {
"result": "hhum",
"id": "00504808e68a41ad83ab5c1e6367ae6b"
}
}
print(test(0))
def reportError(id):
return id
test.reportError()
117 changes: 98 additions & 19 deletions dailyFudan.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from json import loads as json_loads
from json import dumps as json_dumps
from os import path as os_path
from sys import exit as sys_exit
from sys import argv as sys_argv
Expand All @@ -10,6 +11,29 @@
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')

# WeChat notice
#get token via http://iyuu.cn/
import requests
from captcha_break import DailyFDCaptcha
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def iyuu(IYUU_TOKEN):
url = f"https://iyuu.cn/{IYUU_TOKEN}.send"
headers = {'Content-type': 'application/x-www-form-urlencoded'}
def send(text, desp=""):
Form = {'text': text, 'desp': desp}
return requests.post(url, data=Form, headers=headers, verify=False)
return send

# fix random area bug
def set_q(iterO):
res = list()
for item in iterO:
if item not in res:
res.append(item)
return res



class Fudan:
"""
Expand Down Expand Up @@ -93,9 +117,11 @@ def login(self):

if post.status_code == 302:
logging.debug("登录成功")
return True
else:
logging.debug("登录失败,请检查账号信息")
self.close()
return False

def logout(self):
"""
Expand All @@ -116,7 +142,7 @@ def close(self):
self.logout()
self.session.close()
logging.debug("关闭会话")
sys_exit()
# sys_exit() 通知完成再退出 注释掉

class Zlapp(Fudan):
last_info = ''
Expand All @@ -143,11 +169,21 @@ def check(self):
if last_info["d"]["info"]["date"] == today:
logging.info("今日已提交")
self.close()
global gl_info
gl_info = last_info
geo_api_info = json_loads(last_info["d"]["info"]["geo_api_info"])
province = geo_api_info["addressComponent"].get("province", "")
city = geo_api_info["addressComponent"].get("city", "") or province
district = geo_api_info["addressComponent"].get("district", "")
gl_info['dailyFudan'] = " ".join(set_q((province, city, district)))
gl_info = json_dumps(gl_info, indent=4, ensure_ascii=False)
return True
else:
logging.info("未提交")
self.last_info = last_info["d"]["info"]
return False

def checkin(self):
def checkin(self, captcha):
"""
提交
"""
Expand All @@ -170,39 +206,82 @@ def checkin(self):
"tw" : "13",
"province": province,
"city" : city,
"area" : " ".join(set((province, city, district))),
"area" : " ".join(set_q((province, city, district))),
"ismoved" : 0
}
)
# logging.debug(self.last_info)

save = self.session.post(
'https://zlapp.fudan.edu.cn/ncov/wap/fudan/save',
data=self.last_info,
headers=headers,
allow_redirects=False)

save_msg = json_loads(save.text)["m"]
logging.info(save_msg)
for i in range(3):
captcha_text = captcha()
#captcha_text = 'abcd'
self.last_info.update({
'sfzx': 1,
'code': captcha_text
})
save = self.session.post(
'https://zlapp.fudan.edu.cn/ncov/wap/fudan/save',
data=self.last_info,
headers=headers,
allow_redirects=False)

save_msg = json_loads(save.text)["m"]
logging.info(save_msg)
if save_msg != '验证码错误':
break
else:
captcha.reportError()
print('captcha.reportError')

def get_account():
"""
获取账号信息
"""
uid, psw = sys_argv[1].strip().split(' ')
return uid, psw
uid, psw, *IYUU_TOKEN = sys_argv[1].strip().split(' ')
return uid, psw, IYUU_TOKEN

gl_info = "快去手动填写!"
if __name__ == '__main__':
uid, psw = get_account()
uid, psw, IYUU_TOKE = get_account()
if IYUU_TOKE: #有token则通知,无token不通知
if len(IYUU_TOKE) != 3:
logging.error("请正确配置微信通知功能和验证码打码功能~\n")
sys_exit(1)
uname = IYUU_TOKE[1]
pwd = IYUU_TOKE[2]
IYUU_TOKE = IYUU_TOKE[0]
if IYUU_TOKE.startswith('IYUU'):
iy_info = iyuu(IYUU_TOKE)
else:
def iy_info(text, desp=""):
pass
else:
def iy_info(text, desp=""):
pass
logging.error("请按readme操作,以正确完成配置~\n")
sys_exit(1)

# logging.debug("ACCOUNT:" + uid + psw)
zlapp_login = 'https://uis.fudan.edu.cn/authserver/login?' \
'service=https://zlapp.fudan.edu.cn/site/ncov/fudanDaily'
daily_fudan = Zlapp(uid, psw, url_login=zlapp_login)
daily_fudan.login()
if not daily_fudan.login():
iy_info("平安复旦:登陆失败", gl_info)
sys_exit()

if daily_fudan.check():
iy_info("平安复旦:今日已提交", gl_info)
sys_exit()

def captcha_info(message):
iy_info(message, gl_info)
captcha = DailyFDCaptcha(uname,pwd,daily_fudan,captcha_info)
daily_fudan.checkin(captcha)

daily_fudan.check()
daily_fudan.checkin()
# 再检查一遍
daily_fudan.check()
if daily_fudan.check():
iy_info("平安复旦:今日已提交", gl_info)
else:
iy_info("平安复旦:本次提交失败", gl_info)

daily_fudan.close()
sys_exit()

0 comments on commit 6930960

Please sign in to comment.