Model_kdniao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class Model_Kdniao extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. }
  6. public function order($data)
  7. {
  8. $requestData="{'OrderCode': '".$data['orderinfo']."',".
  9. "'ShipperCode':'".$data['express']."',".
  10. "'LogisticCode':'".$data['waybill']."',".
  11. "'PayType':1,".
  12. "'Sender':".
  13. "{".
  14. "'Name':'".$data['warehouse']['company']."','Mobile':'".$data['warehouse']['phone']."','ProvinceName':'".$data['warehouse']['province']."','CityName':'".$data['warehouse']['city']."','ExpAreaName':'".$data['warehouse']['address2']."','Address':'".$data['warehouse']['address']."'},".
  15. "'Receiver':".
  16. "{".
  17. "'Name':'".$data['name']."','Mobile':'".$data['phone']."','ProvinceName':'".$data['province']."','CityName':'".$data['city']."','ExpAreaName':'".$data['street']."','Address':'".$data['address']."'},".
  18. "}";
  19. $datas = array(
  20. 'EBusinessID' => '1397054',
  21. 'RequestType' => '1008',
  22. 'RequestData' => urlencode($requestData) ,
  23. 'DataType' => '2',
  24. );
  25. $datas['DataSign'] = $this->encrypt($requestData,'34aedf94-322e-438e-b6ba-79eea59710bd');
  26. $result = $this->sendPost('http://testapi.kdniao.com:8081/api/dist', $datas);//http://api.kdniao.com/api/dist
  27. $result = json_decode($result,true);
  28. return $result['Success'];//有Success 并且是1 成功订阅
  29. }
  30. public function sendPost($url, $datas)
  31. {
  32. $temps = array();
  33. foreach ($datas as $key => $value)
  34. {
  35. $temps[] = sprintf('%s=%s', $key, $value);
  36. }
  37. $post_data = implode('&', $temps);
  38. $url_info = parse_url($url);
  39. if(empty($url_info['port']))
  40. {
  41. $url_info['port']=80;
  42. }
  43. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  44. $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  45. $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  46. $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  47. $httpheader.= "Connection:close\r\n\r\n";
  48. $httpheader.= $post_data;
  49. $fd = fsockopen($url_info['host'], $url_info['port']);
  50. fwrite($fd, $httpheader);
  51. $gets = "";
  52. $headerFlag = true;
  53. while (!feof($fd))
  54. {
  55. if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n"))
  56. {
  57. break;
  58. }
  59. }
  60. while (!feof($fd))
  61. {
  62. $gets.= fread($fd, 128);
  63. }
  64. fclose($fd);
  65. return $gets;
  66. }
  67. public function encrypt($data, $appkey)
  68. {
  69. return urlencode(base64_encode(md5($data.$appkey)));
  70. }
  71. } //end class