· 5 years ago · Jan 27, 2021, 02:24 AM
1<?php
2 botLog("postion", "nlp ocr");
3 if(getUserVar("QAFOUND")!="TRUE"){
4
5 $msg = strtolower(getUserMessage());
6
7 if(empty($msg)){
8 $msg = strtolower(getUserVar("MSGFORNLP"));
9 }
10
11 $img = getUserImage();
12
13 if($img!=""){
14
15 $no = 1;
16
17 $msg = str_replace("<br>", "-", $msg);
18 $msg = preg_replace("/[^A-Za-z0-9 ]/", "-", $msg);
19 $explodeMsg = explode("-", $msg);
20
21 for($i = 0; $i < sizeof($explodeMsg); $i++){
22 if(strlen($explodeMsg[$i]) == 9){
23 $bl[] = $explodeMsg[$i];
24 }
25 }
26
27 $temparray = []; $i = 0;
28 foreach($bl as $val){
29 $temparray[$val] = [$i];
30 $i++;
31 }
32 foreach($temparray as $key => $val){
33 $bl_uniq[] = $key;
34 }
35
36 for($x = 0; $x < sizeof($bl_uniq); $x++){
37 $url = "http://botmaster2.botika.online/server/mcc/API/index.php";
38
39 $tempArr["accessToken"] = "2625d26a-7023-45ea-9a9e-31694a70998d"; //accessToken
40 $tempArr["action"] = "getFreetimeStatusBL"; //actionnya
41 $tempArr["botId"] = "bc1n715x8ea";//bot id nya Myanmar
42 $tempArr["bl"] = strtoupper($bl_uniq[$x]);
43
44 $json = json_encode($tempArr);
45
46 //Initiate cURL.
47 $ch = curl_init();
48 //curl_setopt($ch, CURLOPT_HEADER, 1);
49
50 //Tell cURL that we want to send a POST request.
51 curl_setopt($ch, CURLOPT_POST, true);
52 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
53 curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
54 curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
55 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
56 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
57
58 // set url
59 curl_setopt($ch, CURLOPT_URL, $url);
60 curl_setopt($ch, CURLOPT_HTTPHEADER,
61 array(
62 "Content-Type: application/json",
63 "Accept: application/json",
64 )
65 );
66
67 //Execute the request
68 $result = curl_exec($ch);
69 if(curl_error($ch))
70 {
71 botLog("error", curl_error($ch));
72 }
73 curl_close($ch);
74
75 botLog("json", $json);
76 botLog("result api freetime", $result);
77
78 $results = json_decode($result,true);
79
80 if($results["result"]=="success"){
81
82 if($results["data"][0]["ftd_ft_dem"]!="" && $results["data"][0]["ftd_ft_det"]!=""){
83 $freetime_exp = "Export Freetime: Demurrage ".$results["data"][0]["ftd_ft_dem"]." days & Detention ".$results["data"][0]["ftd_ft_det"]." days <BR>";
84 }
85
86 if($results["data"][0]["ftd_ft"]!=""){
87 $freetime_imp = "Import Freetime: ".$results["data"][0]["ftd_ft"]." days <BR>";
88 }
89
90 // $bl_type = $results["data"][0]["document_group"];
91 // $task_status = $results["data"][0]["task_name"];
92
93 // if((strtolower($bl_type) == "sea waybill" && strtolower($task_status) == "open")){
94 // $bl_status = "No";
95 // }elseif((strtolower($bl_type) == "original" && strtolower($task_status) == "open")){
96 // $bl_status = "No";
97 // }elseif((strtolower($bl_type) == "sea waybill" && strtolower($task_status) == "closed")){
98 // $bl_status = "Yes";
99 // }elseif((strtolower($bl_type) == "original" && strtolower($task_status) == "closed")){
100 // $bl_status = "Yes";
101 // }else{
102 // $bl_status = "No";
103 // }
104 }
105
106 $url = "https://client.botmaster2.botika.online/mcc/API/myanmar.php";
107
108 $tempArr["accessToken"] = "2625d26a-7023-45ea-9a9e-31694a70998d"; //accessToken
109 $tempArr["action"] = "paymentBl"; //actionnya
110 $tempArr["botId"] = "bc1n715x8ea";//bot id nya Myanmar
111 $tempArr["bl"] = strtoupper($bl_uniq[$x]);
112
113 $json = json_encode($tempArr);
114
115 //Initiate cURL.
116 $ch = curl_init();
117 //curl_setopt($ch, CURLOPT_HEADER, 1);
118
119 //Tell cURL that we want to send a POST request.
120 curl_setopt($ch, CURLOPT_POST, true);
121 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
122 curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
123 curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
124 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
125 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
126
127 // set url
128 curl_setopt($ch, CURLOPT_URL, $url);
129 curl_setopt($ch, CURLOPT_HTTPHEADER,
130 array(
131 "Content-Type: application/json",
132 "Accept: application/json",
133 )
134 );
135
136 //Execute the request
137 $result = curl_exec($ch);
138 if(curl_error($ch))
139 {
140 botLog("error", curl_error($ch));
141 }
142 curl_close($ch);
143
144 botLog("json", $json);
145 botLog("result api payment bl", $result);
146
147 $results = json_decode($result,true);
148
149 if($results["isSuccess"]=="true"){
150 $bl_type = $results["data"][0]["document_group"];
151
152 if(strstr($payment["data"][0]["document_group"], "Sea Waybill")){
153 $status_group[$x] = "Sea Waybill";
154 }elseif(strstr($payment["data"][0]["document_group"], "Negotiable")){
155 $status_group[$x] = "Original BL";
156 }else{
157 $status_group[$x] = "Against present of OBL";
158 }
159 }
160
161
162 // api tracking
163 $url = "https://api.maerskline.com/track/".strtoupper($bl_uniq[$x])."?operator=mcpu";
164
165 $ch = curl_init();
166
167 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
168 curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
169 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
170 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
171 curl_setopt($ch, CURLOPT_URL, $url);
172 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
173 "Authorization: Atmosphere atmosphere_app_id=rcewucoc-8DIAwrPS6rI1PoD3y3emWs8P"
174 ));
175
176 $results = curl_exec($ch);
177 if(curl_error($ch)){
178 botLog("error", curl_error($ch));
179 }
180 curl_close($ch);
181 $result = json_decode($results, true);
182
183 $ctr = "";
184 if($result["tpdoc_num"]!="" || !$result["error"]){
185 $tpdoc[$x] = $result["tpdoc_num"];
186
187 $origin[$x] = $result["origin"]["country"];
188 $pod_import[$x] = $result["destination"]["terminal"];
189
190 foreach($result["containers"] as $key => $container){
191 $containerNumber[$x][$key] = $container["container_num"];
192
193 $pod[$x] = $container["latest"]["city"].", ".$container["latest"]["country"];
194
195 $eta[$x] = date("Y-M-d H:i", strtotime($container["eta_final_delivery"]));
196 $etd[$x] = date("Y-M-d H:i", strtotime($container["latest"]["actual_time"]));
197
198 foreach($container["locations"] as $location){
199 foreach($location["events"] as $event){
200 if($event["vessel_name"]!=""){
201 $vesselName[$x] = $event["vessel_name"];
202 }
203
204 if($event["voyage_num"]!=""){
205 $voyageNum[$x] = $event["voyage_num"];
206 }
207
208
209 }
210
211 foreach($location["events"] as $event){
212 $activity[$x] = $event["activity"];
213 if($activity[$x] == "DISCHARG"){
214 $port_of_discharge[$x] = $location["city"].", ".$location["country"];
215 }
216 if($activity[$x] == "LOAD"){
217 $port_of_load[$x] = $location["city"].", ".$location["country"];
218 }
219 }
220 }
221 if(sizeof($containerNumber[$x]) > 1){
222 $ctr .= " - ".$containerNumber[$x][$key];
223 }else{
224 $ctr = $containerNumber[$x][$key];
225 }
226
227 }
228
229
230
231 if($origin[$x] == "Myanmar (Burma)"){
232 $chat = "<b>Export</b><BR><BR>".
233
234 $tpdoc[$x]." - ".$ctr."<BR><BR>".
235
236 "Vessel: ".$vesselName[$x]."<BR>".
237 "Voyage Number: ".$voyageNum[$x]."<BR>".
238 "Load Port: ".$port_of_load[$x]."<BR>".
239 "Discharge Port: ".$port_of_discharge[$x]."<BR>".
240 "Departure Date:".$etd[$x]."<BR>".
241 "Arrival Date: ".$eta[$x]."<BR><BR>".
242
243 // $freetime_exp.
244 // $freetime_imp."<BR>".
245
246 "BL Type: ".$bl_type."<BR><BR>".
247
248 "Detail transport plan can be downloaded on Sealand website <BR>".
249 "https://www.sealandmaersk.com<BR><BR>".
250
251 "Disclaimer: <BR>".
252 "- Departure/Arrival Date is subject to actual/estimated depending on vessel actual information availability.<BR>".
253 "- SOB can only be confirmed after container is loaded. All dates and times are given as reasonable estimates only and subject to change with or without prior notice.";
254 }else{
255 $chat = "<b>Import</b><BR><BR>".
256
257 $tpdoc[$x]." - ".$ctr."<BR><BR>".
258
259 "Vessel: ".$vesselName[$x]."<BR>".
260 "Voyage Number: ".$voyageNum[$x]."<BR>".
261 "Load Port: ".$port_of_load[$x]."<BR>".
262 "Discharge Port: ".$port_of_discharge[$x]."<BR>".
263 "Place of Delivery: ".$pod_import[$x]."<BR>".
264 "Estimated Arrival Date: ".$eta[$x]."<BR><BR>".
265
266 $freetime_imp."<BR>".
267
268 "BL Type: ".$bl_type."<BR>".
269 "BL Status: ".$status_group[$x]."<BR><BR>".
270 "Disclaimer: <BR>".
271 "- Departure/Arrival Date is subject to actual/estimated depending on vessel actual information availability.<BR>".
272 "- All dates and times are given as reasonable estimates only and subject to change with or without prior notice. <BR>".
273 "- One-off detention approval will not be reflected in the above information. ";
274 }
275 }else{
276 $chat = "BL Number : ".$bl_uniq[$x]."<BR>Apologize for not able to provide shipment status,<BR>".
277 "please contact our local customer service as per below:<BR>".
278 "Export – email to mm.export@sealandmaersk.com<BR>".
279 "Import – email to mm.import@sealandmaersk.com>";
280 }
281 botSendMessage(["text"=>$chat]);
282 setUserVar("QAFOUND", "TRUE");
283 }
284 }
285 setUserVar("MSGFROMNLP", "");
286 }