本帖最后由 u014294325 于 2015-06-19 09:51:33 编辑 做微信公众平台 在php页面从数据库中读取数据,用在微信公众平台的关注自动回复上
求指教怎么做
<br />public function handleEvent($postObj)<br /> {<br /> <br /> //header('Content-type:text/html;charset=utf-8'); //定义输出格式编码为utf-8<br /> $db = new mysqli('127.0.0.1','root','123','weixin'); //建立mysql数据库连接<br /> $_ROWS = $db->query('SELECT * FROM event_subscribe'); //用sql语句获取数据<br /> //mysql_query("set names utf8");//设置编码utf8<br /> while($_ROW = $_ROWS->fetch_assoc())<br /> //$title= $_ROW->ess_Title;<br /> //$Description= $_ROW->ess_Description;<br /> //$PicUrl= $_ROW->ess_PictureUrl;<br /> //$Url= $row->ess_Url; <br /><br /> $title= $_ROW['ess_Title'];<br /> $Description= $_ROW['ess_Description'];<br /> $PicUrl= $_ROW['ess_PictureUrl'];<br /> $Url= $row['ess_Url']; <br /> //$contentStr = "欢迎关注哟"; <br /> $fromUsername = $postObj->FromUserName;<br /> $toUsername = $postObj->ToUserName;<br /> $msgType = "news"; <br /> $time = time();<br /> $textTpl = "<xml><br /> <ToUserName><![CDATA[%s]]></ToUserName><br /> <FromUserName><![CDATA[%s]]></FromUserName><br /> <CreateTime>%s</CreateTime><br /> <MsgType><![CDATA[news]]></MsgType><br /> <ArticleCount>1</ArticleCount><br /> <Articles><br /> <item><br /> <Title><![CDATA[%s]]></Title> <br /> <Description><![CDATA[%s]]></Description><br /> <PicUrl><![CDATA[%s]]></PicUrl><br /> <Url><![CDATA[%s]]></Url><br /> </item> <br /> </Articles><br /> <FuncFlag>1</FuncFlag><br /> </xml>";<br /> <br /> $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,$title,$Description,$PicUrl,$Url);<br /> echo $resultStr;
------解决思路----------------------新的代码
<br />public function handleEvent($postObj)<br /> {<br /> <br /> //header('Content-type:text/html;charset=utf-8'); //定义输出格式编码为utf-8<br /> $db = new mysqli('127.0.0.1','root','123','weixin'); //建立mysql数据库连接<br /> $db->query("SET NAMES utf8");//防止乱码<br /> $_ROWS = $db->query('SELECT * FROM event_subscribe where IsPublic=1'); //用sql语句获取数据<br /> $_ROW = mysqli_fetch_assoc($_ROWS);<br /> $textTpl = "<xml><br /> <ToUserName><![CDATA[%s]]></ToUserName><br /> <FromUserName><![CDATA[%s]]></FromUserName><br /> <CreateTime>%s</CreateTime><br /> <MsgType><![CDATA[news]]></MsgType><br /> <ArticleCount>1</ArticleCount><br /> <Articles><br /> <item><br /> <Title><![CDATA[%s]]></Title> <br /> <Description><![CDATA[%s]]></Description><br /> <PicUrl><![CDATA[%s]]></PicUrl><br /> <Url><![CDATA[%s]]></Url><br /> </item> <br /> </Articles><br /> <FuncFlag>1</FuncFlag><br /> </xml>";<br /> <br /> $resultStr = sprintf($textTpl, $postObj->FromUserName, $postObj->ToUserName, time(),$_ROW['ess_Title'],$_ROW['ess_Description'],$_ROW['ess_PictureUrl'],$_ROW['ess_Url']);<br /> <br /> return $resultStr;<br /> } <br />