|
import gradio as gr |
|
import requests |
|
from bs4 import BeautifulSoup |
|
|
|
def extract_info_from_html(html_content): |
|
soup = BeautifulSoup(html_content, 'html.parser') |
|
|
|
|
|
order_number = soup.find('input', {'name': 'ordr_idxx'})['value'] if soup.find('input', {'name': 'ordr_idxx'}) else 'Not found' |
|
buyer_name = soup.find('input', {'name': 'buyr_name'})['value'] if soup.find('input', {'name': 'buyr_name'}) else 'Not found' |
|
|
|
return { |
|
"order_number": order_number, |
|
"buyer_name": buyer_name, |
|
|
|
} |
|
|
|
def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm, |
|
card_user_type, card_no, expire_date, auth_value, password, tot_amt): |
|
url = "https://store.onoffkorea.co.kr/fix/index.php" |
|
payload = { |
|
"onfftid": onfftid, |
|
"pay_type": pay_type, |
|
"method": method, |
|
"cert_type": cert_type, |
|
"order_no": order_no, |
|
"user_nm": user_nm, |
|
"user_phone2": user_phone2, |
|
"product_nm": product_nm, |
|
"card_user_type": card_user_type, |
|
"card_no": card_no, |
|
"expire_date": expire_date, |
|
"auth_value": auth_value, |
|
"password": password, |
|
"tot_amt": tot_amt |
|
} |
|
|
|
headers = { |
|
'Accept': 'application/json', |
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
} |
|
|
|
try: |
|
response = requests.post(url, data=payload, headers=headers) |
|
response.raise_for_status() |
|
|
|
|
|
try: |
|
return response.json() |
|
except requests.exceptions.JSONDecodeError: |
|
|
|
extracted_info = extract_info_from_html(response.text) |
|
return { |
|
"status": "HTML response received", |
|
"extracted_info": extracted_info, |
|
"raw_html": response.text[:1000] |
|
} |
|
except requests.exceptions.RequestException as e: |
|
return { |
|
"error": str(e), |
|
"status_code": getattr(e.response, 'status_code', None), |
|
"raw_response": getattr(e.response, 'text', None) |
|
} |
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# API ์ฐ๋ ํ
์คํธ") |
|
|
|
with gr.Tab("์นด๋ ๋ฐฐ์นํค ๋ฐ๊ธ ์์ฒญ"): |
|
onfftid = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID") |
|
pay_type = gr.Textbox(label="๊ฒฐ์ ํ์
", value="fixKey") |
|
method = gr.Textbox(label="๋ฉ์๋", value="request") |
|
cert_type = gr.Radio(["0", "1"], label="์ธ์ฆ ์ฌ๋ถ", value="0") |
|
order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ") |
|
user_nm = gr.Textbox(label="์ฃผ๋ฌธ์ ์ด๋ฆ") |
|
user_phone2 = gr.Textbox(label="์ฃผ๋ฌธ์ ์ฐ๋ฝ์ฒ") |
|
product_nm = gr.Textbox(label="์ํ๋ช
") |
|
card_user_type = gr.Radio(["0", "1"], label="์นด๋ ํ์
", value="0") |
|
card_no = gr.Textbox(label="์นด๋๋ฒํธ") |
|
expire_date = gr.Textbox(label="์ ํจ๊ธฐ๊ฐ(YYMM)") |
|
auth_value = gr.Textbox(label="์ฃผ๋ฏผ(์ฌ์
์)๋ฑ๋ก๋ฒํธ") |
|
password = gr.Textbox(label="์นด๋๋น๋ฐ๋ฒํธ ์ 2์๋ฆฌ") |
|
tot_amt = gr.Number(label="๊ฒฐ์ ๊ธ์ก") |
|
|
|
batch_key_button = gr.Button("๋ฐฐ์นํค ๋ฐ๊ธ ์์ฒญ") |
|
batch_key_output = gr.JSON(label="์๋ต ๊ฒฐ๊ณผ") |
|
|
|
batch_key_button.click( |
|
request_batch_key, |
|
inputs=[onfftid, pay_type, method, cert_type, order_no, user_nm, user_phone2, product_nm, |
|
card_user_type, card_no, expire_date, auth_value, password, tot_amt], |
|
outputs=batch_key_output |
|
) |
|
|
|
|
|
|
|
demo.launch() |