function get_news_content() { $xml = <<<xl <?xml version="1.0" encoding="utf-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.reuters.com/ns/2006/05/01/webservices/rkd/News_1" xmlns:ns2="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://www.reuters.com/ns/2006/05/01/webservices/rkd/Common_1"> <env:Header> <ns2:To>http://api.rkd.reuters.com/api/2006/05/01/News_1.svc</ns2:To> <ns2:Action>http://www.reuters.com/ns/2006/05/01/webservices/rkd/News_1/RetrieveStoryML_1</ns2:Action> <ns3:Authorization> <ns3:ApplicationID>trkddemoappwm</ns3:ApplicationID> <ns3:Token>72a7ebf4b402280b1453ded824de6e966792cd79dd0c12d87f0ce21c048baa028db51e2924aa0e60713fea6d85e2f13bd9d521818383febbe0e61f824dae751798433a61b158f5eab068a909a1a8482687f1043cde1046a7c4aff1c0b00cdebb</ns3:Token> </ns3:Authorization> </env:Header> <env:Body> <ns1:RetrieveStoryML_Request_1 characters="zh-Hans"> <ns1:StoryMLRequest> <ns1:TimeOut>600</ns1:TimeOut> <ns1:StoryId>urn:newsml:reuters.com:20160105:nL3T14P3DH</ns1:StoryId> </ns1:StoryMLRequest> </ns1:RetrieveStoryML_Request_1> </env:Body> </env:Envelope> xl; $url = 'http://api.trkd.thomsonreuters.com/api/News/News.svc'; $header[] = 'Content-Type:application/soap+xml;'; $param = $xml; print_r(my_post($url, $param, $header)); } get_news_content();
#获取token $token = file_get_contents('token.txt'); $appid = APPID; foreach ($re_list as $k => $v) { $news_id = $v['id']; //检查Ini文件是否存在 ##存在就跳过,写入 $cur_date = date('Y-m-d'); $is_have = ini_file(null, 'default', $news_id); if ('' == $is_have) { ini_file(null, 'default', $news_id, $cur_date); } else { continue; } #$news_id = 'urn:newsml:reuters.com:20160105:nL3T14P02B'; $tmp_content = get_news_content($appid, $token, $news_id); file_put_contents("./data/news/content.xml", $tmp_content); #获取HT-标题 # TE-内容 #$format_content = XML_unserialize($tmp_content); #print_r($format_content); /*$title = $format_content['s:Envelope']['s:Body']['ns0:RetrieveStoryML_Response_1']['ns0:StoryMLResponse']['ns0:STORYML']['HL']['HT']; $content = $format_content['s:Envelope']['s:Body']['ns0:RetrieveStoryML_Response_1']['ns0:StoryMLResponse']['ns0:STORYML']['HL']['TE']; $re_list[$k]['title'] = $title; $re_list[$k]['content'] = htmlspecialchars($content);*/ $tmp_content_url = "./data/news/content.xml"; $reader = new XMLReader(); $reader->open($tmp_content_url, 'utf-8'); while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { $nodeName = $reader->name;