在本地服务器上api以xml格式向我发送信息。使用Curl Simple XML,我设法将它们放在变量中并以原始格式回显。但我想用php回显表中的数据。
private $fp;
private function connect(){
$apnsHost = 'gateway.push.apple.com';
$apnsCert = 'certs/cert.pem';
$apnsPort = 2195;
$pass = "blah";
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', $pass);
$this->fp = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext);
if (!$this->fp) return("Failed to connect: $err $errstr<br>");
echo 'Connected to APNS<hr />';
}
private function send(){
$this->connect();
foreach($pushes as $push) {
$payload['aps'] = array('alert' => $push->text, 'badge' => 0, 'sound' => 'default');
$payload2 = json_encode($payload);
$msg = chr(0) . pack('n', 32) . pack('H*', $push->token) . pack('n', strlen($payload2)) . $payload2;
try {
$result = fwrite($this->fp, $msg, strlen($msg));
}
catch (\Exception $e) {
fclose($this->fp);
echo('Error sending payload: ' . $e->getMessage());
sleep(5);
$this->connect();
}
}
}
在echo $ data之后,这是我以原始格式获得的。
<?php
$curl = curl_init();
curl_setopt_array($curl, Array(
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://10.10.10.91:8080/StanjeKupca/services/Service.ServiceHttpSoap11Endpoint/getPartner?sifPar=1000001",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "utf8",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
)
));
$data = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
// die('<pre>' . print_r($xml], TRUE) . '</pre>');
foreach ($xml->ns:return as $item) {
echo $item->ax21:kolicina;
echo $item->ax21:nazPar;
echo $item->ax21:sifPar;
}
?>
我不知道处理命名空间!!