You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import os
import requests
# 从环境变量中获取服务器库的 URL如果环境变量未设置则使用默认值 "http://127.0.0.1:5000"
hosts = os.getenv('SERVER_LIB_URL', "http://127.0.0.1:5000")
def checkIdCard(id_card):
"""
验证身份证号码是否有效。
该函数通过向服务器发送 POST 请求来验证身份证号码。
Args:
id_card (str): 要验证的身份证号码。
Returns:
bool: 如果验证成功返回 True否则返回 False。
"""
# 构造验证身份证号码的 URL
url = hosts + "/id_card/verify"
# 构造请求参数
params = {
'idCardNo': id_card
}
# 发送 POST 请求,将参数以 JSON 格式发送
response = requests.post(url, json=params)
# 检查响应状态码是否为 200 且响应数据中的 "result" 字段为 True
return response.status_code == 200 and response.json().get("data")["result"]
def checkBankCard(bank_card):
"""
验证银行卡号码是否有效。
该函数通过向服务器发送 POST 请求来验证银行卡号码。
Args:
bank_card (str): 要验证的银行卡号码。
Returns:
bool: 如果验证成功返回 True否则返回 False。
"""
# 构造验证银行卡号码的 URL
url = hosts + "/bank/card_verify"
# 构造请求参数
params = {
'bankCard': bank_card
}
# 发送 POST 请求,将参数以 JSON 格式发送
response = requests.post(url, json=params)
# 检查响应状态码是否为 200 且响应数据中的 "result" 字段为 True
return response.status_code == 200 and response.json().get("data")["result"]
def checkMobile(mobile_no):
"""
验证手机号码是否有效。
该函数通过向服务器发送 POST 请求来验证手机号码。
Args:
mobile_no (str): 要验证的手机号码。
Returns:
bool: 如果验证成功返回 True否则返回 False。
"""
# 构造验证手机号码的 URL
url = hosts + "/mobile/check"
# 构造请求参数
params = {
'mobileNo': mobile_no
}
# 发送 POST 请求,将参数以 JSON 格式发送
response = requests.post(url, json=params)
# 检查响应状态码是否为 200 且响应数据中的 "result" 字段为 True
return response.status_code == 200 and response.json().get("data")["result"]
def verifyOrderPayment(order_no):
"""
验证订单支付状态。
该函数模拟向支付中心发送验证请求,通过向服务器发送 POST 请求来验证订单支付状态。
Args:
order_no (str): 要验证的订单号。
Returns:
requests.Response: 服务器的响应对象。
"""
# 构造验证订单支付状态的 URL
url = hosts + "/bank/query"
# 构造请求参数
params = {"OrderNo": order_no}
# 发送 POST 请求,将参数以 JSON 格式发送
response = requests.post(url, json=params)
return response