本文将带你了解微信开发31----微信群发消息4,希望本文对大家学微信有所帮助。
index.php代码如下:
checkSignature()){ echo $echoStr; exit; } } public function responseMsg() { //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if (!empty($postStr)){ /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection, the best way is to check the validity of xml by yourself */ // 使用simplexml技术对xml进行解析 // libxml_disable_entity_loader(true), 是从安全性考虑,为了防止xml外部注入, //只对xml内部实体内容进行解析 libxml_disable_entity_loader(true); //加载 postStr 字符串 $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); global $tmp_arr; //当用户公众号有互动时,我们将会动hd_time字段更新 $connect = mysql_connect('localhost','root','root') or die('数据库链接失败'); mysql_select_db('wxdb',$connect); mysql_query('set names utf8'); $sql = "update qf_users set hd_time='{$time}' where openid='{$fromUsername}'"; mysql_query($sql, $connect); //根据接收到的消息类型,来进行分支处理(switch) switch($postObj->MsgType) { case 'event': if($postObj->Event == 'subscribe') { $contentStr = "欢迎关注leigood微信测试号噢"; $resultStr = sprintf($tmp_arr['text'], $fromUsername, $toUsername, $time, $contentStr); echo $resultStr; //消息