/home/mjc1/public_html/adm/get_qna_esm.php


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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
include_once("./_common.php");
$mktime date("YmdHis",time());

include_once 
"simple_html_dom.php";

function 
gm_reply_parse($res){
    
$p1 explode("<li>",$res);
    
$cnt=0;
    foreach(
$p1 as $key => $val){
        if(
strpos($val,"iqntit")>0){
            
// 답변일 파싱
            
$date_pos strpos($val,'<p class="date">');
            
$str1 substr($val,$date_pos+16,strlen($val));
            
$date_pos2 strpos($str1,"</p>");
            
$date_str substr($str1,0,$date_pos2);
            
$date_str str_replace("[답변일 :","",$date_str);
            
$date_str substr($date_str,0,16);

            
// 제목 파싱
            
$subj_pos strpos($val,'<p class="tit iqntit"');
            
$str1 substr($val,$subj_pos+20,strlen($val));
            
$subj_pos2 strpos($str1,"</p>");
            
$subj_str substr($str1,0,$subj_pos2);
            
$subj_pos2 strpos($subj_str,">");
            
$subj_str substr($subj_str,$subj_pos2+1,strlen($subj_str));

            
// 내용 파싱
            
$cont_pos strpos($val,'<div class="txt">');
            
$str1 substr($val,$cont_pos+17,strlen($val));
            
$cont_pos2 strpos($str1,"</div>");
            
$cont_str substr($str1,0,$cont_pos2);

            
$reply_array[$cnt]['date'] = $date_str;
            
$reply_array[$cnt]['subj'] = $subj_str;
            
$reply_array[$cnt]['cont'] = $cont_str;
        
$cnt++;
        }
    }
    
//_pr($reply_array);
    
return $reply_array;
}

$table "otms_qna";
$update_cnt 0$insert_cnt 0

$id trim($default['de_otms_id_esm']);
$pw trim($default['de_otms_pw_esm']);

// 로그인 처리
$loginUrl "https://www.esmplus.com/Member/SignIn/Authenticate";
$login_data "Type=E&ReturnUrl=&Id={$id}&Password={$pw}&RememberMe=false"
$cookie_nm G5_DATA_PATH."/session/esm_cookie.txt"

$ch curl_init(); 
curl_setopt ($chCURLOPT_URL,$loginUrl); //접속할 URL 주소 
curl_setopt ($chCURLOPT_SSL_VERIFYPEERfalse); 
curl_setopt ($chCURLOPT_SSLVERSION,1); 
curl_setopt ($chCURLOPT_HEADER0); 
curl_setopt ($chCURLOPT_POST1); 
curl_setopt($chCURLOPT_COOKIEJAR$cookie_nm); 
curl_setopt($chCURLOPT_COOKIEFILE$cookie_nm); 
curl_setopt($chCURLOPT_POSTFIELDS$login_data); 
curl_setopt ($chCURLOPT_TIMEOUT30); 
curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
$result curl_exec ($ch); 

// 조회 기간설정 3개월
$sdate date("Y-m-d",time()-(60*60*24*90));
$edate date("Y-m-d",time());

// 옥션의 QNA 데이터 가져오기
$loginUrl "https://www.esmplus.com/Member/CustomerService/GetInquryList";
// 500개까지 가져옴

$login_data "page=1&limit=500&paramsData=%7B%22Site%22%3A%22A%22%2C%22Account%22%3A%22All%22%2C%22DateType%22%3A%22DA%22%2C%22StartDate%22%3A%22{$sdate}%22%2C%22EndDate%22%3A%22{$edate}%22%2C%22InquryType%22%3A%22AL%22%2C%22QueryType%22%3A%22AL%22%2C%22ReplyType%22%3A%22AL%22%2C%22KeywordType%22%3A%22KA%22%2C%22Keyword%22%3A%22%22%2C%22OrderType%22%3A%220%22%2C%22PageSize%22%3A20%2C%22CurrentPage%22%3A1%2C%22TotalCount%22%3A0%7D&SortFeild=InsDate&SortType=Desc";

curl_setopt ($chCURLOPT_URL,$loginUrl);
curl_setopt($chCURLOPT_POSTFIELDS$login_data); 
$result curl_exec ($ch); 

$res json_decode($result);
//_pr($res);

