File size: 6,878 Bytes
d9a9bca
ac8e3c3
 
d9a9bca
 
 
 
 
 
 
 
 
 
 
 
2121d78
 
d9a9bca
 
2121d78
 
d9a9bca
 
2121d78
 
ac8e3c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2121d78
d9a9bca
 
ac8e3c3
 
f905452
2121d78
 
f905452
2121d78
f905452
 
 
2121d78
 
f905452
2121d78
 
 
f905452
 
 
 
 
 
 
ac8e3c3
d9a9bca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2121d78
ac8e3c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9a9bca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac8e3c3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from bs4 import BeautifulSoup
import gradio as gr
import requests
from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
    def __init__(self):
        super().__init__()
        self.data = {}

    def handle_starttag(self, tag, attrs):
        if tag == 'input':
            d = dict(attrs)
            if 'name' in d and 'value' in d:
                self.data[d['name']] = d['value']

def extract_info_from_html(html_content):
    parser = MyHTMLParser()
    parser.feed(html_content)
    
    return {
        "order_number": parser.data.get('ordr_idxx', 'Not found'),
        "buyer_name": parser.data.get('buyr_name', 'Not found'),
        # Add more extracted fields as needed
    }

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()
        
        # Check if the response is JSON
        try:
            return response.json()
        except requests.exceptions.JSONDecodeError:
            # If not JSON, assume it's HTML and extract information
            extracted_info = extract_info_from_html(response.text)
            return {
                "status": "HTML response received",
                "extracted_info": extracted_info,
                "raw_html": response.text[:1000]  # First 1000 characters of HTML for reference
            }
    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)
        }

def request_payment(onfftid, fix_key, tot_amt, card_user_type, auth_value, install_period, user_nm, 
                    user_phone2, product_nm, pay_type, method, order_no):
    url = "https://store.onoffkorea.co.kr/fix/index.php"
    payload = {
        "onfftid": onfftid,
        "fix_key": fix_key,
        "tot_amt": tot_amt,
        "card_user_type": card_user_type,
        "auth_value": auth_value,
        "install_period": install_period,
        "user_nm": user_nm,
        "user_phone2": user_phone2,
        "product_nm": product_nm,
        "pay_type": pay_type,
        "method": method,
        "order_no": order_no
    }
    
    headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded',
    }
    
    try:
        response = requests.post(url, data=payload, headers=headers)
        response.raise_for_status()
        
        # Check if the response is JSON
        try:
            return response.json()
        except requests.exceptions.JSONDecodeError:
            # If not JSON, assume it's HTML and extract information
            extracted_info = extract_info_from_html(response.text)
            return {
                "status": "HTML response received",
                "extracted_info": extracted_info,
                "raw_html": response.text[:1000]  # First 1000 characters of HTML for reference
            }
    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
        )
    
    with gr.Tab("์นด๋“œ ๋ฐฐ์น˜ํ‚ค ๊ฒฐ์ œ ์Šน์ธ ์š”์ฒญ"):
        onfftid_pay = gr.Textbox(label="์˜จ์˜คํ”„์ฝ”๋ฆฌ์•„ TID")
        fix_key = gr.Textbox(label="์นด๋“œ ๋ฐฐ์น˜ ํ‚ค")
        tot_amt_pay = gr.Number(label="๊ฒฐ์ œ๊ธˆ์•ก")
        card_user_type_pay = gr.Radio(["0", "1"], label="์นด๋“œ ํƒ€์ž…", value="0")
        auth_value_pay = gr.Textbox(label="์ฃผ๋ฏผ(์‚ฌ์—…์ž)๋“ฑ๋ก๋ฒˆํ˜ธ")
        install_period = gr.Dropdown(["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"], label="ํ• ๋ถ€๊ธฐ๊ฐ„")
        user_nm_pay = gr.Textbox(label="๊ณ ๊ฐ๋ช…")
        user_phone2_pay = gr.Textbox(label="๊ณ ๊ฐ์—ฐ๋ฝ์ฒ˜")
        product_nm_pay = gr.Textbox(label="์ƒํ’ˆ๋ช…")
        pay_type_pay = gr.Textbox(label="๊ฒฐ์ œ ํƒ€์ž…", value="fixKey")
        method_pay = gr.Textbox(label="๋ฉ”์†Œ๋“œ", value="authTran")
        order_no_pay = gr.Textbox(label="์ฃผ๋ฌธ๋ฒˆํ˜ธ")
        
        payment_button = gr.Button("๊ฒฐ์ œ ์Šน์ธ ์š”์ฒญ")
        payment_output = gr.JSON(label="์‘๋‹ต ๊ฒฐ๊ณผ")
        
        payment_button.click(
            request_payment,
            inputs=[onfftid_pay, fix_key, tot_amt_pay, card_user_type_pay, auth_value_pay, install_period, 
                    user_nm_pay, user_phone2_pay, product_nm_pay, pay_type_pay, method_pay, order_no_pay],
            outputs=payment_output
        )

demo.launch()