Home  >  Article  >  Backend Development  >  PHP WeChat public account development, keyword reply using switch error

PHP WeChat public account development, keyword reply using switch error

WBOY
WBOYOriginal
2016-09-24 09:03:131258browse

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:


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 = "
                        
                        
                        %s
                        
                        
                        ";
            $info = sprintf($template, $toUser, $fromUser, $time, $msgType, $content);
            echo $info;
        }
Statement:
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