Ga.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Ga extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_shop','shop');
  7. }
  8. public function _remap($arg,$arg_array)
  9. {
  10. if($arg=="contentpage"){
  11. $this->$arg();
  12. }elseif($arg=="trafficsource"){
  13. $this->$arg();
  14. }elseif($arg=="chart"){
  15. $this->$arg();
  16. }elseif($arg=="productinfo"){
  17. $this->$arg($arg_array);
  18. }elseif($arg=="regionproduct"){
  19. $this->$arg($arg_array);
  20. }elseif($arg=="goals"){
  21. $this->$arg();
  22. }else{
  23. $this->_index();
  24. }
  25. }
  26. public function _index(){
  27. $url="http://getdata.mywigs.com/index/index";
  28. if(isset($_SESSION['api']))
  29. {
  30. $user = $this->user->get_api($_SESSION['api']);
  31. $usp = $user;
  32. $fgshop = "";$sid = "";
  33. $usersp = explode('|',trim($user['shop'],'|'));
  34. foreach ($usersp as $value)
  35. {
  36. $fgshop .= " shop = ".$value." or";
  37. $sid .= " id = ".$value." or";
  38. }
  39. if($user['vip'] == 1)
  40. {
  41. $vip = 1;
  42. }
  43. else
  44. {
  45. $vip = 0;
  46. }
  47. }
  48. else
  49. {
  50. $vip = 0;
  51. }
  52. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  53. $this->data['wlshop'] = $wlshop;
  54. $post = $this->input->post(NULL, TRUE);
  55. $shop = $this->input->post('shop', TRUE);
  56. if(!$shop){
  57. $shop=$wlshop[0];
  58. }
  59. $this->data['shop'] = $shop;
  60. if(isset($post['shop'])) {
  61. $param=[];
  62. $days=intval($post['days']);
  63. if($shop>6){
  64. echo json_encode(array('msg'=>'无权限或者店铺不存在','success'=>false));exit;
  65. }
  66. $param['store']=$shop;
  67. $param['start']=date('Y-m-d',time()-3600*24*$days);
  68. $param['end']=date('Y-m-d',time());
  69. $url=$url.'?'.http_build_query($param);
  70. $data=$this->_curl([],$url,300,"GET");
  71. $data=json_decode($data,true);
  72. $last_data_url=$url.http_build_query([
  73. 'store'=>$shop,
  74. 'start'=>date('Y-m-d',time()-3600*24*$days*2),
  75. 'end'=>date('Y-m-d',time()-3600*24*$days),
  76. ]);
  77. $last_data=$this->_curl([],$last_data_url,300,"GET");
  78. $last_data=json_decode($last_data,true);
  79. if(!$data['status']||!$last_data['status']){
  80. echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  81. }else{
  82. $data=$data['data'];
  83. $last_data=$last_data['data'];
  84. $users=[];
  85. $visitor=$data['visitor'];
  86. $geo=$data['geo'];
  87. foreach($visitor as $k=>$v){
  88. if($v['userType']=="New Visitor"){
  89. $users['new'][]=$v['newUsers'];
  90. $users['date'][]=date('Y-m-d',strtotime($v['date']));
  91. }else{
  92. $users['return'][]=$v['users'];
  93. }
  94. }
  95. $totalSellCount=array_sum(array_column($geo,'transactions'));
  96. $regionStr="";
  97. foreach($geo as $k=>$v){
  98. $percent=round($v['transactions']/$totalSellCount*100,2)."%";
  99. $geo[$k]['percent']=$percent;
  100. }
  101. $sell=[];
  102. $sell['date']['hour']=array_column($data['sell']['hour'],'dateHour');
  103. $sell['date']['day']=array_column($data['sell']['day'],'date');
  104. $sell['date']['week']=array_column($data['sell']['week'],'isoYearIsoWeek');
  105. $sell['date']['month']=array_column($data['sell']['month'],'yearMonth');
  106. $sell['date']['hour']=array_map(function($item){
  107. return date('m/d H',strtotime($item."00")).":00";
  108. },$sell['date']['hour']);
  109. $sell['date']['day']=array_map(function($item){
  110. return date('m/d',strtotime($item));
  111. },$sell['date']['day']);
  112. $sell['date']['week']=array_map(function($item){
  113. return date('Y/W',strtotime(substr_replace($item,"W",-2,0)));
  114. },$sell['date']['week']);
  115. $sell['date']['month']=array_map(function($item){
  116. return date('Y/m',strtotime($item));
  117. },$sell['date']['month']);
  118. foreach($data['sell'] as $k=>$v){
  119. foreach($v as $item){
  120. if(isset($item['date'])&&!empty($item['date'])){
  121. $date=date('m/d',strtotime($item['date']));
  122. }
  123. if(isset($item['dateHour'])&&!empty($item['dateHour'])){
  124. $date=date('m/d H',strtotime($item['dateHour']."00")).":00";
  125. }
  126. if(isset($item['yearMonth'])&&!empty($item['yearMonth'])){
  127. $date=date('Y-m',strtotime($item['yearMonth']));
  128. }
  129. if(isset($item['isoYearIsoWeek'])&&!empty($item['isoYearIsoWeek'])){
  130. $date=date('Y/W',strtotime(substr_replace($item['isoYearIsoWeek'],"W",-2,0)));
  131. }
  132. $item['date']=$date;
  133. // $date=$item['date']??($item['dateHour']??($item['yearWeek']??$item['yearMonth']));
  134. $sell['data'][$k][$date]=$item;
  135. }
  136. }
  137. foreach($last_data['sell'] as $k=>$v){
  138. foreach($v as $item){
  139. $last_sell[$k][]=$item['itemQuantity'];
  140. }
  141. }
  142. $data['store']['广告-销量']=0;
  143. $data['store']['广告-订单数']=0;
  144. $data['store']['广告-收入']=0;
  145. $data['store']['广告-点击次数']=0;
  146. $data['store']['广告-成本']=0;
  147. foreach($data['ads'] as $k=>$v){
  148. if($v['campaign']=="(not set)"){
  149. continue;
  150. }
  151. $data['store']['广告-销量'] +=$v['itemQuantity'];
  152. $data['store']['广告-订单数'] +=$v['transactions'];
  153. $data['store']['广告-收入'] +=$v['transactionRevenue'];
  154. $data['store']['广告-点击次数'] +=$v['adClicks'];
  155. $data['store']['广告-成本'] +=$v['adCost'];
  156. }
  157. $data['store']['广告-收入']=round($data['store']['广告-收入'],2);
  158. $data['store']['广告-成本']=round($data['store']['广告-成本'],2);
  159. $page=array_slice($data['page'],0,99);
  160. foreach($page as $k=>$v){
  161. $page[$k]['pageValue']=round($v['pageValue'],2);
  162. }
  163. $rows=array(
  164. 'success'=>1,
  165. 'data'=>[
  166. 'users'=>$users,
  167. 'geo'=>$geo,
  168. 'product'=>$data['product'],
  169. 'ads'=>$data['ads'],
  170. 'sell'=>$sell,
  171. 'last_sell'=>$last_sell,
  172. 'store'=>$data['store'],
  173. 'page'=>$page,
  174. 'channel'=>$data['channel']
  175. ]
  176. );
  177. echo json_encode($rows);exit;
  178. }
  179. }
  180. $this->_Template('ga_index',$this->data);
  181. }
  182. public function getStoreData(){
  183. $base_url="http://getdata.mywigs.com/index/index";
  184. $post = $this->input->post(NULL, TRUE);
  185. // $shop=$post['store'];
  186. // $days=intval($post['days']);
  187. $shop=3;
  188. $days=15;
  189. $param['store']=$shop;
  190. $param['start']=date('Y-m-d',time()-3600*24*$days);
  191. $param['end']=date('Y-m-d',time());
  192. $url=$base_url.'?'.http_build_query($param);
  193. $data=$this->_curl([],$url,300,"GET");
  194. $data=json_decode($data,true);
  195. $param1['store']=$shop;
  196. $param1['start']=date('Y-m-d',time()-3600*24*($days*2+1));
  197. $param1['end']=date('Y-m-d',time()-3600*24*($days+1));
  198. $url=$base_url.'?'.http_build_query($param1);
  199. $last_data=$this->_curl([],$url,300,"GET");
  200. $last_data=json_decode($last_data,true);
  201. if(!$data['status']||!$last_data['status']){
  202. echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  203. }else{
  204. $storeData=$data['data']['storeData'];
  205. $lastStoreData=$last_data['data']['storeData'];
  206. echo "<pre>";
  207. print_r($storeData);exit;
  208. $res=[
  209. [
  210. 'name'=>'销量',
  211. 'value'=>$storeData['transactions'],
  212. // 'compare'=>round(($storeData['transactions']-$lastStoreData['transactions'])/$lastStoreData['transactions']*100,2)."%",
  213. 'compare'=>round(($lastStoreData['transactions']-$storeData['transactions'])/$lastStoreData['transactions']*100,2)."%",
  214. ],
  215. // [
  216. // 'name'=>
  217. // ]
  218. ];
  219. echo json_encode($res);
  220. exit;
  221. }
  222. }
  223. public function contentpage(){
  224. $url="http://getdata.mywigs.com/index/contentpage";
  225. $post = $this->input->post(NULL, TRUE);
  226. if(isset($post['page'])) {
  227. $page = $this->input->post('page',true);
  228. $perpage = $this->input->post('perpage',true);
  229. if(empty($page))
  230. {
  231. $start = 0;
  232. $perpage = 1;
  233. }
  234. else
  235. {
  236. $start = ($page - 1)*$perpage;
  237. }
  238. $param=[];
  239. $param['limit']=$perpage;
  240. $param['page']=$page;
  241. $url=$url.'?'.http_build_query($param);
  242. $data=$this->_curl([],$url,300,"GET");
  243. $data=json_decode($data,true);
  244. if(!$data['status']){
  245. echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  246. }else{
  247. $data=$data['data'];
  248. $total=$data['total'];
  249. $items=$data['items'];
  250. foreach($items as $k=>$v){
  251. $items[$k]['avgTimeOnPage']=round($items[$k]['avgTimeOnPage'],2);
  252. $items[$k]['bounceRate']=round($items[$k]['bounceRate'],2);
  253. $items[$k]['exitRate']=round($items[$k]['exitRate'],2);
  254. $items[$k]['pageValue']=round($items[$k]['pageValue'],2);
  255. unset($items[$k]['created_at']);
  256. }
  257. $pagenum = ceil($total/$perpage);
  258. $over = $total-($start+$perpage);
  259. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($items));
  260. echo json_encode($rows);exit;
  261. }
  262. }
  263. $this->_Template('ga_contentpage',$this->data);
  264. }
  265. // public function Trafficsource(){
  266. // $url="http://getdata.mywigs.com/index/source";
  267. // $post = $this->input->post(NULL, TRUE);
  268. // if(isset($post['page'])) {
  269. // $page = $this->input->post('page',true);
  270. // $perpage = $this->input->post('perpage',true);
  271. // if(empty($page))
  272. // {
  273. // $start = 0;
  274. // $perpage = 1;
  275. // }
  276. // else
  277. // {
  278. // $start = ($page - 1)*$perpage;
  279. // }
  280. // $param=[];
  281. // $param['limit']=$perpage;
  282. // $param['page']=$page;
  283. // $url=$url.'?'.http_build_query($param);
  284. // $data=$this->_curl([],$url,300,"GET");
  285. // $data=json_decode($data,true);
  286. // if(!$data['status']){
  287. // echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  288. // }else{
  289. // $data=$data['data'];
  290. // $total=$data['total'];
  291. // $items=$data['items'];
  292. // foreach($items as $k=>$v){
  293. // $items[$k]['pageviewsPerSession']=round($items[$k]['pageviewsPerSession'],2);
  294. // $items[$k]['bounceRate']=round($items[$k]['bounceRate'],2);
  295. // $items[$k]['avgSessionDuration']=round($items[$k]['avgSessionDuration'],2);
  296. // $items[$k]['transactionsPerVisit']=round($items[$k]['transactionsPerVisit'],2);
  297. // unset($items[$k]['created_at']);
  298. // }
  299. // $pagenum = ceil($total/$perpage);
  300. // $over = $total-($start+$perpage);
  301. // $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($items));
  302. // echo json_encode($rows);exit;
  303. // }
  304. // }
  305. // $this->_Template('ga_trafficsource',$this->data);
  306. // }
  307. public function Trafficsource(){
  308. $url="http://getdata.mywigs.com/index/statistic";
  309. if(isset($_SESSION['api']))
  310. {
  311. $user = $this->user->get_api($_SESSION['api']);
  312. $usp = $user;
  313. $fgshop = "";$sid = "";
  314. $usersp = explode('|',trim($user['shop'],'|'));
  315. foreach ($usersp as $value)
  316. {
  317. $fgshop .= " shop = ".$value." or";
  318. $sid .= " id = ".$value." or";
  319. }
  320. if($user['vip'] == 1)
  321. {
  322. $vip = 1;
  323. }
  324. else
  325. {
  326. $vip = 0;
  327. }
  328. }
  329. else
  330. {
  331. $vip = 0;
  332. }
  333. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  334. $this->data['wlshop'] = $wlshop;
  335. $post = $this->input->post(NULL, TRUE);
  336. $shop = $this->input->post('shop', TRUE);
  337. if(!$shop){
  338. $shop=$wlshop[0];
  339. }
  340. $this->data['shop'] = $shop;
  341. if(isset($post['shop'])) {
  342. $param=[];
  343. $days=intval($post['days']);
  344. if($shop>6){
  345. echo json_encode(array('msg'=>'无权限或者店铺不存在','success'=>false));exit;
  346. }
  347. $param['store']=$shop;
  348. $param['start']=date('Y-m-d',time()-3600*24*$days);
  349. $param['end']=date('Y-m-d',time());
  350. $url=$url.'?'.http_build_query($param);
  351. $data=$this->_curl([],$url,300,"GET");
  352. $data=json_decode($data,true);
  353. if(!$data['status']){
  354. echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  355. }else{
  356. $data=$data['data'];
  357. $users=[];
  358. $visitor=$data['visitor'];
  359. $sell=$data['sell'];
  360. foreach($visitor as $k=>$v){
  361. if($v['userType']=="New Visitor"){
  362. $users['new'][]=$v['newUsers'];
  363. $users['date'][]=date('Y-m-d',strtotime($v['date']));
  364. }else{
  365. $users['return'][]=$v['users'];
  366. }
  367. }
  368. $totalSellCount=array_sum(array_column($sell,'transactions'));
  369. // echo $totalSellCount;exit;
  370. $regionStr="";
  371. foreach($sell as $k=>$v){
  372. $percent=round($v['transactions']/$totalSellCount*100,2)."%";
  373. $sell[$k]['percent']=$percent;
  374. }
  375. $rows=array(
  376. 'success'=>1,
  377. 'data'=>[
  378. 'users'=>$users,
  379. 'sell'=>$sell,
  380. 'product'=>$data['product'],
  381. ]
  382. );
  383. echo json_encode($rows);exit;
  384. }
  385. }
  386. $this->_Template('ga_chart',$this->data);
  387. }
  388. public function productinfo($arg_array=[]){
  389. $url="http://getdata.mywigs.com/index/productinfo";
  390. $shop=$arg_array[0];
  391. $days=intval($arg_array[1])??7;
  392. $productName=base64_decode($arg_array[2]);
  393. if(isset($productName)&&!empty($productName)) {
  394. $param=[];
  395. $param['store']=$shop;
  396. $param['productName']=$productName;
  397. $param['start']=date('Y-m-d',time()-3600*24*$days);
  398. $param['end']=date('Y-m-d',time());
  399. $url=$url.'?'.http_build_query($param);
  400. $data=$this->_curl([],$url,300,"GET");
  401. $data=json_decode($data,true);
  402. if(!$data['status']){
  403. echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  404. }else{
  405. $data=$data['data'];
  406. $sell=[];
  407. $sell['date']['hour']=array_column($data['sell']['hour'],'dateHour');
  408. $sell['date']['day']=array_column($data['sell']['day'],'date');
  409. $sell['date']['week']=array_column($data['sell']['week'],'isoYearIsoWeek');
  410. $sell['date']['month']=array_column($data['sell']['month'],'yearMonth');
  411. $sell['date']['hour']=array_map(function($item){
  412. return date('m/d H',strtotime($item."00")).":00";
  413. },$sell['date']['hour']);
  414. $sell['date']['day']=array_map(function($item){
  415. return date('m/d',strtotime($item));
  416. },$sell['date']['day']);
  417. $sell['date']['week']=array_map(function($item){
  418. return date('Y/W',strtotime(substr_replace($item,"W",-2,0)));
  419. },$sell['date']['week']);
  420. $sell['date']['month']=array_map(function($item){
  421. return date('Y/m',strtotime($item));
  422. },$sell['date']['month']);
  423. // echo "<pre>";
  424. // print_r($data['sell']['week']);
  425. foreach($data['sell'] as $k=>$v){
  426. foreach($v as $item){
  427. if(isset($item['date'])&&!empty($item['date'])){
  428. $date=date('m/d',strtotime($item['date']));
  429. }
  430. if(isset($item['dateHour'])&&!empty($item['dateHour'])){
  431. $date=date('m/d H',strtotime($item['dateHour']."00")).":00";
  432. }
  433. if(isset($item['yearMonth'])&&!empty($item['yearMonth'])){
  434. $date=date('Y-m',strtotime($item['yearMonth']));
  435. }
  436. if(isset($item['isoYearIsoWeek'])&&!empty($item['isoYearIsoWeek'])){
  437. $date=date('Y/W',strtotime(substr_replace($item['isoYearIsoWeek'],"W",-2,0)));
  438. }
  439. $item['date']=$date;
  440. // $date=$item['date']??($item['dateHour']??($item['yearWeek']??$item['yearMonth']));
  441. $sell['data'][$k][$date]=$item;
  442. }
  443. }
  444. }
  445. // echo "<pre>";
  446. // print_r($sell);exit;
  447. $this->data['sell']=json_encode($sell,true);
  448. $this->data['sku']=json_encode($data['sku'],true);
  449. $this->data['days']=$days;
  450. }
  451. $this->data['productName']=$productName;
  452. $this->_Template('ga_productinfo',$this->data);
  453. }
  454. public function regionproduct($arg_array=[]){
  455. $url="http://getdata.mywigs.com/index/region-product";
  456. $shop=$arg_array[0];
  457. $days=intval($arg_array[1])??7;
  458. $region=base64_decode($arg_array[2]);
  459. if(isset($region)&&!empty($region)) {
  460. $param=[];
  461. $param['store']=$shop;
  462. $param['region']=$region;
  463. $param['start']=date('Y-m-d',time()-3600*24*$days);
  464. $param['end']=date('Y-m-d',time());
  465. $url=$url.'?'.http_build_query($param);
  466. $data=$this->_curl([],$url,300,"GET");
  467. $data=json_decode($data,true);
  468. if(!$data['status']){
  469. echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  470. }else{
  471. $data=$data['data'];
  472. }
  473. $this->data['info']=$data[0];
  474. }
  475. $this->_Template('ga_productinfo',$this->data);
  476. }
  477. public function goals(){
  478. $url="http://getdata.mywigs.com/index/goals";
  479. if(isset($_SESSION['api']))
  480. {
  481. $user = $this->user->get_api($_SESSION['api']);
  482. $usp = $user;
  483. $fgshop = "";$sid = "";
  484. $usersp = explode('|',trim($user['shop'],'|'));
  485. foreach ($usersp as $value)
  486. {
  487. $fgshop .= " shop = ".$value." or";
  488. $sid .= " id = ".$value." or";
  489. }
  490. if($user['vip'] == 1)
  491. {
  492. $vip = 1;
  493. }
  494. else
  495. {
  496. $vip = 0;
  497. }
  498. }
  499. else
  500. {
  501. $vip = 0;
  502. }
  503. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  504. $this->data['wlshop'] = $wlshop;
  505. $post = $this->input->post(NULL, TRUE);
  506. $shop = $this->input->post('shop', TRUE);
  507. if(!$shop){
  508. $shop=$wlshop[0];
  509. }
  510. $this->data['shop'] = $shop;
  511. if(isset($post['page'])) {
  512. $param=[];
  513. $timetk = $this->input->post('timetk',true);
  514. $timetj = $this->input->post('timetj',true);
  515. // $days=intval($post['days']);
  516. if($shop>6){
  517. echo json_encode(array('msg'=>'无权限或者店铺不存在','success'=>false));exit;
  518. }
  519. $param['store']=$shop;
  520. $param['start']=date('Y-m-d',strtotime($timetk));
  521. $param['end']=date('Y-m-d',strtotime($timetj));
  522. $url=$url.'?'.http_build_query($param);
  523. $data=$this->_curl([],$url,300,"GET");
  524. $data=json_decode($data,true);
  525. if(!$data['status']){
  526. echo json_encode(array('msg'=>'获取失败,请重试','success'=>false));exit;
  527. }else{
  528. $data=$data['data'];
  529. // foreach($sell as $k=>$v){
  530. // $percent=round($v['transactions']/$totalSellCount*100,2)."%";
  531. // $sell[$k]['percent']=$percent;
  532. // }
  533. $row=[
  534. $data['pageviews'],
  535. $data['sessions'],
  536. $data['users'],
  537. $data['newUsers'],
  538. round($data['bounceRate'],2).'%',
  539. $data['cartCompletions'],
  540. round($data['cartConversionRate'],2).'%',
  541. $data['orderCompletions'],
  542. round($data['orderConversionRate'],2).'%',
  543. $data['transactionRevenue'],
  544. round($data['revenuePerTransaction'],2),
  545. ];
  546. $rows = array('rows'=>[$row]);
  547. echo json_encode($rows);exit;
  548. }
  549. }
  550. $this->_Template('ga_goals',$this->data);
  551. }
  552. public function _curl($data,$url,$timeout=300,$httptype="POST",$date_type=false,$header=array(),$userpwd='')
  553. {
  554. if ($date_type == 'http_build_query')
  555. {
  556. $data = http_build_query($data);
  557. }
  558. else if ($date_type == 'json')
  559. {
  560. $data = json_encode($data);
  561. }
  562. $ch = curl_init();
  563. curl_setopt($ch, CURLOPT_URL, $url);
  564. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  565. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  566. curl_setopt($ch, CURLOPT_HEADER, false);
  567. switch ($httptype)
  568. {
  569. case "GET":
  570. curl_setopt($ch, CURLOPT_HTTPGET, true);
  571. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  572. break;
  573. case "POST":
  574. curl_setopt($ch, CURLOPT_POST, true);
  575. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  576. break;
  577. case "PUT":
  578. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  579. break;
  580. case "DELETE":
  581. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  582. break;
  583. }
  584. $isSecure = strpos($url, "https://");
  585. if ($isSecure === 0)
  586. {
  587. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  588. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  589. }
  590. if(!empty($header))
  591. {
  592. curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
  593. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  594. }
  595. if(!empty($userpwd))
  596. {
  597. curl_setopt($ch,CURLOPT_USERPWD,$userpwd);
  598. }
  599. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  600. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  601. $result = curl_exec($ch);
  602. curl_close($ch);
  603. return $result;
  604. }
  605. }