PHP WeChat public account development, keyword reply using switch error

WBOY
Release: 2016-09-24 09:03:13
Original
1356 people have browsed it

Using PHP to develop the WeChat public platform, I encountered a problem when doing keyword replies, using if. There is no problem with the else if statement, but if it is switched to switch, the public platform cannot be submitted when modifying the configuration. Has anyone encountered this situation?
Here is the code:

<code>
if (strtolower( $postObj->MsgType ) == 'text') {
            switch ( trim($postObj->Content )) {
                case '电影':
                    $contnet = '最近都没有看过什么电影,真的是没有什么时间啊。';
                    break;
                case '菜':
                    $content = '最喜欢吃红烧肉了,真心不喜欢那些都是骨头和皮没有肉的荤菜。';
                    break;
                case '饮料':
                    $content = '柠檬水,我感觉我对柠檬水上瘾了。'
                    break;
                default:
                    $content = '这不是我们设置的关键字,你再看看?';
                    break;
            }
            $toUser = $postObj->FromUserName;
            $fromUser = $postObj->ToUserName;
            $time = time();
            $msgType = 'text';
            $template = "<xml>
                        <ToUserName><![CDATA[%s]]></ToUserName>
                        <FromUserName><![CDATA[%s]]></FromUserName>
                        <CreateTime>%s</CreateTime>
                        <MsgType><![CDATA[%s]]></MsgType>
                        <Content><![CDATA[%s]]></Content>
                        </xml>";
            $info = sprintf($template, $toUser, $fromUser, $time, $msgType, $content);
            echo $info;
        }
</code>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!