aiqtech commited on
Commit
9e93a27
ยท
verified ยท
1 Parent(s): 667e67f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -168
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
- class MyHTMLParser(HTMLParser):
8
- def __init__(self):
9
- super().__init__()
10
- self.data = {}
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
- "pay_type": pay_type,
47
- "method": method,
48
- "cert_type": cert_type,
49
- "order_no": order_no,
 
 
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
- "tot_amt": tot_amt
59
- }
60
-
61
- headers = {
62
- 'Accept': 'application/json',
63
- 'Content-Type': 'application/x-www-form-urlencoded',
64
  }
65
 
66
- try:
67
- response = requests.post(url, data=payload, headers=headers)
68
- response.raise_for_status()
69
-
70
- # Check if the response is JSON
71
  try:
72
  return response.json()
73
- except requests.exceptions.JSONDecodeError:
74
- # If not JSON, assume it's HTML and extract information
75
- extracted_info = extract_info_from_html(response.text)
76
- return {
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
- def request_payment(onfftid, fix_key, tot_amt, card_user_type, auth_value, install_period, user_nm,
89
- user_phone2, product_nm, pay_type, method, order_no):
90
- url = "https://store.onoffkorea.co.kr/fix/index.php"
91
- payload = {
92
- "onfftid": onfftid,
93
- "fix_key": fix_key,
94
- "tot_amt": tot_amt,
95
- "card_user_type": card_user_type,
96
- "auth_value": auth_value,
97
- "install_period": install_period,
98
- "user_nm": user_nm,
99
- "user_phone2": user_phone2,
100
- "product_nm": product_nm,
101
- "pay_type": pay_type,
102
- "method": method,
103
- "order_no": order_no
104
- }
105
-
106
- headers = {
107
- 'Accept': 'application/json',
108
- 'Content-Type': 'application/x-www-form-urlencoded',
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
- with gr.Blocks() as demo:
134
- gr.Markdown("# API ์—ฐ๋™ ํ…Œ์ŠคํŠธ")
135
-
136
- with gr.Tab("์นด๋“œ ๋ฐฐ์น˜ํ‚ค ๋ฐœ๊ธ‰ ์š”์ฒญ"):
137
- onfftid = gr.Textbox(label="์˜จ์˜คํ”„์ฝ”๋ฆฌ์•„ TID")
138
- pay_type = gr.Textbox(label="๊ฒฐ์ œ ํƒ€์ž…", value="fixKey")
139
- method = gr.Textbox(label="๋ฉ”์†Œ๋“œ", value="request")
140
- cert_type = gr.Radio(["0", "1"], label="์ธ์ฆ ์—ฌ๋ถ€", value="0")
141
- order_no = gr.Textbox(label="์ฃผ๋ฌธ๋ฒˆํ˜ธ")
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
- demo.launch()
 
 
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()