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>