Update app.py
Browse files
app.py
CHANGED
|
@@ -1,186 +1,72 @@
|
|
| 1 |
-
from bs4 import BeautifulSoup
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
-
from html.parser import HTMLParser
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
self.current_tag = None
|
| 12 |
-
|
| 13 |
-
def handle_starttag(self, tag, attrs):
|
| 14 |
-
self.current_tag = tag
|
| 15 |
-
if tag == 'input':
|
| 16 |
-
d = dict(attrs)
|
| 17 |
-
if 'name' in d and 'value' in d:
|
| 18 |
-
self.data[d['name']] = d['value']
|
| 19 |
-
|
| 20 |
-
def handle_data(self, data):
|
| 21 |
-
if self.current_tag == 'script':
|
| 22 |
-
if 'fix_key' in data:
|
| 23 |
-
for line in data.split('\n'):
|
| 24 |
-
if 'fix_key' in line:
|
| 25 |
-
key, value = line.split('=')
|
| 26 |
-
self.data['fix_key'] = value.strip().strip("';")
|
| 27 |
-
|
| 28 |
-
def extract_info_from_html(html_content):
|
| 29 |
-
parser = MyHTMLParser()
|
| 30 |
-
parser.feed(html_content)
|
| 31 |
-
|
| 32 |
-
return {
|
| 33 |
-
"order_number": parser.data.get('ordr_idxx', 'Not found'),
|
| 34 |
-
"buyer_name": parser.data.get('buyr_name', 'Not found'),
|
| 35 |
-
"fix_key": parser.data.get('fix_key', 'Not found'),
|
| 36 |
-
# Add more extracted fields as needed
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm,
|
| 42 |
-
card_user_type, card_no, expire_date, auth_value, password, tot_amt):
|
| 43 |
-
url = "https://store.onoffkorea.co.kr/fix/index.php"
|
| 44 |
-
payload = {
|
| 45 |
"onfftid": onfftid,
|
| 46 |
-
"
|
| 47 |
-
"
|
| 48 |
-
"
|
| 49 |
-
"
|
|
|
|
|
|
|
| 50 |
"user_nm": user_nm,
|
| 51 |
"user_phone2": user_phone2,
|
| 52 |
"product_nm": product_nm,
|
| 53 |
-
"card_user_type": card_user_type,
|
| 54 |
-
"card_no": card_no,
|
| 55 |
"expire_date": expire_date,
|
|
|
|
|
|
|
| 56 |
"auth_value": auth_value,
|
| 57 |
"password": password,
|
| 58 |
-
"
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
headers = {
|
| 62 |
-
'Accept': 'application/json',
|
| 63 |
-
'Content-Type': 'application/x-www-form-urlencoded',
|
| 64 |
}
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
response.raise_for_status()
|
| 69 |
-
|
| 70 |
-
# Check if the response is JSON
|
| 71 |
try:
|
| 72 |
return response.json()
|
| 73 |
-
except
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
"status": "HTML response received",
|
| 78 |
-
"extracted_info": extracted_info,
|
| 79 |
-
"raw_html": response.text[:1000] # First 1000 characters of HTML for reference
|
| 80 |
-
}
|
| 81 |
-
except requests.exceptions.RequestException as e:
|
| 82 |
-
return {
|
| 83 |
-
"error": str(e),
|
| 84 |
-
"status_code": getattr(e.response, 'status_code', None),
|
| 85 |
-
"raw_response": getattr(e.response, 'text', None)
|
| 86 |
-
}
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
try:
|
| 112 |
-
response = requests.post(url, data=payload, headers=headers)
|
| 113 |
-
response.raise_for_status()
|
| 114 |
-
|
| 115 |
-
# Check if the response is JSON
|
| 116 |
-
try:
|
| 117 |
-
return response.json()
|
| 118 |
-
except requests.exceptions.JSONDecodeError:
|
| 119 |
-
# If not JSON, assume it's HTML and extract information
|
| 120 |
-
extracted_info = extract_info_from_html(response.text)
|
| 121 |
-
return {
|
| 122 |
-
"status": "HTML response received",
|
| 123 |
-
"extracted_info": extracted_info,
|
| 124 |
-
"raw_html": response.text[:1000] # First 1000 characters of HTML for reference
|
| 125 |
-
}
|
| 126 |
-
except requests.exceptions.RequestException as e:
|
| 127 |
-
return {
|
| 128 |
-
"error": str(e),
|
| 129 |
-
"status_code": getattr(e.response, 'status_code', None),
|
| 130 |
-
"raw_response": getattr(e.response, 'text', None)
|
| 131 |
-
}
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
user_nm = gr.Textbox(label="์ฃผ๋ฌธ์ ์ด๋ฆ")
|
| 143 |
-
user_phone2 = gr.Textbox(label="์ฃผ๋ฌธ์ ์ฐ๋ฝ์ฒ")
|
| 144 |
-
product_nm = gr.Textbox(label="์ํ๋ช
")
|
| 145 |
-
card_user_type = gr.Radio(["0", "1"], label="์นด๋ ํ์
", value="0")
|
| 146 |
-
card_no = gr.Textbox(label="์นด๋๋ฒํธ")
|
| 147 |
-
expire_date = gr.Textbox(label="์ ํจ๊ธฐ๊ฐ(YYMM)")
|
| 148 |
-
auth_value = gr.Textbox(label="์ฃผ๋ฏผ(์ฌ์
์)๋ฑ๋ก๋ฒํธ")
|
| 149 |
-
password = gr.Textbox(label="์นด๋๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ")
|
| 150 |
-
tot_amt = gr.Number(label="๊ฒฐ์ ๊ธ์ก")
|
| 151 |
-
|
| 152 |
-
batch_key_button = gr.Button("๋ฐฐ์นํค ๋ฐ๊ธ ์์ฒญ")
|
| 153 |
-
batch_key_output = gr.JSON(label="์๋ต ๊ฒฐ๊ณผ")
|
| 154 |
-
|
| 155 |
-
batch_key_button.click(
|
| 156 |
-
request_batch_key,
|
| 157 |
-
inputs=[onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm,
|
| 158 |
-
card_user_type, card_no, expire_date, auth_value, password, tot_amt],
|
| 159 |
-
outputs=batch_key_output
|
| 160 |
-
)
|
| 161 |
-
|
| 162 |
-
with gr.Tab("์นด๋ ๋ฐฐ์นํค ๊ฒฐ์ ์น์ธ ์์ฒญ"):
|
| 163 |
-
onfftid_pay = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID")
|
| 164 |
-
fix_key = gr.Textbox(label="์นด๋ ๋ฐฐ์น ํค")
|
| 165 |
-
tot_amt_pay = gr.Number(label="๊ฒฐ์ ๊ธ์ก")
|
| 166 |
-
card_user_type_pay = gr.Radio(["0", "1"], label="์นด๋ ํ์
", value="0")
|
| 167 |
-
auth_value_pay = gr.Textbox(label="์ฃผ๋ฏผ(์ฌ์
์)๋ฑ๋ก๋ฒํธ")
|
| 168 |
-
install_period = gr.Dropdown(["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"], label="ํ ๋ถ๊ธฐ๊ฐ")
|
| 169 |
-
user_nm_pay = gr.Textbox(label="๊ณ ๊ฐ๋ช
")
|
| 170 |
-
user_phone2_pay = gr.Textbox(label="๊ณ ๊ฐ์ฐ๋ฝ์ฒ")
|
| 171 |
-
product_nm_pay = gr.Textbox(label="์ํ๋ช
")
|
| 172 |
-
pay_type_pay = gr.Textbox(label="๊ฒฐ์ ํ์
", value="fixKey")
|
| 173 |
-
method_pay = gr.Textbox(label="๋ฉ์๋", value="authTran")
|
| 174 |
-
order_no_pay = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ")
|
| 175 |
-
|
| 176 |
-
payment_button = gr.Button("๊ฒฐ์ ์น์ธ ์์ฒญ")
|
| 177 |
-
payment_output = gr.JSON(label="์๋ต ๊ฒฐ๊ณผ")
|
| 178 |
-
|
| 179 |
-
payment_button.click(
|
| 180 |
-
request_payment,
|
| 181 |
-
inputs=[onfftid_pay, fix_key, tot_amt_pay, card_user_type_pay, auth_value_pay, install_period,
|
| 182 |
-
user_nm_pay, user_phone2_pay, product_nm_pay, pay_type_pay, method_pay, order_no_pay],
|
| 183 |
-
outputs=payment_output
|
| 184 |
)
|
| 185 |
|
| 186 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
+
def card_authorization(onfftid, tot_amt, com_tax_amt, com_free_amt, com_vat_amt, card_no, install_period,
|
| 5 |
+
user_nm, user_phone2, product_nm, expire_date, cert_type, card_user_type,
|
| 6 |
+
auth_value, password, card_nm, order_no, pay_type):
|
| 7 |
+
url = "https://store.onoffkorea.co.kr/payment/index.php"
|
| 8 |
+
data = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"onfftid": onfftid,
|
| 10 |
+
"tot_amt": tot_amt,
|
| 11 |
+
"com_tax_amt": com_tax_amt,
|
| 12 |
+
"com_free_amt": com_free_amt,
|
| 13 |
+
"com_vat_amt": com_vat_amt,
|
| 14 |
+
"card_no": card_no,
|
| 15 |
+
"install_period": install_period,
|
| 16 |
"user_nm": user_nm,
|
| 17 |
"user_phone2": user_phone2,
|
| 18 |
"product_nm": product_nm,
|
|
|
|
|
|
|
| 19 |
"expire_date": expire_date,
|
| 20 |
+
"cert_type": cert_type,
|
| 21 |
+
"card_user_type": card_user_type,
|
| 22 |
"auth_value": auth_value,
|
| 23 |
"password": password,
|
| 24 |
+
"card_nm": card_nm,
|
| 25 |
+
"order_no": order_no,
|
| 26 |
+
"pay_type": pay_type
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
+
response = requests.post(url, data=data)
|
| 30 |
+
if response.status_code == 200:
|
|
|
|
|
|
|
|
|
|
| 31 |
try:
|
| 32 |
return response.json()
|
| 33 |
+
except ValueError:
|
| 34 |
+
return {"error": "Non-JSON response", "details": response.text}
|
| 35 |
+
else:
|
| 36 |
+
return {"error": "Request failed", "status_code": response.status_code}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
with gr.Blocks() as app:
|
| 39 |
+
with gr.Tab("์นด๋ ๊ฒฐ์ ์น์ธ ์์ฒญ"):
|
| 40 |
+
with gr.Row():
|
| 41 |
+
with gr.Column(scale=1):
|
| 42 |
+
onfftid = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID", value="OFPT000000011017", readonly=True)
|
| 43 |
+
tot_amt = gr.Number(label="๊ฒฐ์ ๊ธ์ก", placeholder="๊ธ์ก์ ์
๋ ฅํ์ธ์")
|
| 44 |
+
com_tax_amt = gr.Number(label="๊ณผ์ธ์น์ธ๊ธ์ก", optional=True)
|
| 45 |
+
com_free_amt = gr.Number(label="๋น๊ณผ์ธ์น์ธ๊ธ์ก", optional=True)
|
| 46 |
+
com_vat_amt = gr.Number(label="๋ถ๊ฐ์ธ", optional=True)
|
| 47 |
+
card_no = gr.Textbox(label="์นด๋๋ฒํธ", placeholder="์นด๋๋ฒํธ๋ฅผ ์
๋ ฅํ์ธ์")
|
| 48 |
+
install_period = gr.Dropdown([str(i).zfill(2) for i in range(13)], label="ํ ๋ถ๊ธฐ๊ฐ ์ ํ")
|
| 49 |
+
user_nm = gr.Textbox(label="๊ฒฐ์ ์๋ช
", placeholder="๊ฒฐ์ ์์ ์ด๋ฆ์ ์
๋ ฅํ์ธ์")
|
| 50 |
+
user_phone2 = gr.Textbox(label="๊ฒฐ์ ์ ์ฐ๋ฝ์ฒ", placeholder="์ฐ๋ฝ์ฒ๋ฅผ ์
๋ ฅํ์ธ์")
|
| 51 |
+
product_nm = gr.Textbox(label="์ํ๋ช
", placeholder="์ํ๋ช
์ ์
๋ ฅํ์ธ์")
|
| 52 |
+
expire_date = gr.Textbox(label="์ ํจ๊ธฐ๊ฐ(YYMM)", placeholder="์: 2306")
|
| 53 |
+
cert_type = gr.Radio(choices=["0 - ์ธ์ฆ", "1 - ๋น์ธ์ฆ"], label="์ธ์ฆ์ฌ๋ถ ์ ํ")
|
| 54 |
+
card_user_type = gr.Radio(choices=["0 - ๊ฐ์ธ์นด๋", "1 - ๋ฒ์ธ์นด๋"], label="์นด๋์ ํ ์ ํ")
|
| 55 |
+
auth_value = gr.Textbox(label="์ธ์ฆ๋ฒํธ", placeholder="๊ฐ์ธ์ ์ฃผ๋ฏผ๋ฒํธ ์ 6์๋ฆฌ, ๋ฒ์ธ์ ์ฌ์
์๋ฑ๋ก๋ฒํธ")
|
| 56 |
+
password = gr.Textbox(label="์นด๋ ๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ", placeholder="๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ")
|
| 57 |
+
card_nm = gr.Textbox(label="์นด๋์ฌ๋ช
", optional=True, placeholder="์นด๋์ฌ๋ช
์ ์
๋ ฅํ์ธ์")
|
| 58 |
+
order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ", optional=True, placeholder="์ฃผ๋ฌธ๋ฒํธ๋ฅผ ์
๋ ฅํ์ธ์")
|
| 59 |
+
pay_type = gr.Textbox(label="๊ฒฐ์ ํ์
", value="card", readonly=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
submit_button = gr.Button("๊ฒฐ์ ์น์ธ ์์ฒญ")
|
| 62 |
+
result_area = gr.JSON(label="๊ฒฐ๊ณผ")
|
| 63 |
+
|
| 64 |
+
submit_button.click(
|
| 65 |
+
fn=card_authorization,
|
| 66 |
+
inputs=[onfftid, tot_amt, com_tax_amt, com_free_amt, com_vat_amt, card_no, install_period,
|
| 67 |
+
user_nm, user_phone2, product_nm, expire_date, cert_type, card_user_type,
|
| 68 |
+
auth_value, password, card_nm, order_no, pay_type],
|
| 69 |
+
outputs=result_area
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
+
app.launch()
|