if($res->success!='1'){
    echo 
"<strong>ESM+ 상품정보를 가져오지 못했습니다. 로그인정보에 문제가 있을 가능성이 큽니다.</strong>";
} else {
    for(
$i=0;$i<$res->total;$i++){
        foreach(
$res->data[$i] as $key=>$val){
            if(
$key=='CategoryLName'){ // 캐릭터셋 필요시 사용
                //$res->data[$i]->$key = iconv("UTF-8","EUCKR",$val);
            
}
            if(
$key=='ItemNo'){
                
$res->data[$i]->$key trim(strip_tags($val));
            }
            if(
$key=='Content'){
                
$res->data[$i]->$key str_replace("/br","</br>",$val);    
            }
            if(
substr($val,0,5)=='/Date'){
                
$v substr($val,6,10);
                
$res->data[$i]->$key $v;
            }
        }
    }

    for(
$i=0;$i<$res->total;$i++){

        
$row $res->data[$i];

        if(
$row->SiteType=='IAC'){ 
            
$siteId 'au';
        } else if(
$row->SiteType=='GMKT'){
            
$siteId 'gm';
        } else {
            continue;
        }

        
$sql "select count(*) as cnt from $table where SiteId = '{$siteId}' and SeqNo = '{$row->SeqNo}' ";
        
$res2 sql_query($sql);
        
$info mysql_fetch_array($res2);
        
$sql_common " SIteId = '$siteId', SeqNo = '{$row->SeqNo}', SeqNoSpecified = '{$row->SeqNoSpecified}', 
                            Token = '
{$row->Token}', SiteType = '{$row->SiteType}', InquryType = '{$row->InquryType}', 
                            ReplyType = '
{$row->ReplyType}', InsDate = '{$row->InsDate}', UpdDate = '{$row->UpdDate}', 
                            ItemNo = '
{$row->ItemNo}', QueryType = '{$row->QueryType}', OrderNo = '{$row->OrderNo}', 

                            SellStatusCode = '
{$row->SellStatusCode}', SellStatus = '{$row->SellStatus}', Title = '{$row->Title}', 
                            Content = '
{$row->Content}', BuyerID = '{$row->BuyerID}', BuyerIdTemp = '{$row->BuyerIdTemp}', 
                            BuyerName = '
{$row->BuyerName}', ReplyDate = '{$row->ReplyDate}', ReplyDateSpecified = '{$row->ReplyDateSpecified}', 
                            ReplyCount = '
{$row->ReplyCount}', TelNum1 = '{$row->TelNum1}', TelNum2 = '{$row->TelNum2}', 
                            SellerId = '
{$row->SellerId}', LogisticsType = '{$row->LogisticsType}'
        "
;
        if(
$info['cnt']>'0'){
            
$sql "update $table set
                            
$sql_common 
                        where SiteId = '
{$siteId}' and SeqNo = '{$row->SeqNo}'
            "
;
            
$update_cnt++;
        } else {
            
$sql "insert into $table set $sql_common ";
            
$insert_cnt++;
        }

        
sql_query($sql);
        
//_pr($sql); 
        //exit;

        
$loginUrl "https://www.esmplus.com/Member/CustomerService/GetInquiryDetailIac";
        
$login_data "SeqNo={$row->SeqNo}&Token={$row->Token}&ItemNo={$row->ItemNo}++";

        
curl_setopt ($chCURLOPT_URL,$loginUrl);
        
curl_setopt($chCURLOPT_POSTFIELDS$login_data); 
        
$result2 curl_exec ($ch); 

        
$res2 json_decode($result2);
        
//_pr($res2);
        
$replay_cont "";
        for(
$ii=0;$ii<count($res2->data);$ii++){
            
$row2 $res2->data[$ii];
            if(
$row2->QnaSeqNo>0){
                
$row2->Content str_replace("/br","</br>",$row2->Content);
                
//_pr($row2->Content);
                
$replay_cont .= "[답변{$row2->QnaSeqNo}]</br>".$row2->Content."</br></br>";
            }
        }
        if(
$replay_cont!=''){
            
$replay_cont addslashes($replay_cont);
            
$sql "update $table set ReplyContent = '{$replay_cont}' where SiteId = '{$siteId}' and SeqNo = '{$row->SeqNo}' ";
            
sql_query($sql);
        }
    }
}

// 지마켓의 QNA 데이터 가져오기
$loginUrl "https://www.esmplus.com/Member/CustomerService/GetInquryList";
// 500개까지 가져옴
$login_data "page=1&limit=500&paramsData=%7B%22Site%22%3A%22G%22%2C%22Account%22%3A%22All%22%2C%22DateType%22%3A%22DA%22%2C%22StartDate%22%3A%22{$sdate}%22%2C%22EndDate%22%3A%22{$edate}%22%2C%22InquryType%22%3A%22AL%22%2C%22QueryType%22%3A%22AL%22%2C%22ReplyType%22%3A%22AL%22%2C%22KeywordType%22%3A%22KC%22%2C%22Keyword%22%3A%22%22%2C%22OrderType%22%3A%220%22%2C%22PageSize%22%3A20%2C%22CurrentPage%22%3A1%2C%22TotalCount%22%3A0%7D&SortFeild=InsDate&SortType=Desc";

