link 上一篇的那个获取微信消息文章,你可以在接收消息的方法里加入,这里我是为了实现当用户发送指定的文本消息后自动回复。
function sendMsg($access_token,$fromusername){
$contentStr="这是发送内容<a href='http://www.baidu.com'>go</a>";
$contentStr=urlencode($contentStr);
//$content = $content."<a href='http://www.baidu.com'>go</a>";
$a=array("content"=>$contentStr);
$this ->creatTextFile($fromusername,'res3444');
$b=array("touser"=>"{$fromusername}","msgtype"=>"text","text"=>$a);
$this ->creatTextFile(count($b),'res433');
$post=json_encode($b);
$post=urldecode($post);
$sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$result = $this -> http_post_json($sendUrl,$post);
$this ->creatTextFile($result,'res433');
}
private function receiveText($object,$access_token) {
$funcFlag = 0;
$contentStr = $object -> Content;
//this ->show($contentStr);
$fromusername = $object -> FromUserName;
$this -> sendMsg($access_token,$fromusername);
$resultStr = $this -> transmitText($object, $contentStr, $funcFlag);
return $resultStr;
}