| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | 
							- <?php
 
- class Model_Kdniao extends Lin_Model {
 
- function __construct(){
 
- 		parent::__construct();
 
- }
 
- 	public function order($data)
 
- 	{
 
- 	    $requestData="{'OrderCode': '".$data['orderinfo']."',".
 
- 			  	     "'ShipperCode':'".$data['express']."',".
 
- 			   		 "'LogisticCode':'".$data['waybill']."',".
 
- 			   		 "'PayType':1,".
 
- 			   		 "'Sender':".
 
- 			   		 "{".
 
- 			  		 "'Name':'".$data['warehouse']['company']."','Mobile':'".$data['warehouse']['phone']."','ProvinceName':'".$data['warehouse']['province']."','CityName':'".$data['warehouse']['city']."','ExpAreaName':'".$data['warehouse']['address2']."','Address':'".$data['warehouse']['address']."'},".
 
- 			  		 "'Receiver':".
 
- 			   		 "{".
 
- 			  		 "'Name':'".$data['name']."','Mobile':'".$data['phone']."','ProvinceName':'".$data['province']."','CityName':'".$data['city']."','ExpAreaName':'".$data['street']."','Address':'".$data['address']."'},".
 
- 			   		 "}";
 
- 		$datas = array(
 
-         'EBusinessID' => '1397054',
 
-         'RequestType' => '1008',
 
-         'RequestData' => urlencode($requestData) ,
 
-         'DataType' => '2',
 
-    		);
 
-         $datas['DataSign'] = $this->encrypt($requestData,'34aedf94-322e-438e-b6ba-79eea59710bd');
 
- 	    $result = $this->sendPost('http://testapi.kdniao.com:8081/api/dist', $datas);//http://api.kdniao.com/api/dist
 
- 	    $result = json_decode($result,true);
 
- 	    return $result['Success'];//有Success 并且是1 成功订阅
 
-     }
 
- 	public function sendPost($url, $datas) 
 
- 	{
 
-         $temps = array();	
 
-         foreach ($datas as $key => $value) 
 
- 		{
 
-             $temps[] = sprintf('%s=%s', $key, $value);		
 
-         }	
 
-         $post_data = implode('&', $temps);
 
-         $url_info = parse_url($url);
 
- 	    if(empty($url_info['port']))
 
- 	    {
 
- 	    	$url_info['port']=80;	
 
- 	    }
 
-         $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
 
-         $httpheader.= "Host:" . $url_info['host'] . "\r\n";
 
-         $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
 
-         $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
 
-         $httpheader.= "Connection:close\r\n\r\n";
 
-         $httpheader.= $post_data;
 
-         $fd = fsockopen($url_info['host'], $url_info['port']);
 
-         fwrite($fd, $httpheader);
 
-         $gets = "";
 
- 	    $headerFlag = true;
 
- 	    while (!feof($fd)) 
 
- 		{
 
- 		    if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) 
 
- 		    {
 
- 		    	break;
 
- 		    }
 
- 	    }
 
-         while (!feof($fd)) 
 
- 		{
 
- 		    $gets.= fread($fd, 128);
 
-         }
 
-         fclose($fd);  
 
-         return $gets;
 
-     }
 
- 	public function encrypt($data, $appkey) 
 
- 	{
 
-         return urlencode(base64_encode(md5($data.$appkey)));
 
-     }
 
- }  //end class
 
 
  |