电商Sign署名天生
@param data 内容
@param appkey Appkey
@return DataSign署名
/
public function encrypt($data, $appkey) {
return urlencode(base64_encode(md5($data.$appkey)));
}
/
post提交数据
@param string $url 要求Url
@param array $datas 提交的数据
@return url相应返回的html
/
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;
}
/
Json办法 物流信息订阅
/
public function orderTracesSubByJson(){
$requestData=\"大众{'OrderCode': '$orderSn',\公众.
\"大众'ShipperCode':'$ShipperCode',\公众.
\"大众'LogisticCode':'$LogisticCode',\"大众.
\"大众}\"大众;
$AppKey = \"大众249b6-03b-db8-964-36ab2ae\"大众;
$ReqURL ='http://api.kdniao.com/api/dist';
$datas = array(
'EBusinessID' => '1419',
'RequestType' => '8001',
'RequestData' => urlencode($requestData) ,
'DataType' => '2',
);
$datas['DataSign'] = $this->encrypt($requestData, $AppKey);
$result=$this->sendPost($ReqURL, $datas);
//根据公司业务处理返回的信息......
return $result;
}