步骤:服务器做了操作(新增用户)推送消息给客户端;因服务器不在我这里,我就写了个本地模拟发送xml数据;
/**
* @author tanwenwei
* 描述:接收xml数据
*/
public function getxml(){
//1.获取到推送过来post数据(xml格式)
$postArr = @$GLOBALS['HTTP_RAW_POST_DATA'];
$postObj = simplexml_load_string($postArr);
M('settings')->where(array('id'=>7))->save(['value'=>(string)$postObj->Content]);
// $reqdata = "<xml><Encrypt><![CDATA[RypEvHKD8QQKFhvQ6QleEB4J58tiPdvo+rtK1I9qca6aM/wvqnLSV5zEPeusUiX5L5X/0lWfrf0QADHHhGd3QczcdCUpj911L3vg3W/sYYvuJTs3TUUkSUXxaccAS0qhxchrRYt66wiSpGLYL42aM6A8dTT+6k4aSknmPj48kzJs8qLjvd4Xgpue06DOdnLxAUHzM6+kDZ+HMZfJYuR+LtwGc2hgf5gsijff0ekUNXZiqATP7PF5mZxZ3Izoun1s4zG4LUMnvw2r+KqCKIw+3IQH03v+BCA9nMELNqbSf6tiWSrXJB3LAVGUcallcrw8V2t9EL4EhzJWrQUax5wLVMNS0+rUPA3k22Ncx4XXZS9o0MBH27Bo6BpNelZpS+/uh9KsNlY6bHCmJU9p8g7m3fVKn28H3KDYA5Pl/T8Z1ptDAVe0lXdQ2YoyyH2uyPIGHBZZIs2pDBS8R07+qN+E7Q==]]></Encrypt><MsgSignature><![CDATA[477715d11cdb4164915debcba66cb864d751f3e6]]></MsgSignature><TimeStamp><![CDATA[1409659813]]></TimeStamp><Nonce><![CDATA[1372623149]]></Nonce></xml>";
// $sync = new \Sync(C('ssosync.token'),C('ssosync.encodingAesKey'),C('ssosync.corpId'));
// $encrypt = $sync->decodedata($reqdata);
}
/**
* @author tanwenwei
* 描述:发送xml数据
*/
public function postxml(){
$xmlData = "<xml>
<Content><![CDATA[测试时间:2018-11-20]]></Content >
</xml >";
$url = 'localhost:1299/index.php/sync/getxml'; //接收xml数据的文件
$header[] = "Content-type: text/xml"; //定义content-type为xml,注意是数组
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $xmlData);
$response = curl_exec($ch);
if(curl_errno($ch)){
printcurl_error($ch);
}
curl_close($ch);
}
模拟的时候在浏览器直接调用postxml方法,如果数据库插入成功数据,说明接收成功;注:便用HTTP_RAW_POST_DATA需要在php.ini文件配置always_populate_raw_post_data为on