mirror of
https://github.com/cqwu-ehall/cqwu-ehall.git
synced 2024-11-21 18:38:18 +00:00
✨ Support query pay
This commit is contained in:
parent
c6f9a5cd92
commit
89e854c74d
@ -29,10 +29,11 @@ class Client(Methods):
|
|||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
self.me: Optional[User] = None
|
self.me: Optional[User] = None
|
||||||
self._use_password_login = False
|
self._use_password_login = False
|
||||||
self.xue_nian = 2022
|
self.xue_nian = 2023
|
||||||
""" 学年 """
|
""" 学年 """
|
||||||
self.xue_qi = 1
|
self.xue_qi = 0
|
||||||
""" 学期,0 为第一学期,1 为第二学期 """
|
""" 学期,0 为第一学期,1 为第二学期 """
|
||||||
|
self._pay_x_token = ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_input(word: str = "", is_int: bool = False):
|
def get_input(word: str = "", is_int: bool = False):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from .auth import Auth
|
from .auth import Auth
|
||||||
from .epay import EPay
|
from .epay import EPay
|
||||||
|
from .pay import Pay
|
||||||
from .users import Users
|
from .users import Users
|
||||||
from .webvpn import WebVPN
|
from .webvpn import WebVPN
|
||||||
from .xg import XG
|
from .xg import XG
|
||||||
@ -8,6 +9,7 @@ from .xg import XG
|
|||||||
class Methods(
|
class Methods(
|
||||||
Auth,
|
Auth,
|
||||||
EPay,
|
EPay,
|
||||||
|
Pay,
|
||||||
Users,
|
Users,
|
||||||
WebVPN,
|
WebVPN,
|
||||||
XG,
|
XG,
|
||||||
|
29
cqwu/methods/pay/__init__.py
Normal file
29
cqwu/methods/pay/__init__.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
import cqwu
|
||||||
|
|
||||||
|
from .get_pay_project_detail import GetPayProjectDetail
|
||||||
|
from .get_pay_projects import GetPayProjects
|
||||||
|
from .get_pay_user import GetPayUser
|
||||||
|
|
||||||
|
|
||||||
|
class Pay(
|
||||||
|
GetPayProjectDetail,
|
||||||
|
GetPayProjects,
|
||||||
|
GetPayUser,
|
||||||
|
):
|
||||||
|
async def _oauth_pay(
|
||||||
|
self: "cqwu.Client",
|
||||||
|
):
|
||||||
|
url = f"https://pay.cqwu.edu.cn/api/pay/web/dlyscas/casLogin/{self.username}/2"
|
||||||
|
html = await self.request.get(url, follow_redirects=False)
|
||||||
|
if html.status_code == 302:
|
||||||
|
location = html.headers["location"]
|
||||||
|
params = {i.split("=")[0]: i.split("=")[1] for i in location.split("?")[1].split("&")}
|
||||||
|
self._pay_x_token = params["token"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pay_headers(self) -> Dict[str, str]:
|
||||||
|
return {
|
||||||
|
"X-Token": self._pay_x_token,
|
||||||
|
}
|
29
cqwu/methods/pay/get_pay_project_detail.py
Normal file
29
cqwu/methods/pay/get_pay_project_detail.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
import cqwu
|
||||||
|
from cqwu.errors.auth import CookieError
|
||||||
|
from cqwu.types import PayProjectDetail
|
||||||
|
|
||||||
|
|
||||||
|
class GetPayProjectDetail:
|
||||||
|
async def get_pay_project_detail(
|
||||||
|
self: "cqwu.Client",
|
||||||
|
project_id: str,
|
||||||
|
) -> List[Optional[PayProjectDetail]]:
|
||||||
|
"""
|
||||||
|
获取缴费项目详情
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Optional[PayProjectDetail]]: 缴费项目详情列表
|
||||||
|
"""
|
||||||
|
if not self._pay_x_token:
|
||||||
|
await self._oauth_pay()
|
||||||
|
url = (f"https://pay.cqwu.edu.cn/api/pay/web/tuitionAndDorm/getTuitionAndDormList/"
|
||||||
|
f"{self.username}/{project_id}")
|
||||||
|
html = await self.request.get(url, headers=self.pay_headers)
|
||||||
|
if html.status_code != 200:
|
||||||
|
raise CookieError()
|
||||||
|
data = html.json().get("data", [])
|
||||||
|
if not data:
|
||||||
|
return []
|
||||||
|
return [PayProjectDetail(**i) for i in data]
|
27
cqwu/methods/pay/get_pay_projects.py
Normal file
27
cqwu/methods/pay/get_pay_projects.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
import cqwu
|
||||||
|
from cqwu.errors.auth import CookieError
|
||||||
|
from cqwu.types import PayProject
|
||||||
|
|
||||||
|
|
||||||
|
class GetPayProjects:
|
||||||
|
async def get_pay_projects(
|
||||||
|
self: "cqwu.Client",
|
||||||
|
) -> List[Optional[PayProject]]:
|
||||||
|
"""
|
||||||
|
获取缴费项目
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Optional[PayProject]]: 缴费项目列表
|
||||||
|
"""
|
||||||
|
if not self._pay_x_token:
|
||||||
|
await self._oauth_pay()
|
||||||
|
url = "https://pay.cqwu.edu.cn/api/pay/project/getAllProjectList"
|
||||||
|
html = await self.request.get(url, headers=self.pay_headers)
|
||||||
|
if html.status_code != 200:
|
||||||
|
raise CookieError()
|
||||||
|
data = html.json().get("data", [])
|
||||||
|
if not data:
|
||||||
|
return []
|
||||||
|
return [PayProject(**i) for i in data]
|
27
cqwu/methods/pay/get_pay_user.py
Normal file
27
cqwu/methods/pay/get_pay_user.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
import cqwu
|
||||||
|
from cqwu.errors.auth import CookieError
|
||||||
|
from cqwu.types import PayUser
|
||||||
|
|
||||||
|
|
||||||
|
class GetPayUser:
|
||||||
|
async def get_pay_user(
|
||||||
|
self: "cqwu.Client",
|
||||||
|
) -> Optional[PayUser]:
|
||||||
|
"""
|
||||||
|
获取缴费用户信息
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Optional[PayUser]]: 缴费用户信息列表
|
||||||
|
"""
|
||||||
|
if not self._pay_x_token:
|
||||||
|
await self._oauth_pay()
|
||||||
|
url = f"https://pay.cqwu.edu.cn/api/pay/queryUserInfo/{self._pay_x_token}"
|
||||||
|
html = await self.request.get(url, headers=self.pay_headers)
|
||||||
|
if html.status_code != 200:
|
||||||
|
raise CookieError()
|
||||||
|
data = html.json().get("data")
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
return PayUser(**data)
|
@ -2,5 +2,6 @@ from .calendar import AiCourse
|
|||||||
from .cp import CP, PublicCPRaw, CPGS
|
from .cp import CP, PublicCPRaw, CPGS
|
||||||
from .epay import PayBill, PayBillPage
|
from .epay import PayBill, PayBillPage
|
||||||
from .exam import AiExam
|
from .exam import AiExam
|
||||||
|
from .pay import PayProject, PayProjectDetail, PayUser
|
||||||
from .score import Score
|
from .score import Score
|
||||||
from .user import User
|
from .user import User
|
||||||
|
58
cqwu/types/pay.py
Normal file
58
cqwu/types/pay.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
|
|
||||||
|
class PayProject(BaseModel):
|
||||||
|
id: str
|
||||||
|
createDate: datetime
|
||||||
|
createBy: str
|
||||||
|
updateDate: datetime
|
||||||
|
updateBy: str
|
||||||
|
projectType: str
|
||||||
|
projectCode: str
|
||||||
|
projectName: str
|
||||||
|
""" 项目名称 """
|
||||||
|
imgUrl: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
|
class PayProjectDetail(BaseModel):
|
||||||
|
id: Optional[str]
|
||||||
|
xh: Optional[int]
|
||||||
|
""" 学号 """
|
||||||
|
executespanname: Optional[str]
|
||||||
|
financingname: Optional[str]
|
||||||
|
""" 名称 """
|
||||||
|
taxname: Optional[str]
|
||||||
|
""" 税务名称 """
|
||||||
|
ysje: Optional[float]
|
||||||
|
""" 应收金额 """
|
||||||
|
sfje: Optional[float]
|
||||||
|
""" 已收金额 """
|
||||||
|
qfje: Optional[float]
|
||||||
|
""" 欠费金额 """
|
||||||
|
jmje: Optional[float]
|
||||||
|
""" 减免金额 """
|
||||||
|
tfje: Optional[float]
|
||||||
|
""" 退费金额 """
|
||||||
|
|
||||||
|
@validator("ysje", "sfje", "qfje", "jmje", "tfje", pre=True)
|
||||||
|
def _float(cls, v):
|
||||||
|
if v == "":
|
||||||
|
return 0.0
|
||||||
|
return float(v) / 100.0
|
||||||
|
|
||||||
|
|
||||||
|
class PayUser(BaseModel):
|
||||||
|
id: str
|
||||||
|
createDate: datetime
|
||||||
|
createBy: str
|
||||||
|
updateDate: datetime
|
||||||
|
updateBy: str
|
||||||
|
idserial: Optional[int]
|
||||||
|
name: Optional[str]
|
||||||
|
idNum: Optional[int]
|
||||||
|
""" 身份证号 """
|
||||||
|
phone: Optional[int]
|
||||||
|
""" 手机号 """
|
@ -1,5 +1,5 @@
|
|||||||
httpx==0.24.1
|
httpx==0.24.1
|
||||||
lxml==4.9.2
|
lxml==4.9.3
|
||||||
PyExecJS2==1.6.1
|
PyExecJS2==1.6.1
|
||||||
beautifulsoup4==4.12.2
|
beautifulsoup4==4.12.2
|
||||||
qrcode==7.4.2
|
qrcode==7.4.2
|
||||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="cqwu", # 用自己的名替换其中的YOUR_USERNAME_
|
name="cqwu", # 用自己的名替换其中的YOUR_USERNAME_
|
||||||
version="0.0.13", # 包版本号,便于维护版本
|
version="0.0.14", # 包版本号,便于维护版本
|
||||||
author="omg-xtao", # 作者,可以写自己的姓名
|
author="omg-xtao", # 作者,可以写自己的姓名
|
||||||
author_email="xtao@xtaolink.cn", # 作者联系方式,可写自己的邮箱地址
|
author_email="xtao@xtaolink.cn", # 作者联系方式,可写自己的邮箱地址
|
||||||
description="A cqwu ehall client.", # 包的简述
|
description="A cqwu ehall client.", # 包的简述
|
||||||
|
Loading…
Reference in New Issue
Block a user