php对了,可是对接到微信只返回array
用这个之后php是对,可是接到微信就变成单独的回复一个array
------解决思路----------------------
把数据连接成串,或编码成 json
------解决思路----------------------
return json_encode($res);
------解决思路----------------------
在echo json_encode之前,加上:header('content-type:application/json;charset=utf-8');
------解决思路----------------------
引用:quote: 引用:
在echo json_encode之前,加上:header('content-type:application/json;charset=utf-8');
$sql = select * from `record` where title like '%$keyword%';
$result = mysql_query($sql, $link); // 执行查询语句
$res=array();
while($row = mysql_fetch_array($result))
{
$res[]=$row[title];
}
header('content-type:application/json;charset=utf-8');
return json_encode($res);
mysql_close($link);
} 这次返回的值是[]
返回值为空?那么直接return hello world;是什么结果?
------解决思路----------------------
引用:quote: 引用:
在echo json_encode之前,加上:header('content-type:application/json;charset=utf-8');
会不会是这个有错误?
%s
0
你把0去掉试试。
另外:要返回信息,不应该用return,而是echo
public function responsemsg(){
//get post data, may be due to the different environments
$poststr = $globals[http_raw_post_data]; //接收微信发来的xml数据
//extract post data
if(!empty($poststr)){
//解析post来的xml为一个对象$postobj
$postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata);
$fromusername = $postobj->fromusername; //请求消息的用户
$tousername = $postobj->tousername; //我的公众号id
$keyword = trim($postobj->content); //用户发送的消息内容
$time = time(); //时间戳
$msgtype = 'text'; //消息类型:文本
$texttpl =
%s
;
$contentstr = 输入-h查看帮助吧(=?ω?=);
$resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr);
echo $resultstr;
