学习微信官方代码----关注回复

微信开发文档中没有提及关注时自动回复的参数,手动提取,在程序中添加两个变量$type 和 $customevent

当 $type值为event, $customevent的值为subscribe时,返回设置信息

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 */
              libxml_disable_entity_loader(true);
               $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);//解析xml
              $fromUsername = $postObj->FromUserName; //用户名
              $toUsername = $postObj->ToUserName; //公众号ID

              //自定义event,subscribe事件
              $type = $postObj -> MsgType;
              $customevent = $postObj -> Event;

返回信息设置

case "event";
    if($customevent == "subscribe"){
        $contentStr = "感谢你来到樱桃梦想屋 \n 回复 1 查看1的内容 \n 回复 2 查看2的内容 \n 回复 3 查看3的内容";
    }
    break;

你可能感兴趣的:(微信开发)