-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl.php
178 lines (151 loc) · 6.65 KB
/
curl.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
<?php
function getData($cmnd,$code){
$curl = curl_init('http://vpbrbqa-com.stackstaging.com');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl,CURLOPT_TIMEOUT,1000);
curl_setopt($curl, CURLOPT_POSTFIELDS,
"cmnd=$cmnd&code=$code");
$result = curl_exec($curl);
curl_close ($curl);
return $result;
}
function getCmnd($data){
$strLength = strlen(strval($data));
$cmd = substr($data,($strLength - 4));
if(substr($cmd,0,1) == 0){
$return = substr($cmd,1);
}else{
$return = $cmd;
}
return $return;
}
// example
/*$a = html_entity_decode(getData('2651','3861663'));
preg_match_all('/<table.*?>(.*?)<\/table>/si',$a, $out, PREG_PATTERN_ORDER);
preg_match_all('/<tr.*?>(.*?)<\/tr>/si',$out[0][0], $tr, PREG_PATTERN_ORDER);
preg_match_all('/<td.*?>(.*?)<\/td>/si',$tr[0][17], $td1, PREG_PATTERN_ORDER);
preg_match_all('/<td.*?>(.*?)<\/td>/si',$tr[0][18], $td2, PREG_PATTERN_ORDER);
echo "<pre>";
var_dump($tr);die();*/
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/scripts/phpExcel/PHPExcel.php';
echo date('H:i:s') , " Load from Excel2007 file" , EOL;
$callStartTime = microtime(true);
$objPHPExcel = PHPExcel_IOFactory::load("tmp/".$_FILES['uploaded_file']['name']);
$files = "tmp/".$_FILES['uploaded_file']['name'];
//Tiến hành xác thực file
$objFile = PHPExcel_IOFactory::identify($files);
$objData = PHPExcel_IOFactory::createReader($objFile);
//Chỉ đọc dữ liệu
$objData->setReadDataOnly(true);
// Load dữ liệu sang dạng đối tượng
$objPHPExcel = $objData->load($files);
//Lấy ra số trang sử dụng phương thức getSheetCount();
// Lấy Ra tên trang sử dụng getSheetNames();
//Chọn trang cần truy xuất
$sheet = $objPHPExcel->setActiveSheetIndex(0);
//Lấy ra số dòng cuối cùng
$Totalrow = $sheet->getHighestRow();
//Lấy ra tên cột cuối cùng
$LastColumn = $sheet->getHighestColumn();
//Chuyển đổi tên cột đó về vị trí thứ, VD: C là 3,D là 4
$TotalCol = PHPExcel_Cell::columnIndexFromString($LastColumn);
//Tạo mảng chứa dữ liệu
$data = [];
//Tiến hành lặp qua từng ô dữ liệu
//----Lặp dòng, Vì dòng đầu là tiêu đề cột nên chúng ta sẽ lặp giá trị từ dòng 2
for ($i = 1; $i <= $Totalrow; $i++) {
//----Lặp cột
for ($j = 0; $j < $TotalCol; $j++) {
// Tiến hành lấy giá trị của từng ô đổ vào mảng
$data[$i - 1][$j] = $sheet->getCellByColumnAndRow($j, $i)->getValue();;
}
}
$objPHPExcel = new PHPExcel();
// Set document properties
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("huyenxinh")
->setLastModifiedBy("huyenxinh")
->setTitle("haha")
->setSubject("list400")
->setDescription("test curls data")
->setKeywords("xxx")
->setCategory("list4000");
// Add some data
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'CIF')
->setCellValue('B1', 'FullName')
->setCellValue('C1', 'Cmd')
->setCellValue('D1', 'Result')
->setCellValue('E1', 'Đơn vị được khai thác')
->setCellValue('F1', 'Hạn mức UPL tối đa')
->setCellValue('G1', 'Hạn mức thẻ TD tối đa')
->setCellValue('H1', 'Phân luồng trình hồ sơ của UPL')
->setCellValue('I1', 'Phân luồng trình hồ sơ của CC');
$i = 2;
foreach ($data as $key => $value) {
$cmnd = getCmnd($value[2]);
$curls = getData($cmnd,$value[0]);
preg_match_all('/<table.*?>(.*?)<\/table>/si',$curls, $out, PREG_PATTERN_ORDER);
$result = 0;
$t1 = $t2 = $t3 = $t4 = $t5 = '';
if(!empty($out[1])){
preg_match_all('/<table.*?>(.*?)<\/table>/si',$curls, $out, PREG_PATTERN_ORDER);
preg_match_all('/<tr.*?>(.*?)<\/tr>/si',$out[0][0], $tr, PREG_PATTERN_ORDER);
preg_match_all('/<td.*?>(.*?)<\/td>/si',$tr[0][3], $td1, PREG_PATTERN_ORDER);
preg_match_all('/<td.*?>(.*?)<\/td>/si',$tr[0][4], $td2, PREG_PATTERN_ORDER);
preg_match_all('/<td.*?>(.*?)<\/td>/si',$tr[0][5], $td3, PREG_PATTERN_ORDER);
preg_match_all('/<td.*?>(.*?)<\/td>/si',$tr[0][17], $td4, PREG_PATTERN_ORDER);
preg_match_all('/<td.*?>(.*?)<\/td>/si',$tr[0][18], $td5, PREG_PATTERN_ORDER);
$result = 1;
$t1 = strip_tags($td1[0][1],"<td>");
$t2 = strip_tags($td2[0][1],"<td>");
$t3 = strip_tags($td3[0][1],"<td>");
$t4 = strip_tags($td4[0][1],"<td>");
$t5 = strip_tags($td5[0][1],"<td>");
}
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$i, $value[0])
->setCellValue('B'.$i, $value[1])
->setCellValue('C'.$i, $value[2])
->setCellValue('D'.$i, $result)
->setCellValue('E'.$i, $t1)
->setCellValue('F'.$i, $t2)
->setCellValue('G'.$i, $t3)
->setCellValue('H'.$i, $t4)
->setCellValue('I'.$i, $t5);
$i++;
}
// Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet()->setTitle('huyenxinh');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($_FILES['uploaded_file']['name']);
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
// Echo done
echo date('H:i:s') , " Done writing files" , EOL;
echo 'Files have been created in ' , getcwd() , EOL;
?>