Model_apismt.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. curl_close($ch);
  147. $res = json_decode($res,true);
  148. if(isset($res))
  149. {
  150. return $res;
  151. }
  152. }
  153. public function get_obtain($orderinfo,$code) //查询声明
  154. {
  155. $ch = curl_init();
  156. //$url = 'http://39.100.97.180/start/obtain';
  157. $url = 'http://39.100.97.180/smt.php';
  158. curl_setopt($ch,CURLOPT_URL,$url);
  159. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  160. curl_setopt($ch,CURLOPT_HEADER,0);
  161. curl_setopt($ch,CURLOPT_POST, 1);
  162. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  163. //设置post数据
  164. $post = array();
  165. $post['statement'] = 1;
  166. $post['orderinfo'] = $orderinfo;
  167. $post['code'] = $code;
  168. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  169. $res = curl_exec($ch);
  170. curl_close($ch);
  171. $res = json_decode($res,true);
  172. if(isset($res))
  173. {
  174. return $res;
  175. }
  176. }
  177. public function get_editout($oldwhlabel,$whlabel,$all,$orderinfo,$oldex,$ex,$code) //更改声明
  178. {
  179. $ch = curl_init();
  180. //$url = 'http://39.100.97.180/start/editout';
  181. $url = 'http://39.100.97.180/smt.php';
  182. curl_setopt($ch,CURLOPT_URL,$url);
  183. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  184. curl_setopt($ch,CURLOPT_HEADER,0);
  185. curl_setopt($ch,CURLOPT_POST, 1);
  186. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  187. //设置post数据
  188. $post = array();
  189. $post['editstatement'] = 1;
  190. $post['oldwhlabel'] = $oldwhlabel;
  191. $post['whlabel'] = $whlabel;
  192. $post['all'] = $all;
  193. $post['orderinfo'] = $orderinfo;
  194. $post['oldex'] = $oldex;
  195. $post['ex'] = $ex;
  196. $post['code'] = $code;
  197. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  198. $res = curl_exec($ch);
  199. curl_close($ch);
  200. $res = json_decode($res,true);
  201. if(isset($res))
  202. {
  203. return $res;
  204. }
  205. }
  206. public function get_msg($shopid,$userid,$content,$code,$order) //发送站内信
  207. {
  208. $ch = curl_init();
  209. //$url = 'http://39.100.97.180/start/msg';
  210. $url = 'http://39.100.97.180/smt.php';
  211. curl_setopt($ch,CURLOPT_URL,$url);
  212. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  213. curl_setopt($ch,CURLOPT_HEADER,0);
  214. curl_setopt($ch,CURLOPT_POST, 1);
  215. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  216. //设置post数据
  217. $post = array();
  218. $post['shopid'] = $shopid;
  219. $post['userid'] = $userid;
  220. $post['message_type'] = 'order';
  221. $post['content'] = $content;
  222. $post['code'] = $code;
  223. $post['order'] = $order;
  224. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  225. $res = curl_exec($ch);
  226. curl_close($ch);
  227. $res = json_decode($res,true);
  228. if(isset($res))
  229. {
  230. return $res;
  231. }
  232. }
  233. public function get_commoditylist($page,$size,$code) //获取商品列表
  234. {
  235. $ch = curl_init();
  236. //$url = 'http://39.100.97.180/start/commoditylist';
  237. $url = 'http://39.100.97.180/smt.php';
  238. curl_setopt($ch,CURLOPT_URL,$url);
  239. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  240. curl_setopt($ch,CURLOPT_HEADER,0);
  241. curl_setopt($ch,CURLOPT_POST, 1);
  242. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  243. //设置post数据
  244. $post = array();
  245. $post['order_commodity_list'] = 1;
  246. $post['page'] = $page;
  247. $post['size'] = $size;//小于等于100
  248. $post['type'] = 'onSelling';//商品业务状态,目前提供5种,输入参数分别是:上架:onSelling ;下架:offline ;审核中:auditing ;审核不通过:editingRequired;客服删除:service_delete
  249. $post['code'] = $code;
  250. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  251. $res = curl_exec($ch);
  252. curl_close($ch);
  253. $this->logic_ding->sendToDing("速卖通获取商品列表监视列表(".json_encode($post,JSON_UNESCAPED_UNICODE).")【".$res."】");
  254. $res = json_decode($res,true);
  255. if(isset($res))
  256. {
  257. return $res;
  258. }
  259. }
  260. public function get_commodityread($data,$code) //商品详情
  261. {
  262. $ch = curl_init();
  263. //$url = 'http://39.100.97.180/start/commodityread';
  264. $url = 'http://39.100.97.180/smt.php';
  265. curl_setopt($ch,CURLOPT_URL,$url);
  266. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  267. curl_setopt($ch,CURLOPT_HEADER,0);
  268. curl_setopt($ch,CURLOPT_POST, 1);
  269. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  270. //设置post数据
  271. $post = array();
  272. $post['order_commodity_read'] = 1;
  273. $post['data'] = $data;
  274. $post['code'] = $code;
  275. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  276. $res = curl_exec($ch);
  277. $this->logic_ding->sendToDing("速卖通获取商品列表监视详情(".json_encode($post,JSON_UNESCAPED_UNICODE).")【".$res."】");
  278. curl_close($ch);
  279. $res = json_decode($res,true);
  280. $sku = array();
  281. if(isset($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']))
  282. {
  283. $gg = array();
  284. if(!isset($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku'][0]))
  285. {
  286. foreach ($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku']['aeop_s_k_u_property_list']['aeop_sku_property'] as $vg)
  287. {
  288. if(isset($vg['property_value_definition_name']))
  289. {
  290. $gg[$vg['property_value_id']] = $vg['property_value_definition_name'];
  291. }
  292. }
  293. $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']:'';
  294. $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);
  295. }
  296. else
  297. {
  298. foreach ($res['aeop_ae_product_s_k_us']['aeop_ae_product_sku'] as $vv)
  299. {
  300. foreach ($vv['aeop_s_k_u_property_list']['aeop_sku_property'] as $vg)
  301. {
  302. if(isset($vg['property_value_definition_name']))
  303. {
  304. $gg[$vg['property_value_id']] = $vg['property_value_definition_name'];
  305. }
  306. }
  307. $code = isset($vv['sku_code'])?$vv['sku_code']:'';
  308. $sku[$vv['id']] = array('skuid'=>$vv['id'],'code'=>$code);
  309. }
  310. }
  311. $img = explode(';',$res['image_u_r_ls']);
  312. $title = '';
  313. if(isset($res['subject_list']['subject'][14]['value']))
  314. {
  315. $title = $res['subject_list']['subject'][14]['value'];
  316. }
  317. else if(isset($res['subject_list']['subject']['locale']))
  318. {
  319. if($res['subject_list']['subject']['locale'] == 'en_US')
  320. {
  321. $title = $res['subject_list']['subject']['value'];
  322. }
  323. }
  324. else
  325. {
  326. foreach ($res['subject_list']['subject'] as $rv)
  327. {
  328. if($rv['locale'] == 'en_US')
  329. {
  330. $title = $rv['value'];
  331. }
  332. }
  333. }
  334. @$mid = array('productid'=>$res['product_id'],'img'=>$img[0],'title'=>$title,'type'=>$res['product_status_type'],'cid'=>$res['category_id'],'sku'=>$sku,'gg'=>$gg);
  335. return $mid;
  336. }
  337. else
  338. {
  339. $myfile = fopen("./data/errors/txt/".$data.'-'.date('Ymd_His',time()).".txt", "w");
  340. $txt = json_encode($res);
  341. fwrite($myfile,$txt);
  342. fclose($myfile);
  343. return 1;exit;
  344. }
  345. }
  346. public function get_commoditysku($data,$code) //商品类目(sku)
  347. {
  348. $ch = curl_init();
  349. //$url = 'http://39.100.97.180/start/commoditysku';
  350. $url = 'http://39.100.97.180/smt.php';
  351. curl_setopt($ch,CURLOPT_URL,$url);
  352. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  353. curl_setopt($ch,CURLOPT_HEADER,0);
  354. curl_setopt($ch,CURLOPT_POST, 1);
  355. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  356. //设置post数据
  357. $post = array();
  358. $post['order_commodity_sku'] = 1;
  359. $post['sku'] = $data;
  360. $post['code'] = $code;
  361. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  362. $res = curl_exec($ch);
  363. curl_close($ch);
  364. $res = json_decode($res,true);
  365. if(isset($res))
  366. {
  367. return $res;
  368. }
  369. }
  370. public function get_logistics9($data,$orderinfo,$express,$al) //速卖通物流接口
  371. {
  372. $ch = curl_init();
  373. //$url = 'http://39.100.97.180/start/logistics';
  374. $url = 'http://39.100.97.180/smt.php';
  375. curl_setopt($ch,CURLOPT_URL,$url);
  376. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  377. curl_setopt($ch,CURLOPT_HEADER,0);
  378. curl_setopt($ch,CURLOPT_POST, 1);
  379. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  380. //设置post数据
  381. $post = array();
  382. $post['logistics'] = 1;
  383. $post['waybill'] = $waybill;
  384. $post['ESCROW'] = 'ESCROW';
  385. $post['orderinfo'] = $orderinfo;
  386. $post['express'] = $express;
  387. $post['al'] = $al;
  388. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  389. $res = curl_exec($ch);
  390. curl_close($ch);
  391. $res = json_decode($res,true);
  392. if(isset($res))
  393. {
  394. return $res;
  395. }
  396. }
  397. public function get_logistics($v) //阿里云云市场
  398. {
  399. $host = "https://ali-deliver.showapi.com";
  400. $path = "/showapi_expInfo";
  401. $method = "GET";
  402. $appcode = "008b9815e9fa49c49ba3a95f83f662f6";
  403. $headers = array();
  404. array_push($headers, "Authorization:APPCODE " . $appcode);
  405. $waybill = ($v['express'] == 'usps')?str_replace(array('420',$v['zipcode']),array('',''),$v['waybill']):$v['waybill'];
  406. $querys = "com=".$v['cxcode']."&nu=".$waybill;
  407. $bodys = "";
  408. $url = $host . $path . "?" . $querys;
  409. $v['exstate'] = (isset($v['exstate']))?$v['exstate']:'';//非订单查询无此属性
  410. $curl = curl_init();
  411. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  412. curl_setopt($curl, CURLOPT_URL, $url);
  413. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  414. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  415. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  416. //curl_setopt($curl, CURLOPT_HEADER, true);
  417. if (1 == strpos("$".$host, "https://"))
  418. {
  419. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  420. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  421. }
  422. $read = json_decode(curl_exec($curl),true);
  423. if(!isset($read['showapi_res_body']['status']))
  424. {
  425. $content = (isset($read['showapi_res_body']['msg']))?date('Y-m-d H',time()).'-'.$read['showapi_res_body']['msg']:date('Y-m-d H',time()).'-'.'查询失败';
  426. $list = array('content'=>$content,'f'=>0);//非正常只更改详情信息
  427. }
  428. else if($read['showapi_res_body']['status'] > 1 && $read['showapi_res_body']['status'] != $v['exstate'])
  429. {
  430. $exstate = $read['showapi_res_body']['status'];
  431. $content = $read['showapi_res_body']['data'][0]['time'].' - '.$read['showapi_res_body']['data'][0]['context'];
  432. $xq = '';
  433. foreach($read['showapi_res_body']['data'] as $v)
  434. {
  435. $xq .= $v['time'].' '.$v['context'].'<br />';
  436. }
  437. if($exstate == 2)
  438. {
  439. $exstate = 3;
  440. }
  441. else if($exstate == 3)
  442. {
  443. $exstate = 5;
  444. }
  445. else if($exstate == 4)
  446. {
  447. $exstate = 6;
  448. }
  449. else if($exstate == 9 || $exstate == 5)
  450. {
  451. $exstate = 1;
  452. }
  453. $list = array('exstate'=>$exstate,'content'=>$content,'f'=>1,'data'=>$xq);//正常可发送站内信
  454. }
  455. else
  456. {
  457. $content = (isset($read['showapi_res_body']['msg']))?date('Y-m-d H',time()).'-'.$read['showapi_res_body']['msg']:date('Y-m-d H',time()).'-'.'查询失败';
  458. $list = array('content'=>$content,'f'=>0);//非正常只更改详情信息
  459. }
  460. return $list;
  461. //status : -1 待查询 0 查询异常 1 暂无记录 2 在途中 3 派送中 4 已签收 5 用户拒签 6 疑难件 7 无效单 8 超时单 9 签收失败 10 退回
  462. }
  463. public function get_logistics1($data) //快递100
  464. {
  465. $key = 'jUQDydMC8647';//客户授权key
  466. $customer = '2C11630697BD4A3F260479649ADD9236'; //查询公司编号
  467. $param = array (
  468. 'com' => $data['express'], //快递公司编码
  469. 'num' => $data['waybill'], //快递单号
  470. 'phone' => '', //手机号
  471. 'from' => '', //出发地城市
  472. 'to' => '', //目的地城市
  473. 'resultv2' => '1' //开启行政区域解析
  474. );
  475. //请求参数
  476. $post_data = array();
  477. $post_data["customer"] = $customer;
  478. $post_data["param"] = json_encode($param);
  479. $sign = md5($post_data["param"].$key.$post_data["customer"]);
  480. $post_data["sign"] = strtoupper($sign);
  481. $url = 'http://poll.kuaidi100.com/poll/query.do'; //实时查询请求地址
  482. $params = "";
  483. foreach ($post_data as $k=>$v) {
  484. $params .= "$k=".urlencode($v)."&"; //默认UTF-8编码格式
  485. }
  486. $post_data = substr($params, 0, -1);
  487. $ch = curl_init();
  488. curl_setopt($ch, CURLOPT_POST, 1);
  489. curl_setopt($ch, CURLOPT_HEADER, 0);
  490. curl_setopt($ch, CURLOPT_URL, $url);
  491. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  492. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  493. $result = curl_exec($ch);
  494. $data = str_replace("\"", '"', $result );
  495. return json_decode($data);
  496. }
  497. //快递鸟查询快递信息开始
  498. public function get_logistics3($data){
  499. $requestData= "{'OrderCode':'','ShipperCode':'".$data['express']."','LogisticCode':'".$data['waybill']."'}";
  500. $datas = array(
  501. 'EBusinessID' => '1397054',
  502. 'RequestType' => '8001',
  503. 'RequestData' => urlencode($requestData) ,
  504. 'DataType' => '2',
  505. );
  506. $datas['DataSign']=$this->_encrypt($requestData,'34aedf94-322e-438e-b6ba-79eea59710bd');
  507. $result=$this->_sendPost('http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx',$datas);
  508. return $result;
  509. }
  510. public function _sendPost($url,$datas) {
  511. $temps = array();
  512. foreach ($datas as $key => $value) {
  513. $temps[] = sprintf('%s=%s', $key, $value);
  514. }
  515. $post_data = implode('&', $temps);
  516. $url_info = parse_url($url);
  517. if(empty($url_info['port']))
  518. {
  519. $url_info['port']=80;
  520. }
  521. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  522. $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  523. $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  524. $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  525. $httpheader.= "Connection:close\r\n\r\n";
  526. $httpheader.= $post_data;
  527. $fd = fsockopen($url_info['host'], $url_info['port']);
  528. fwrite($fd, $httpheader);
  529. $gets = "";
  530. $headerFlag = true;
  531. while (!feof($fd)) {
  532. if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  533. break;
  534. }
  535. }
  536. while (!feof($fd)) {
  537. $gets.= fread($fd, 128);
  538. }
  539. fclose($fd);
  540. return $gets;
  541. }
  542. public function _encrypt($data,$appkey) {
  543. return urlencode(base64_encode(md5($data.$appkey)));
  544. }
  545. //快递鸟查询快递信息结束
  546. } //end class