· 7 years ago · Sep 06, 2018, 06:18 PM
1<?php
2
3namespace IDVInnoCigsConnector;
4
5/**
6 * @copyright IJustDev
7 * <IDVInnoCigsConnector> Copyright (C) 2018 IJustDev
8 * This program comes with ABSOLUTELY NO WARRANTY
9 *
10 */
11use IDVInnoCigsConnector\InnoCigsAPIClient;
12use Shopware\Components\Plugin\Context\ActivateContext;
13use Shopware\Components\Plugin\Context\InstallContext;
14use Shopware\Components\Plugin\Context\UninstallContext;
15
16class IDVInnoCigsConnector extends \Shopware\Components\Plugin
17{
18
19
20 //DEBUG-LEVEL 0-3
21 public $DEBUG_LEVEL = 2;
22
23 //InnoCigsAPIClient
24 public $apiclient;
25
26 //Logfile
27 public $logfile;
28
29
30 /**
31 * Shopware initialize
32 */
33 public static function getSubscribedEvents()
34 {
35
36 return [
37 'Enlight_Controller_Action_PostDispatch_Frontend_Detail' => 'changeArticleStock_on_Frontend_Detail',
38 'Shopware_CronJob_RefreshOrder'=>'CommitOrderCronJob',
39 'Shopware_CronJob_updateTrackingData' =>'updateTrackingDataCronJob',
40 'Shopware_CronJob_updateArticleStock' =>'updateArticleCronJob',
41 # Importing ArticleImportCronJob in Version 1.1.7
42 # 'Shopware_CronJob_importArticles' =>'ArticleImportCronJob',
43 'Shopware_Controllers_Frontend_Checkout::ajaxAddArticleCartAction::after'=>'fetchArticleStockFromAPI_on_Checkout'];
44
45 }
46
47 public function install(InstallContext $context)
48 {
49
50 //Create s_idv_orderstatus if not exists
51 Shopware()->Db()->executeQuery("CREATE TABLE IF NOT EXISTS s_idv_orderstatus (
52 id INT AUTO_INCREMENT,
53 orderid VARCHAR(50),
54 orderstatus INT,
55 PRIMARY KEY (id));
56 ");
57 }
58
59 public function activate(ActivateContext $context)
60 {
61 //Create s_idv_orderstatus if not exists
62 Shopware()->Db()->executeQuery("CREATE TABLE IF NOT EXISTS s_idv_orderstatus (
63 id INT AUTO_INCREMENT,
64 orderid VARCHAR(50),
65 orderstatus INT,
66 PRIMARY KEY (id));
67 ");
68
69 }
70
71 public function uninstall(UninstallContext $context)
72 {
73
74 //Delete Database
75 Shopware()->Db()->executeQuery("DROP TABLE IF EXISTS s_idv_orderstatus;");
76 //Remove Cronjob
77 $query = Shopware()->Db()->executeQuery("SELECT * FROM s_crontab WHERE name='OrderRefresher';")->fetchAll()[0];
78 $exists["id"] = $query["id"];
79 if($exists["id"]!=null)
80 Shopware()->Db()->executeQuery("DELETE FROM s_crontab WHERE id=?",[$exists["id"]]);
81 $query = Shopware()->Db()->executeQuery("SELECT * FROM s_crontab WHERE name='TrackingDataUpdater';")->fetchAll()[0];
82 $exists["id"] = $query["id"];
83 if($exists["id"]!=null)
84 Shopware()->Db()->executeQuery("DELETE FROM s_crontab WHERE id=?",[$exists["id"]]);
85 Shopware()->Db()->executeQuery("DELETE FROM s_crontab WHERE id=?",[$exists["id"]]);
86 }
87
88
89 /**
90 * Changes Stockvalue of article to Stockvalue from database with articleid from detail page
91 */
92 public function changeArticleStock_on_Frontend_Detail(\Enlight_Controller_ActionEventArgs $args){
93
94 $this->apiclient = new InnoCigsAPIClient($this->getAPIUsername(),$this->getAPIKey());
95 $view = $args->getSubject()->View();
96 $sArticle = $view->getAssign('sArticle');
97
98 $ordernumber = $sArticle['ordernumber'];
99 $instock = $this->apiclient->getStock($ordernumber);
100
101 if($instock==0){
102 $sArticle["isAvailable"] = false;
103 $sArticle["instock"] = 0;
104 }
105
106 $view->assign("sArticle", $sArticle);
107
108 Shopware()->Db()->executeUpdate("UPDATE s_articles_details SET instock=? WHERE ordernumber=?;", [intval($instock), $ordernumber]);
109
110 }
111
112
113 /**
114 * Commits order to InnoCigs-API
115 *
116 * s_idv_orderstatus - Statuscodes
117 * 0 = Order not commited
118 * 1 = Commited already
119 */
120 public function CommitOrderCronJob(){
121
122 $fetched = Shopware()->Db()->executeQuery("SELECT * FROM s_order;")->fetchAll();
123 $this->apiclient = new InnoCigsAPIClient($this->getAPIUsername(), $this->getAPIKey());
124 foreach($fetched as $object) {
125 $ordernumber = $object['ordernumber'];
126
127 $clearingstatus = intval($object['cleared']);
128
129 $orderstatus = intval($object['status']);
130
131 $s_idv_orderstatus = Shopware()->Db()->executeQuery("SELECT orderstatus FROM s_idv_orderstatus WHERE orderid=?", [$object['ordernumber']])->fetchAll();
132
133 if($s_idv_orderstatus[0]["orderstatus"]==null){
134 Shopware()->Db()->executeQuery("INSERT INTO s_idv_orderstatus(orderid, orderstatus) VALUES(?, ?)", [$object['ordernumber'], 0]);
135 continue;
136 }
137
138 if(intval($s_idv_orderstatus[0]["orderstatus"])==1)
139 continue;
140
141 if($clearingstatus==12 && $orderstatus==0){
142
143 $response = $this->apiclient->sendOrder($ordernumber, $this);
144 $xmlparsed_response = simplexml_load_string($response);
145 $success = $xmlparsed_response->DROPSHIPPING->DROPSHIP->STATUS=="OK";
146 if($success){
147
148 Shopware()->Db()->executeUpdate("UPDATE s_idv_orderstatus SET orderstatus=? WHERE orderid=?", [1, $ordernumber]);
149 Shopware()->Db()->executeUpdate("UPDATE s_order SET status=? WHERE ordernumber=?;", [1, $ordernumber]);
150
151 }else{
152 Shopware()->Db()->executeUpdate("UPDATE s_order SET status=? WHERE ordernumber=?;", [8, $ordernumber]);
153
154 print("Error with Order: ".$ordernumber."!".$xmlparsed_response);
155
156 $errorfile = fopen("InnoCigsLogs/".$ordernumber.".error.log", "w");
157
158 fwrite($errorfile, "Error response from InnoCigs: \n");
159 fwrite($errorfile, $xmlparsed_response);
160 fclose($errorfile);
161
162 }
163
164 }
165 }
166 }
167
168
169 /**
170 * Update-Tracking-Data-Cron
171 *
172 * Updates your tracking data
173 */
174 public function updateTrackingDataCronJob(){
175
176 $this->apiclient = new InnoCigsAPIClient($this->getAPIUsername(), $this->getAPIKey());
177
178 $date = date('Y-m-d');
179
180 $trackingdataxml = $this->apiclient->getTrackingData($date);
181
182 foreach($trackingdataxml->TRACKING->DROSPHIP as $tracking){
183
184 $ordernumber = $tracking->ORDERS_NUMBER;
185
186 $ordernumber = str_replace("ORDER", "", $ordernumber);
187
188 $trackingcode = $tracking->TRACKINGS->TRACKINGINFO->CODE;
189
190 Shopware()->Db()->executeUpdate("UPDATE s_order SET trackingcode=? WHERE ordernumber=?;", [$trackingcode, $ordernumber]);
191 Shopware()->Db()->executeUpdate("UPDATE s_order SET `status`=? WHERE ordernumber=?;", [5, $ordernumber]);
192
193 }
194
195 }
196
197
198 /**
199 * Update Article Stock CronJob
200 */
201 public function updateArticleCronJob(){
202 $articleswithstockandordernumber = Shopware()->Db()->executeQuery("SELECT ordernumber, instock, articleID FROM s_articles_details;")->fetchAll();
203 $this->apiclient = new InnoCigsAPIClient($this->getAPIUsername(), $this->getAPIKey());
204 $xml = $this->apiclient->getAllStocks();
205 $products = [];
206
207 foreach($xml->QUANTITIES->PRODUCT as $product){
208
209 //Assigning stock to ordernumber
210 $products["".$product->PRODUCTS_MODEL] = $product->QUANTITY;
211
212 }
213
214 foreach($articleswithstockandordernumber as $item){
215
216 $articleID = $item["articleID"];
217 $ordernumber = $item["ordernumber"];
218
219 if($products[$ordernumber] != $item["instock"]){
220
221 Shopware()->Db()->executeUpdate("UPDATE s_articles_details SET instock=? WHERE ordernumber=?;", [$products[$ordernumber], $ordernumber]);
222
223 }
224
225 }
226 }
227
228
229 /**
230 * CronJob
231 * Import All Articles From InnoCigs
232 */
233 public function ArticleImportCronJob(){
234
235 $this->apiclient = new InnoCigsAPIClient($this->getAPIUsername(), $this->getAPIKey());
236 $allproducts = $this->apiclient->getAllProducts();
237
238 # Get All Products
239 $already_inserted_articles = Shopware()->Db()->executeQuery("SELECT ordernumber FROM s_articles_details;")->fetchAll();
240
241 foreach($allproducts->PRODUCT as $product){
242
243 # Check if database contains Ordernumber
244 if(in_array($product->MODEL, $already_inserted_articles)){
245 continue;
246 }
247
248 $productobject = array();
249 $productobject["master"] = $product->MASTER;
250 $productobject["ean"] = $product->EAN;
251 $productobject["name"] = $product->NAME;
252 $productobject["price"] = $product->PRODUCTS_PRICE;
253 $productobject["img"] = $product->PRODUCTS_IMAGE;
254 $productobject["model"] = $product->MODEL;
255
256 if(Shopware()->Db()->executeQuery("SELECT * FROM s_articles_details WHERE ordernumber=?;", [$productobject["model"]])->fetchAll()[0]["ordernumber"]!=null){
257 continue;
258 }
259
260 $master_ordernumber_result = Shopware()->Db()->executeQuery("SELECT * FROM S_articles_details WHERE ordernumber=?;", [$productobject["master"]])->fetchAll();
261
262 if($master_ordernumber_result != null){
263 insertProductWithMaster($productobject);
264 }else{
265 instertProductWithOutMaster($productobject);
266 }
267
268 }
269
270 }
271
272
273 public function insertProductWithMaster($product){
274
275 $articleid = Shopware()->Db()->executeQuery("SELECT articleID from s_articles_details WHERE ordernumber=?;", [$product["master"]])->fetchAll();
276
277 # Insert Into s_articles_details with articleID of Master
278 Shopware()->Db()->executeQuery("INSERT INTO s_articles_details(articleID, ordernumber, active, instock, ean, pursacheprice) VALUES(?, ?, '0', '0', ?, ?);", [$articleid, $product["model"], $product["ean"], $product["price"]]);
279
280 # Todo Download Images
281
282 # Get Next Image Position
283 $nextPosition = getNextPosition($articleid);
284
285 # Insert Image (The Wrong Way)
286 Shopware()->Db()->executeQuery("INSERT INTO s_articles_relationships(articleID, img, main, position, extension) VALUES(?, ?, ?, ?, ?);", [$article, $img, 2, $nextPosition, $extension]);
287
288 # Make use of Image Profile
289
290 }
291
292 public function insertProductWithOutMaster($product){
293
294 # Insert Into s_articles
295 Shopware()->Db()->executeQuery("INSERT INTO s_articles(`name`, `active`) VALUES(?,?);", [$product["name"], '0']);
296
297 # Todo Download Images
298
299 # Get Article of article added to Database
300 $articleid = Shopware()->Db()->executeQuery("SELECT id FROM s_articles WHERE `name`=? AND `active`='0';", [$product["name"]])->fetchAll()[0]["id"];
301
302 # Insert Into s_articles_details
303 Shopware()->Db()->exequteQuery("INSERT INTO s_articles_details(articleID, ordernumber, active, instock, ean, pursacheprice) VALUES(?,?,'0', ?, ?)", [$articleid, $product["model"], 0, 0, $product["ean"], $product["price"]]);
304
305 # Make use of Image Profile
306 }
307
308
309 public function getNextPosition($articleid){
310 $positionsArray = Shopware()->Db()->executeQuery("SELECT position FROM s_articles_relationships WHERE articleID=?;", [$articleid])->fetchAll();
311
312 $highestposition = 0;
313 foreach ($positionsArray as $position){
314 if($position > $highestposition)
315 {
316 $highestposition = $position["position"];
317 }
318 }
319
320 return $highestposition+1;
321 }
322
323
324 public function downloadImage($filename, $link){
325 file_put_contents($filename, $link);
326 }
327
328
329 /**
330 * Frontend-Detail
331 * Checks Article Stock for opened article
332 */
333 public function fetchArticleStockFromAPI_on_Checkout(\Enlight_Hook_HookArgs $args)
334 {
335
336 $basket = $args->getSubject()->getBasket();
337 $showmessage = false;
338
339 foreach ($basket["content"] as $item) {
340
341 if ($item["instock"] == 0) {
342 Shopware()->Modules()->Basket()->sDeleteArticle($item["id"]);
343 $showmessage = true;
344 }
345
346 }
347
348 if ($showmessage) echo "Es ist ein Fehler aufgetreten. Dieser Aritkel steht derzeit nicht zum Kauf zur Verfügung.";
349 }
350
351
352 /**
353 * Config-Access
354 *
355 *
356 * @return string
357 * Returns API-Username from Config
358 */
359 public function getAPIUsername()
360 {
361
362 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'apiUsername');
363 }
364
365 /**
366 * @return string
367 * Returns API-Password from Config
368 */
369 public function getAPIKey()
370 {
371
372 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'apiKey');
373 }
374
375
376 /**
377 * companyName
378 * vorName
379 * nachName
380 * streetAddress
381 * postCode
382 * email
383 * telefonNummer
384 * city
385 * countryCode
386 */
387
388 public function getCompanyName(){
389 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'companyName');
390 }
391
392 public function getVorName(){
393 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'vorName');
394 }
395
396 public function getNachName(){
397 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'nachName');
398 }
399
400 public function getStreetAddress(){
401 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'streetAddress');
402 }
403
404 public function getPostCode(){
405 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'postCode');
406 }
407
408 public function getEmail(){
409 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'email');
410 }
411
412 public function getTelefonNummer(){
413 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'telefonNummer');
414 }
415
416 public function getCity(){
417 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'city');
418 }
419
420 public function getCountryCode(){
421 return (string) Shopware()->Config()->getByNamespace('IDVInnoCigsConnector', 'countryCode');
422 }
423
424
425
426
427 /**
428 * Logging
429 *
430 * @return File
431 * Returns LogFile
432 */
433 public function initLogFile(){
434
435 if($this->logfile = null) {
436
437 $this->logfile = fopen("InnoCigsLogs/logfile.txt", "a");
438 }
439
440 return $this->logfile;
441
442 }
443
444
445 //Log to log file
446 public function log($loginfo, $loglevel){
447
448 $logfile = $this->initLogFile();
449 $prefix = "";
450
451 switch($loglevel){
452
453 case "info" || "i":
454 $prefix = "[info] ";
455 break;
456
457 case "exception" || "e":
458 $prefix = "[exception] ";
459 break;
460
461 case "success" || "s":
462 $prefix = "[success] ";
463 break;
464
465 }
466
467 $now = new DateTime();
468 $now->format('Y-m-d H:i:s'); // MySQL datetime format
469
470 if($this->DEBUG_LEVEL > 0){
471 fwrite($logfile, $now->getTimestamp()." ". $prefix. $loginfo. "\n");
472 echo $now->getTimestamp()." ". $prefix.$loginfo;
473 fclose($logfile);
474 }
475
476 }
477
478}
479
480
481
482<?php
483/**
484 * Created by PhpStorm.
485 * User: Gott
486 * Date: 24.06.2018
487 * Time: 12:28
488 */
489namespace IDVInnoCigsConnector;
490/**
491 * @copyright Copyright (C) 2018 IJustDev
492 * InnoCigsAPIClient
493 */
494class InnoCigsAPIClient {
495
496
497 /**
498 * @var string
499 * API-Url for connecting to InnoCigs
500 */
501 private $apiurl;
502
503 /**
504 * @var string
505 * API-Username for authentication :InnoCigs
506 */
507 private $apiusername;
508
509 /**
510 * @var API-Password for authentication :InnoCigs
511 */
512 private $apikey;
513
514
515
516 public function __construct($apiusername, $apikey)
517 {
518
519 $this->apiusername=$apiusername;
520 $this->apikey = $apikey;
521 $this->apiurl = "https://www.innocigs.com/xmlapi/api.php?cid=".$this->getApiusername().'&auth='.$this->getApikey();
522
523 }
524
525 /**
526 * @return mixed
527 */
528 public function getApikey()
529 {
530
531 return $this->apikey;
532 }
533
534 /**
535 * @return mixed
536 */
537 public function getApiurl()
538 {
539
540 return $this->apiurl;
541 }
542
543 /**
544 * @return mixed
545 */
546 public function getApiusername()
547 {
548
549 return $this->apiusername;
550 }
551
552
553 /**
554 * Get Stock From Article by ArticleID
555 *
556 * @param article_id
557 * @return int
558 * Returns inStock from InnoCigs with ArticleID
559 */
560 public function getStock($articleID){
561
562 $url = $this->apiurl."&command=quantity&model=".$articleID;
563 $xml = simplexml_load_file($url);
564
565 foreach($xml->ERRORS->ERROR as $error){
566
567 echo($error->MESSAGE);
568 }
569
570 $stock= $xml->QUANTITIES->PRODUCT[0]->QUANTITY."";
571
572 if(!is_numeric($stock))
573 return 0;
574
575 return (int)$stock;
576
577 }
578
579
580 public function getAllStocks(){
581
582 $url = $this->getApiurl()."&command=quantity_all";
583 $xml = simplexml_load_file($url);
584
585 return $xml;
586
587 }
588
589 /**
590 * Fetching TrackingData from InnoCigsAPI
591 *
592 * @return array
593 * returns XML-Object with Tracking-Code
594 */
595 public function getTrackingData($date){
596
597 $url = $this->getApiurl().'&command=tracking&day='.$date;
598 $xml = simplexml_load_file($url);
599
600 return $xml;
601
602 }
603
604
605 /**
606 * Get All Products of InnoCigs with '&command=products'
607 */
608 public function getAllProducts(){
609
610 $url = $this->getApiurl().'&command=products';
611 $xml = simplexml_load_file($url);
612
613 return $xml;
614
615 }
616
617 /**
618 * Sending order
619 *
620 * @param $ordernumber
621 * @return mixed
622 * @throws \Zend_Db_Statement_Exception
623 */
624 public function sendOrder($ordernumber, $idvinnocigsconnector){
625
626 //Read template
627 $filecontent = file_get_contents(__DIR__."/InnoCigsOrderTemplate.xml");
628
629 //Define Tables to lookup
630 $orderdetailsdb = Shopware()->Db()->executeQuery("SELECT * FROM s_order_details WHERE ordernumber=?;", [$ordernumber])->fetchAll();
631
632 $orderID = $orderdetailsdb[0]["orderID"];
633
634 //Define User Database
635 $userdb = Shopware()->Db()->executeQuery("SELECT * FROM s_order_shippingaddress WHERE orderID='".$orderID."';")->fetchAll();
636
637 //Define Item Array
638 $items = [];
639 $curindex = 0;
640
641 foreach($orderdetailsdb as $item){
642
643 $items[$curindex]["name"] = $item["name"];
644 $items[$curindex]["quantity"] =$item["quantity"];
645 $items[$curindex]["aodnumber"] = $item["articleordernumber"];
646 $items[$curindex]["articleID"] = $item["articleID"];
647 $items[$curindex]["price"] = $item["price"];
648 $items[$curindex]["modus"] = $item["modus"];
649 $curindex=(int)$curindex+1;
650
651 }
652
653 //Fetch Usercredentials
654 $usercredentials = [];
655 $usercredentials["company"] = $userdb[0]["company"];
656 $usercredentials["firstname"] = $userdb[0]["firstname"];
657 $usercredentials["lastname"] = $userdb[0]["lastname"];
658 $usercredentials["street"] = $userdb[0]["street"];
659 $usercredentials["city"] = $userdb[0]["city"];
660 $usercredentials["zipcode"] = $userdb[0]["zipcode"];
661 $usercredentials["countrycode"] = Shopware()->Db()->executeQuery("SELECT countryiso FROM s_core_countries WHERE id=?",[$userdb[0]["countryID"]])->fetchAll()[0]["countryiso"];
662 $usercredentials["firstname"] = str_replace("ä","ae", $usercredentials["firstname"]);
663
664 //Make use of template
665 $filecontent = str_replace("{ordernumber}", $ordernumber, $filecontent);
666 $filecontent = str_replace("{products}", $this->xmlBuilderArticles($items), $filecontent);
667 $filecontent = str_replace("{company}", $usercredentials["company"], $filecontent);
668 $filecontent = str_replace("{firstname}", $usercredentials["firstname"],$filecontent);
669 $filecontent = str_replace("{lastname}", $usercredentials["lastname"],$filecontent);
670 $filecontent = str_replace("{street}", $usercredentials["street"],$filecontent);
671 $filecontent = str_replace("{postcode}", $usercredentials["zipcode"],$filecontent);
672 $filecontent = str_replace("{city}", $usercredentials["city"],$filecontent);
673 $filecontent = str_replace("{countrycode}", $usercredentials["countrycode"],$filecontent);
674 $filecontent = str_replace("ä", "ae",$filecontent);
675 $filecontent = str_replace("ö", "oe",$filecontent);
676 $filecontent = str_replace("ü", "ue",$filecontent);
677 $filecontent = str_replace("ß", "ss",$filecontent);
678
679
680 //Sender Credentials
681 $filecontent = str_replace("{sender_company}", $idvinnocigsconnector->getCompanyName(), $filecontent);
682 $filecontent = str_replace("{sender_firstname}", $idvinnocigsconnector->getVorName(),$filecontent);
683 $filecontent = str_replace("{sender_lastname}", $idvinnocigsconnector->getNachName(),$filecontent);
684 $filecontent = str_replace("{sender_streetaddress}", $idvinnocigsconnector->getStreetAddress(),$filecontent);
685 $filecontent = str_replace("{sender_postcode}", $idvinnocigsconnector->getPostCode(),$filecontent);
686 $filecontent = str_replace("{sender_email}", $idvinnocigsconnector->getEmail(),$filecontent);
687 $filecontent = str_replace("{sender_telephone}", $idvinnocigsconnector->getTelefonNummer() ,$filecontent);
688 $filecontent = str_replace("{sender_city}", $idvinnocigsconnector->getCity(),$filecontent);
689 $filecontent = str_replace("{sender_countrycode}", $idvinnocigsconnector->getCountryCode(),$filecontent);
690
691
692 $filecontent = "cid=".$this->getApiusername()."&auth=".$this->getApikey()."&command=dropship&xml=".$filecontent;
693 $res = $this->httpPost("https://www.innocigs.com/xmlapi/api.php", $filecontent);
694
695 return $res;
696
697 }
698
699
700 /**
701 * @param articles[]
702 * Builds XML Source with articles
703 * @return string
704 */
705 public function xmlBuilderArticles($articles){
706
707 $xmlsource = "";
708 foreach($articles as $article) {
709
710 if($article["modus"]==4)continue;
711
712 $xmlsource.="
713 <PRODUCT>
714 <PRODUCTS_MODEL>".$article["aodnumber"]."</PRODUCTS_MODEL>
715 <QUANTITY>".$article['quantity']."</QUANTITY>
716 </PRODUCT>";
717
718 }
719 return $xmlsource;1
720
721 }
722
723
724 function httpPost($url, $data) {
725
726 $curl = curl_init($url);
727
728 curl_setopt($curl, CURLOPT_POST, true);
729 curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
730 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
731 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
732 curl_setopt($curl, CURLOPT_VERBOSE, 0);
733
734 $response = curl_exec($curl);
735 curl_close($curl);
736
737 return $response;
738
739 }
740
741}