>  기사  >  백엔드 개발  >  WeChat 공개 계정 개발 xml: XML 필드 오류입니다. 응답 xml을 확인하세요!

WeChat 공개 계정 개발 xml: XML 필드 오류입니다. 응답 xml을 확인하세요!

不言
不言원래의
2018-05-15 11:58:442755검색

php 코드는 다음과 같습니다 tp Framework

responseMsg();
      }
    }
    public function responseMsg()
    {
    //get post data, May be due to the different environments
    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
    // $tmpstr = $postStr;
    libxml_disable_entity_loader(true);
    $postObj = simplexml_load_string($postStr,'SimpleXMLElement', LIBXML_NOCDATA);
    //extract post data
    if (strtolower( $postObj->MsgType ) == 'event'){
                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
                   the best way is to check the validity of xml by yourself */
                   if (strtolower( $postObj->Event == 'subscribe')) {
                     $toUsername = $postObj->FromUserName;
                     $fromUsername = $postObj->ToUserName;
                     $time = time();
                     $MsgType = 'text';
                     $content = "欢迎访问我的公众号";
                     $textTpl = "%s";
                     $info = sprintf($textTpl,$toUsername,$fromUsername,$time,$MsgType,$content);
                     echo $info;
                   }
        }
    }
}

테스트 결과는 다음과 같습니다.

http://120.27.115.59/wechat.php/Home/Index/wechat
成功或失败:
Decrypt Fail!  
错误原因:
Xml fields error, please check your response xml! 
状态码:
200    OK 
Headers:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Date: Tue, 23 Aug 2016 10:23:34 GMT
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Set-Cookie: PHPSESSID=4tlrj4jd7cgoo3ueaigc6753q7; path=/
Pragma: no-cache
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Content-Type: text/html
Content-Length: 239
 
解密前xml:1471947814解密后xml:

답글 내용:

php 코드는 다음과 같습니다 tp Framework

responseMsg();
      }
    }
    public function responseMsg()
    {
    //get post data, May be due to the different environments
    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
    // $tmpstr = $postStr;
    libxml_disable_entity_loader(true);
    $postObj = simplexml_load_string($postStr,'SimpleXMLElement', LIBXML_NOCDATA);
    //extract post data
    if (strtolower( $postObj->MsgType ) == 'event'){
                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
                   the best way is to check the validity of xml by yourself */
                   if (strtolower( $postObj->Event == 'subscribe')) {
                     $toUsername = $postObj->FromUserName;
                     $fromUsername = $postObj->ToUserName;
                     $time = time();
                     $MsgType = 'text';
                     $content = "欢迎访问我的公众号";
                     $textTpl = "%s";
                     $info = sprintf($textTpl,$toUsername,$fromUsername,$time,$MsgType,$content);
                     echo $info;
                   }
        }
    }
}

테스트 결과는 다음과 같습니다.

http://120.27.115.59/wechat.php/Home/Index/wechat
成功或失败:
Decrypt Fail!  
错误原因:
Xml fields error, please check your response xml! 
状态码:
200    OK 
Headers:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Date: Tue, 23 Aug 2016 10:23:34 GMT
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Set-Cookie: PHPSESSID=4tlrj4jd7cgoo3ueaigc6753q7; path=/
Pragma: no-cache
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Content-Type: text/html
Content-Length: 239
 
解密前xml:1471947814解密后xml:

해결되었습니다. . TP 문제인 것 같습니다

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.