Model_apismt.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <?php
  2. class Model_Apismt extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. }
  6. public function get_ex($code) //查看支持快递
  7. {
  8. $ch = curl_init();
  9. $url = 'http://39.100.97.180/smt.php';
  10. curl_setopt($ch,CURLOPT_URL,$url);
  11. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  12. curl_setopt($ch,CURLOPT_HEADER,0);
  13. curl_setopt($ch,CURLOPT_POST, 1);
  14. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  15. //设置post数据
  16. $post = array();
  17. $post['code'] = $code;
  18. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  19. $res = curl_exec($ch);
  20. curl_close($ch);
  21. $res = json_decode($res,true);
  22. if(isset($res))
  23. {
  24. return $res;
  25. }
  26. }
  27. public function get_hq($page,$size,$starttime,$endtime,$state,$code) //获取
  28. {
  29. $ch = curl_init();
  30. //$url = 'http://39.100.97.180/start/order';
  31. $url = 'http://39.100.97.180/smt.php';
  32. curl_setopt($ch,CURLOPT_URL,$url);
  33. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  34. curl_setopt($ch,CURLOPT_HEADER,0);
  35. curl_setopt($ch,CURLOPT_POST, 1);
  36. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  37. //设置post数据
  38. $post = array();
  39. $post['order_list'] = 1;
  40. $post['starttime'] = $starttime;
  41. $post['endtime'] = $endtime;
  42. $post['page'] = $page;
  43. $post['size'] = $size;
  44. $post['state'] = $state;
  45. $post['code'] = $code;
  46. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  47. $res = curl_exec($ch);
  48. curl_close($ch);
  49. $res = json_decode($res,true);
  50. if(isset($res))
  51. {
  52. return $res;
  53. }
  54. }
  55. public function get_hqfull($page,$size,$starttime,$endtime,$state,$code) //获取
  56. {
  57. $ch = curl_init();
  58. //$url = 'http://39.100.97.180/start/orderfull';
  59. $url = 'http://39.100.97.180/smt.php';
  60. curl_setopt($ch,CURLOPT_URL,$url);
  61. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  62. curl_setopt($ch,CURLOPT_HEADER,0);
  63. curl_setopt($ch,CURLOPT_POST, 1);
  64. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  65. //设置post数据
  66. $post = array();
  67. $post['order_list_full'] = 1;
  68. $post['starttime'] = $starttime;
  69. $post['endtime'] = $endtime;
  70. $post['page'] = $page;
  71. $post['size'] = $size;
  72. $post['state'] = $state;
  73. $post['code'] = $code;
  74. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  75. $res = curl_exec($ch);
  76. //$this->logic_ding->sendToDing("速卖通获取订单详情监视列表"."【".$res."】");
  77. curl_close($ch);
  78. $res = json_decode($res,true);
  79. $data = array();$fund_status = '';
  80. if(isset($res['result']['target_list']['aeop_order_item_dto']))
  81. {
  82. foreach ($res['result']['target_list']['aeop_order_item_dto'] as $v)
  83. {
  84. if(!isset($v['fund_status']))
  85. {
  86. $fund_status = 'NOT_PAY';
  87. }
  88. if($fund_status = 'NOT_PAY' && isset($v['gmt_pay_time']))
  89. {
  90. $fund_status = 'PAY_SUCCESS';
  91. }
  92. if(isset($v['order_id']) && isset($v['order_status']) && isset($v['buyer_login_id']))
  93. {
  94. $data[] = array('orderinfo'=>$v['order_id'],'state'=>$v['order_status'],'userid'=>$v['buyer_login_id'],'fundstate'=>$fund_status);
  95. }
  96. }
  97. return $data;
  98. }
  99. }
  100. public function get_order($orderid,$code) //详情
  101. {
  102. $ch = curl_init();
  103. //$url = 'http://39.100.97.180/start/data';
  104. $url = 'http://39.100.97.180/smt.php';
  105. curl_setopt($ch,CURLOPT_URL,$url);
  106. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  107. curl_setopt($ch,CURLOPT_HEADER,0);
  108. curl_setopt($ch,CURLOPT_POST, 1);
  109. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  110. //设置post数据
  111. $post = array();
  112. $post['order_id'] = 1;
  113. $post['orderid'] = $orderid;
  114. $post['code'] = $code;
  115. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  116. $res = curl_exec($ch);
  117. curl_close($ch);
  118. //$this->logic_ding->sendToDing("速卖通获取订单详情监视订单".$orderid."【".$res."】");
  119. $res = json_decode($res,true);
  120. if(isset($res))
  121. {
  122. return $res;
  123. }
  124. }
  125. public function get_out($whlabel,$all,$orderinfo,$ex,$code) //发货声明
  126. {
  127. $ch = curl_init();
  128. //$url = 'http://39.100.97.180/start/out';
  129. $url = 'http://39.100.97.180/smt.php';
  130. curl_setopt($ch,CURLOPT_URL,$url);
  131. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  132. curl_setopt($ch,CURLOPT_HEADER,0);
  133. curl_setopt($ch,CURLOPT_POST, 1);
  134. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  135. //设置post数据
  136. $post = array();
  137. $post['order_out'] = 1;
  138. $post['whlabel'] = $whlabel;
  139. $post['all'] = $all;
  140. $post['orderinfo'] = $orderinfo;
  141. $post['ex'] = $ex;
  142. $post['code'] = $code;
  143. //$this->logic_ding->sendToDing("SMT运单同步".json_encode($post,JSON_UNESCAPED_UNICODE));
  144. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  145. $res = curl_exec($ch);
  146. $this->logic_ding->sendToDing("SMT运单同步【".$orderinfo."】".json_encode($post,JSON_UNESCAPED_UNICODE)."||".$res);
  147. curl_close($ch);
  148. $res = json_decode($res,true);
  149. if(isset($res))
  150. {
  151. return $res;
  152. }
  153. }
  154. public function get_obtain($orderinfo,$code) //查询声明
  155. {
  156. $ch = curl_init();
  157. //$url = 'http://39.100.97.180/start/obtain';
  158. $url = 'http://39.100.97.180/smt.php';
  159. curl_setopt($ch,CURLOPT_URL,$url);
  160. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  161. curl_setopt($ch,CURLOPT_HEADER,0);
  162. curl_setopt($ch,CURLOPT_POST, 1);
  163. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  164. //设置post数据
  165. $post = array();
  166. $post['statement'] = 1;
  167. $post['orderinfo'] = $orderinfo;
  168. $post['code'] = $code;
  169. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  170. $res = curl_exec($ch);
  171. curl_close($ch);
  172. $res = json_decode($res,true);
  173. if(isset($res))
  174. {
  175. return $res;
  176. }
  177. }
  178. public function get_editout($oldwhlabel,$whlabel,$all,$orderinfo,$oldex,$ex,$code) //更改声明
  179. {
  180. $ch = curl_init();
  181. //$url = 'http://39.100.97.180/start/editout';
  182. $url = 'http://39.100.97.180/smt.php';
  183. curl_setopt($ch,CURLOPT_URL,$url);
  184. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  185. curl_setopt($ch,CURLOPT_HEADER,0);
  186. curl_setopt($ch,CURLOPT_POST, 1);
  187. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  188. //设置post数据
  189. $post = array();
  190. $post['editstatement'] = 1;
  191. $post['oldwhlabel'] = $oldwhlabel;
  192. $post['whlabel'] = $whlabel;
  193. $post['all'] = $all;
  194. $post['orderinfo'] = $orderinfo;
  195. $post['oldex'] = $oldex;
  196. $post['ex'] = $ex;
  197. $post['code'] = $code;
  198. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  199. $res = curl_exec($ch);
  200. curl_close($ch);
  201. $res = json_decode($res,true);
  202. if(isset($res))
  203. {
  204. return $res;
  205. }
  206. }
  207. public function get_msg($shopid,$userid,$content,$code,$order) //发送站内信
  208. {
  209. $ch = curl_init();
  210. //$url = 'http://39.100.97.180/start/msg';
  211. $url = 'http://39.100.97.180/smt.php';
  212. curl_setopt($ch,CURLOPT_URL,$url);
  213. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  214. curl_setopt($ch,CURLOPT_HEADER,0);
  215. curl_setopt($ch,CURLOPT_POST, 1);
  216. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  217. //设置post数据
  218. $post = array();
  219. $post['shopid'] = $shopid;
  220. $post['userid'] = $userid;
  221. $post['message_type'] = 'order';
  222. $post['content'] = $content;
  223. $post['code'] = $code;
  224. $post['order'] = $order;
  225. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  226. $res = curl_exec($ch);
  227. curl_close($ch);
  228. $res = json_decode($res,true);
  229. if(isset($res))
  230. {
  231. return $res;
  232. }
  233. }
  234. public function get_commoditylist($page,$size,$code) //获取商品列表
  235. {
  236. $ch = curl_init();
  237. //$url = 'http://39.100.97.180/start/commoditylist';
  238. $url = 'http://39.100.97.180/smt.php';
  239. curl_setopt($ch,CURLOPT_URL,$url);
  240. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  241. curl_setopt($ch,CURLOPT_HEADER,0);
  242. curl_setopt($ch,CURLOPT_POST, 1);
  243. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  244. //设置post数据
  245. $post = array();
  246. $post['order_commodity_list'] = 1;
  247. $post['page'] = $page;
  248. $post['size'] = $size;//小于等于100
  249. $post['type'] = 'onSelling';//商品业务状态,目前提供5种,输入参数分别是:上架:onSelling ;下架:offline ;审核中:auditing ;审核不通过:editingRequired;客服删除:service_delete
  250. $post['code'] = $code;
  251. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  252. $res = curl_exec($ch);
  253. curl_close($ch);
  254. //$this->logic_ding->sendToDing("速卖通获取商品列表监视列表(".json_encode($post,JSON_UNESCAPED_UNICODE).")【".$res."】");
  255. $res = json_decode($res,true);
  256. if(isset($res))
  257. {
  258. return $res;
  259. }
  260. }
  261. public function get_commodityread($data,$code) //商品详情
  262. {
  263. $ch = curl_init();
  264. //$url = 'http://39.100.97.180/start/commodityread';
  265. $url = 'http://39.100.97.180/smt.php';
  266. curl_setopt($ch,CURLOPT_URL,$url);
  267. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  268. curl_setopt($ch,CURLOPT_HEADER,0);
  269. curl_setopt($ch,CURLOPT_POST, 1);
  270. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  271. //设置post数据
  272. $post = array();
  273. $post['order_commodity_read'] = 1;
  274. $post['data'] = $data;
  275. $post['code'] = $code;
  276. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  277. $res = curl_exec($ch);
  278. //$this->logic_ding->sendToDing("速卖通获取商品列表监视详情(".json_encode($post,JSON_UNESCAPED_UNICODE).")【".$res."】");
  279. curl_close($ch);
  280. $res = json_decode($res,true);
  281. $sku = array();
  282. if(isset($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']))
  283. {
  284. $gg = array();
  285. if(!isset($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku'][0]))
  286. {
  287. foreach ($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']['aeop_s_k_u_property_list']['aeop_sku_property'] as $vg)
  288. {
  289. if(isset($vg['property_value_definition_name']))
  290. {
  291. $gg[$vg['property_value_id']] = $vg['property_value_definition_name'];
  292. }
  293. }
  294. $code = isset($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']['sku_code'])?$res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']['sku_code']:'';
  295. $sku[$res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']['id']] = array('skuid'=>$res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']['id'],'code'=>$code);
  296. }
  297. else
  298. {
  299. foreach ($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku'] as $vv)
  300. {
  301. foreach ($vv['aeop_s_k_u_property_list']['aeop_sku_property'] as $vg)
  302. {
  303. if(isset($vg['property_value_definition_name']))
  304. {
  305. $gg[$vg['property_value_id']] = $vg['property_value_definition_name'];
  306. }
  307. }
  308. $code = isset($vv['sku_code'])?$vv['sku_code']:'';
  309. $sku[$vv['id']] = array('skuid'=>$vv['id'],'code'=>$code);
  310. }
  311. }
  312. $img = explode(';',$res['image_u_r_ls']);
  313. $title = '';
  314. // if(isset($res['subject_list']['subject'][14]['value']))
  315. // {
  316. // $title = $res['subject_list']['subject'][14]['value'];
  317. // }
  318. // else if(isset($res['subject_list']['subject']['locale']))
  319. // {
  320. // if($res['subject_list']['subject']['locale'] == 'en_US')
  321. // {
  322. // $title = $res['subject_list']['subject']['value'];
  323. // }
  324. // }
  325. // else
  326. // {
  327. // foreach ($res['subject_list']['subject'] as $rv)
  328. // {
  329. // if($rv['locale'] == 'en_US')
  330. // {
  331. // $title = $rv['value'];
  332. // }
  333. // }
  334. // }
  335. //不知道14是啥东西 肯定是又要求的 但是 却这样展示 目前根据需求给注释了
  336. if(isset($res['subject_list']['subject']['locale']))
  337. {
  338. if($res['subject_list']['subject']['locale'] == 'en_US')
  339. {
  340. $title = $res['subject_list']['subject']['value'];
  341. }
  342. }
  343. else
  344. {
  345. foreach ($res['subject_list']['subject'] as $rv)
  346. {
  347. if($rv['locale'] == 'en_US')
  348. {
  349. $title = $rv['value'];
  350. }
  351. }
  352. }
  353. @$mid = array('productid'=>$res['product_id'],'img'=>$img[0],'title'=>$title,'type'=>$res['product_status_type'],'cid'=>$res['category_id'],'sku'=>$sku,'gg'=>$gg);
  354. return $mid;
  355. }
  356. else
  357. {
  358. $myfile = fopen("./data/errors/txt/".$data.'-'.date('Ymd_His',time()).".txt", "w");
  359. $txt = json_encode($res);
  360. fwrite($myfile,$txt);
  361. fclose($myfile);
  362. return 1;exit;
  363. }
  364. }
  365. public function get_commoditysku($data,$code) //商品类目(sku)
  366. {
  367. $ch = curl_init();
  368. //$url = 'http://39.100.97.180/start/commoditysku';
  369. $url = 'http://39.100.97.180/smt.php';
  370. curl_setopt($ch,CURLOPT_URL,$url);
  371. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  372. curl_setopt($ch,CURLOPT_HEADER,0);
  373. curl_setopt($ch,CURLOPT_POST, 1);
  374. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  375. //设置post数据
  376. $post = array();
  377. $post['order_commodity_sku'] = 1;
  378. $post['sku'] = $data;
  379. $post['code'] = $code;
  380. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  381. $res = curl_exec($ch);
  382. curl_close($ch);
  383. $res = json_decode($res,true);
  384. if(isset($res))
  385. {
  386. return $res;
  387. }
  388. }
  389. public function get_logistics9($data,$orderinfo,$express,$al) //速卖通物流接口
  390. {
  391. $ch = curl_init();
  392. //$url = 'http://39.100.97.180/start/logistics';
  393. $url = 'http://39.100.97.180/smt.php';
  394. curl_setopt($ch,CURLOPT_URL,$url);
  395. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  396. curl_setopt($ch,CURLOPT_HEADER,0);
  397. curl_setopt($ch,CURLOPT_POST, 1);
  398. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  399. //设置post数据
  400. $post = array();
  401. $post['logistics'] = 1;
  402. $post['waybill'] = $waybill;
  403. $post['ESCROW'] = 'ESCROW';
  404. $post['orderinfo'] = $orderinfo;
  405. $post['express'] = $express;
  406. $post['al'] = $al;
  407. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  408. $res = curl_exec($ch);
  409. curl_close($ch);
  410. $res = json_decode($res,true);
  411. if(isset($res))
  412. {
  413. return $res;
  414. }
  415. }
  416. public function get_logistics($v) //阿里云云市场
  417. {
  418. $host = "https://ali-deliver.showapi.com";
  419. $path = "/showapi_expInfo";
  420. $method = "GET";
  421. $appcode = "008b9815e9fa49c49ba3a95f83f662f6";
  422. $headers = array();
  423. array_push($headers, "Authorization:APPCODE " . $appcode);
  424. $waybill = ($v['express'] == 'usps')?str_replace(array('420',$v['zipcode']),array('',''),$v['waybill']):$v['waybill'];
  425. $querys = "com=".$v['cxcode']."&nu=".$waybill;
  426. $bodys = "";
  427. $url = $host . $path . "?" . $querys;
  428. $v['exstate'] = (isset($v['exstate']))?$v['exstate']:'';//非订单查询无此属性
  429. $curl = curl_init();
  430. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  431. curl_setopt($curl, CURLOPT_URL, $url);
  432. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  433. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  434. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  435. //curl_setopt($curl, CURLOPT_HEADER, true);
  436. if (1 == strpos("$".$host, "https://"))
  437. {
  438. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  439. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  440. }
  441. $read = json_decode(curl_exec($curl),true);
  442. if(!isset($read['showapi_res_body']['status']))
  443. {
  444. $content = (isset($read['showapi_res_body']['msg']))?date('Y-m-d H',time()).'-'.$read['showapi_res_body']['msg']:date('Y-m-d H',time()).'-'.'查询失败';
  445. $list = array('content'=>$content,'f'=>0);//非正常只更改详情信息
  446. }
  447. else if($read['showapi_res_body']['status'] > 1 && $read['showapi_res_body']['status'] != $v['exstate'])
  448. {
  449. $exstate = $read['showapi_res_body']['status'];
  450. $content = $read['showapi_res_body']['data'][0]['time'].' - '.$read['showapi_res_body']['data'][0]['context'];
  451. $xq = '';
  452. foreach($read['showapi_res_body']['data'] as $v)
  453. {
  454. $xq .= $v['time'].' '.$v['context'].'<br />';
  455. }
  456. if($exstate == 2)
  457. {
  458. $exstate = 3;
  459. }
  460. else if($exstate == 3)
  461. {
  462. $exstate = 5;
  463. }
  464. else if($exstate == 4)
  465. {
  466. $exstate = 6;
  467. }
  468. else if($exstate == 9 || $exstate == 5)
  469. {
  470. $exstate = 1;
  471. }
  472. $list = array('exstate'=>$exstate,'content'=>$content,'f'=>1,'data'=>$xq);//正常可发送站内信
  473. }
  474. else
  475. {
  476. $content = (isset($read['showapi_res_body']['msg']))?date('Y-m-d H',time()).'-'.$read['showapi_res_body']['msg']:date('Y-m-d H',time()).'-'.'查询失败';
  477. $list = array('content'=>$content,'f'=>0);//非正常只更改详情信息
  478. }
  479. return $list;
  480. //status : -1 待查询 0 查询异常 1 暂无记录 2 在途中 3 派送中 4 已签收 5 用户拒签 6 疑难件 7 无效单 8 超时单 9 签收失败 10 退回
  481. }
  482. public function get_logistics1($data) //快递100
  483. {
  484. $key = 'jUQDydMC8647';//客户授权key
  485. $customer = '2C11630697BD4A3F260479649ADD9236'; //查询公司编号
  486. $param = array (
  487. 'com' => $data['express'], //快递公司编码
  488. 'num' => $data['waybill'], //快递单号
  489. 'phone' => '', //手机号
  490. 'from' => '', //出发地城市
  491. 'to' => '', //目的地城市
  492. 'resultv2' => '1' //开启行政区域解析
  493. );
  494. //请求参数
  495. $post_data = array();
  496. $post_data["customer"] = $customer;
  497. $post_data["param"] = json_encode($param);
  498. $sign = md5($post_data["param"].$key.$post_data["customer"]);
  499. $post_data["sign"] = strtoupper($sign);
  500. $url = 'http://poll.kuaidi100.com/poll/query.do'; //实时查询请求地址
  501. $params = "";
  502. foreach ($post_data as $k=>$v) {
  503. $params .= "$k=".urlencode($v)."&"; //默认UTF-8编码格式
  504. }
  505. $post_data = substr($params, 0, -1);
  506. $ch = curl_init();
  507. curl_setopt($ch, CURLOPT_POST, 1);
  508. curl_setopt($ch, CURLOPT_HEADER, 0);
  509. curl_setopt($ch, CURLOPT_URL, $url);
  510. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  511. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  512. $result = curl_exec($ch);
  513. $data = str_replace("\"", '"', $result );
  514. return json_decode($data);
  515. }
  516. //快递鸟查询快递信息开始
  517. public function get_logistics3($data){
  518. $requestData= "{'OrderCode':'','ShipperCode':'".$data['express']."','LogisticCode':'".$data['waybill']."'}";
  519. $datas = array(
  520. 'EBusinessID' => '1397054',
  521. 'RequestType' => '8001',
  522. 'RequestData' => urlencode($requestData) ,
  523. 'DataType' => '2',
  524. );
  525. $datas['DataSign']=$this->_encrypt($requestData,'34aedf94-322e-438e-b6ba-79eea59710bd');
  526. $result=$this->_sendPost('http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx',$datas);
  527. return $result;
  528. }
  529. public function _sendPost($url,$datas) {
  530. $temps = array();
  531. foreach ($datas as $key => $value) {
  532. $temps[] = sprintf('%s=%s', $key, $value);
  533. }
  534. $post_data = implode('&', $temps);
  535. $url_info = parse_url($url);
  536. if(empty($url_info['port']))
  537. {
  538. $url_info['port']=80;
  539. }
  540. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  541. $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  542. $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  543. $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  544. $httpheader.= "Connection:close\r\n\r\n";
  545. $httpheader.= $post_data;
  546. $fd = fsockopen($url_info['host'], $url_info['port']);
  547. fwrite($fd, $httpheader);
  548. $gets = "";
  549. $headerFlag = true;
  550. while (!feof($fd)) {
  551. if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  552. break;
  553. }
  554. }
  555. while (!feof($fd)) {
  556. $gets.= fread($fd, 128);
  557. }
  558. fclose($fd);
  559. return $gets;
  560. }
  561. public function _encrypt($data,$appkey) {
  562. return urlencode(base64_encode(md5($data.$appkey)));
  563. }
  564. //快递鸟查询快递信息结束
  565. } //end class