Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm,
|
| 5 |
card_user_type, card_no, expire_date, auth_value, password, tot_amt):
|
|
@@ -21,56 +35,25 @@ def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, u
|
|
| 21 |
"tot_amt": tot_amt
|
| 22 |
}
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
# Try to parse JSON, if fails, return the raw text
|
| 29 |
-
try:
|
| 30 |
-
return response.json()
|
| 31 |
-
except requests.exceptions.JSONDecodeError:
|
| 32 |
-
return {
|
| 33 |
-
"error": "Invalid JSON response",
|
| 34 |
-
"status_code": response.status_code,
|
| 35 |
-
"raw_response": response.text
|
| 36 |
-
}
|
| 37 |
-
except requests.exceptions.RequestException as e:
|
| 38 |
-
return {
|
| 39 |
-
"error": str(e),
|
| 40 |
-
"status_code": getattr(e.response, 'status_code', None),
|
| 41 |
-
"raw_response": getattr(e.response, 'text', None)
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
def request_payment(onfftid, fix_key, tot_amt, card_user_type, auth_value, install_period, user_nm,
|
| 45 |
-
user_phone2, product_nm, pay_type, method, order_no):
|
| 46 |
-
url = "https://store.onoffkorea.co.kr/fix/index.php"
|
| 47 |
-
payload = {
|
| 48 |
-
"onfftid": onfftid,
|
| 49 |
-
"fix_key": fix_key,
|
| 50 |
-
"tot_amt": tot_amt,
|
| 51 |
-
"card_user_type": card_user_type,
|
| 52 |
-
"auth_value": auth_value,
|
| 53 |
-
"install_period": install_period,
|
| 54 |
-
"user_nm": user_nm,
|
| 55 |
-
"user_phone2": user_phone2,
|
| 56 |
-
"product_nm": product_nm,
|
| 57 |
-
"pay_type": pay_type,
|
| 58 |
-
"method": method,
|
| 59 |
-
"order_no": order_no
|
| 60 |
}
|
| 61 |
|
| 62 |
try:
|
| 63 |
-
response = requests.post(url, data=payload)
|
| 64 |
-
response.raise_for_status()
|
| 65 |
|
| 66 |
-
#
|
| 67 |
try:
|
| 68 |
return response.json()
|
| 69 |
except requests.exceptions.JSONDecodeError:
|
|
|
|
|
|
|
| 70 |
return {
|
| 71 |
-
"
|
| 72 |
-
"
|
| 73 |
-
"
|
| 74 |
}
|
| 75 |
except requests.exceptions.RequestException as e:
|
| 76 |
return {
|
|
@@ -79,6 +62,8 @@ def request_payment(onfftid, fix_key, tot_amt, card_user_type, auth_value, insta
|
|
| 79 |
"raw_response": getattr(e.response, 'text', None)
|
| 80 |
}
|
| 81 |
|
|
|
|
|
|
|
| 82 |
with gr.Blocks() as demo:
|
| 83 |
gr.Markdown("# API ์ฐ๋ ํ
์คํธ")
|
| 84 |
|
|
@@ -108,28 +93,6 @@ with gr.Blocks() as demo:
|
|
| 108 |
outputs=batch_key_output
|
| 109 |
)
|
| 110 |
|
| 111 |
-
|
| 112 |
-
onfftid_pay = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID")
|
| 113 |
-
fix_key = gr.Textbox(label="์นด๋ ๋ฐฐ์น ํค")
|
| 114 |
-
tot_amt_pay = gr.Number(label="๊ฒฐ์ ๊ธ์ก")
|
| 115 |
-
card_user_type_pay = gr.Radio(["0", "1"], label="์นด๋ ํ์
", value="0")
|
| 116 |
-
auth_value_pay = gr.Textbox(label="์ฃผ๋ฏผ(์ฌ์
์)๋ฑ๋ก๋ฒํธ")
|
| 117 |
-
install_period = gr.Dropdown(["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"], label="ํ ๋ถ๊ธฐ๊ฐ")
|
| 118 |
-
user_nm_pay = gr.Textbox(label="๊ณ ๊ฐ๋ช
")
|
| 119 |
-
user_phone2_pay = gr.Textbox(label="๊ณ ๊ฐ์ฐ๋ฝ์ฒ")
|
| 120 |
-
product_nm_pay = gr.Textbox(label="์ํ๋ช
")
|
| 121 |
-
pay_type_pay = gr.Textbox(label="๊ฒฐ์ ํ์
", value="fixKey")
|
| 122 |
-
method_pay = gr.Textbox(label="๋ฉ์๋", value="authTran")
|
| 123 |
-
order_no_pay = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ")
|
| 124 |
-
|
| 125 |
-
payment_button = gr.Button("๊ฒฐ์ ์น์ธ ์์ฒญ")
|
| 126 |
-
payment_output = gr.JSON(label="์๋ต ๊ฒฐ๊ณผ")
|
| 127 |
-
|
| 128 |
-
payment_button.click(
|
| 129 |
-
request_payment,
|
| 130 |
-
inputs=[onfftid_pay, fix_key, tot_amt_pay, card_user_type_pay, auth_value_pay, install_period,
|
| 131 |
-
user_nm_pay, user_phone2_pay, product_nm_pay, pay_type_pay, method_pay, order_no_pay],
|
| 132 |
-
outputs=payment_output
|
| 133 |
-
)
|
| 134 |
|
| 135 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
|
| 5 |
+
def extract_info_from_html(html_content):
|
| 6 |
+
soup = BeautifulSoup(html_content, 'html.parser')
|
| 7 |
+
|
| 8 |
+
# Example: Extract order number and buyer name
|
| 9 |
+
order_number = soup.find('input', {'name': 'ordr_idxx'})['value'] if soup.find('input', {'name': 'ordr_idxx'}) else 'Not found'
|
| 10 |
+
buyer_name = soup.find('input', {'name': 'buyr_name'})['value'] if soup.find('input', {'name': 'buyr_name'}) else 'Not found'
|
| 11 |
+
|
| 12 |
+
return {
|
| 13 |
+
"order_number": order_number,
|
| 14 |
+
"buyer_name": buyer_name,
|
| 15 |
+
# Add more extracted fields as needed
|
| 16 |
+
}
|
| 17 |
|
| 18 |
def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm,
|
| 19 |
card_user_type, card_no, expire_date, auth_value, password, tot_amt):
|
|
|
|
| 35 |
"tot_amt": tot_amt
|
| 36 |
}
|
| 37 |
|
| 38 |
+
headers = {
|
| 39 |
+
'Accept': 'application/json', # ์์ฒญ์ด JSON์ ์ ํธํ๋ค๊ณ ์๋ฒ์ ์๋ฆฝ๋๋ค
|
| 40 |
+
'Content-Type': 'application/x-www-form-urlencoded', # ํผ ๋ฐ์ดํฐ๋ก ์ ์ก
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
try:
|
| 44 |
+
response = requests.post(url, data=payload, headers=headers)
|
| 45 |
+
response.raise_for_status()
|
| 46 |
|
| 47 |
+
# Check if the response is JSON
|
| 48 |
try:
|
| 49 |
return response.json()
|
| 50 |
except requests.exceptions.JSONDecodeError:
|
| 51 |
+
# If not JSON, assume it's HTML and extract information
|
| 52 |
+
extracted_info = extract_info_from_html(response.text)
|
| 53 |
return {
|
| 54 |
+
"status": "HTML response received",
|
| 55 |
+
"extracted_info": extracted_info,
|
| 56 |
+
"raw_html": response.text[:1000] # First 1000 characters of HTML for reference
|
| 57 |
}
|
| 58 |
except requests.exceptions.RequestException as e:
|
| 59 |
return {
|
|
|
|
| 62 |
"raw_response": getattr(e.response, 'text', None)
|
| 63 |
}
|
| 64 |
|
| 65 |
+
# The request_payment function can be updated similarly
|
| 66 |
+
|
| 67 |
with gr.Blocks() as demo:
|
| 68 |
gr.Markdown("# API ์ฐ๋ ํ
์คํธ")
|
| 69 |
|
|
|
|
| 93 |
outputs=batch_key_output
|
| 94 |
)
|
| 95 |
|
| 96 |
+
# The "์นด๋ ๋ฐฐ์นํค ๊ฒฐ์ ์น์ธ ์์ฒญ" tab can be updated similarly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
demo.launch()
|