curl_setopt ($chCURLOPT_URL,$loginUrl);
curl_setopt($chCURLOPT_POSTFIELDS$login_data); 
$result curl_exec ($ch); 

$res json_decode($result);
//_pr($res);

if($res->success!='1'){
    echo 
"<strong>ESM+ 상품정보를 가져오지 못했습니다. 로그인정보에 문제가 있을 가능성이 큽니다.</strong>";
} else {
    for(
$i=0;$i<$res->total;$i++){
        foreach(
$res->data[$i] as $key=>$val){
            if(
$key=='CategoryLName'){ // 캐릭터셋 필요시 사용
                //$res->data[$i]->$key = iconv("UTF-8","EUCKR",$val);
            
}
            if(
$key=='ItemNo'){
                
$res->data[$i]->$key trim(strip_tags($val));
            }
            if(
substr($val,0,5)=='/Date'){
                
$v substr($val,6,10);
                
$res->data[$i]->$key $v;
            }
        }
    }

    for(
$i=0;$i<$res->total;$i++){

        
$row $res->data[$i];

        if(
$row->SiteType=='IAC'){ 
            
$siteId 'au';
        } else if(
$row->SiteType=='GMKT'){
            
$siteId 'gm';
        } else {
            continue;
        }

        
$sql "select count(*) as cnt from $table where SiteId = '{$siteId}' and SeqNo = '{$row->SeqNo}' ";
        
$res2 sql_query($sql);
        
$info mysql_fetch_array($res2);
        
$sql_common " SIteId = '$siteId', SeqNo = '{$row->SeqNo}', SeqNoSpecified = '{$row->SeqNoSpecified}', 
                            Token = '
{$row->Token}', SiteType = '{$row->SiteType}', InquryType = '{$row->InquryType}', 
                            ReplyType = '
{$row->ReplyType}', InsDate = '{$row->InsDate}', UpdDate = '{$row->UpdDate}', 
                            ItemNo = '
{$row->ItemNo}', QueryType = '{$row->QueryType}', OrderNo = '{$row->OrderNo}', 

                            SellStatusCode = '
{$row->SellStatusCode}', SellStatus = '{$row->SellStatus}', Title = '{$row->Title}', 
                            Content = '
{$row->Content}', BuyerID = '{$row->BuyerID}', BuyerIdTemp = '{$row->BuyerIdTemp}', 
                            BuyerName = '
{$row->BuyerName}', ReplyDate = '{$row->ReplyDate}', ReplyDateSpecified = '{$row->ReplyDateSpecified}', 
                            ReplyCount = '
{$row->ReplyCount}', TelNum1 = '{$row->TelNum1}', TelNum2 = '{$row->TelNum2}', 
                            SellerId = '
{$row->SellerId}', LogisticsType = '{$row->LogisticsType}'
        "
;
        if(
$info['cnt']>'0'){
            
$sql "update $table set
                            
$sql_common 
                        where SiteId = '
{$siteId}' and SeqNo = '{$row->SeqNo}'
            "
;
            
$update_cnt++;
        } else {
            
$sql "insert into $table set $sql_common ";
            
$insert_cnt++;
        }

        
sql_query($sql);
        
//_pr($sql); 
        //exit;
        
$token urlencode($row->Token);
        
$loginUrl "https://www.esmplus.com/Member/CustomerService/GetInquiryDetail";
        
$login_data "SeqNo={$row->SeqNo}&Token={$token}";

        
curl_setopt ($chCURLOPT_URL,$loginUrl);
        
curl_setopt($chCURLOPT_POSTFIELDS$login_data); 
        
$result2 curl_exec ($ch); 

        
$res2 gm_reply_parse($result2);

        
$replay_cont "";
        for(
$ii=0;$ii<count($res2);$ii++){
            
$row2 $res2[$ii];
            
$row2['cont'] = str_replace("/br","</br>",$row2['cont']);
            
$ix $ii+1;
            
$replay_cont .= "[답변{$ix}]</br>".$row2['cont']."</br></br>";
        }
        if(
$replay_cont!=''){
            
$replay_cont addslashes($replay_cont);
            
$sql "update $table set ReplyContent = '{$replay_cont}' where SiteId = '{$siteId}' and SeqNo = '{$row->SeqNo}' ";
            
//_pr($sql);
            
sql_query($sql);
        }

    }
}

echo 
"추가된 레코드 : {$insert_cnt} 개<br>";
echo 
"수정된 레코드 : {$update_cnt} 개<br>";
echo 
"처리가 완료되었습니다.";

curl_close ($ch); 
?>