php case 문장 분점

3902 단어 case
http://www.php.net/manual/zh/control-structures.switch.php
문서 에서 다음 과 같이 말 합 니 다.
케이스 문 구 를 대체 하 는 콜론 을 사용 할 수 있 습 니 다. 예 를 들 어:
<?php
switch($beer)
{
    case 'tuborg';
    case 'carlsberg';
    case 'heineken';
        echo 'Good choice';
    break;
    default;
        echo 'Please make a new selection...';
    break;
}
?>

나 는 위 챗 공식 플랫폼 구축 과 개발 폭로 서 의 예시 코드 가 틀린 줄 알 았 는데... 기념:
<?php
/**
  * wechat php test
  */

//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
//$wechatObj->valid();
$wechatObj->responseMsg();
class wechatCallbackapiTest
{
	public function valid()
    {
        $echoStr = $_GET["echostr"];

        //valid signature , option
        if($this->checkSignature()){
        	echo $echoStr;
        	exit;
        }
    }

    public function responseMsg()
    {
		//get post data, May be due to the different environments
		$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

      	//extract post data
		if (!empty($postStr)){
                
              	$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername = $postObj->FromUserName;
                $toUsername = $postObj->ToUserName;
				$type = $postObj->MsgType;
				$customevent = $postObj->Event;
				$latitude  = $postObj->Location_X;
				$longitude = $postObj->Location_Y;
                $keyword = trim($postObj->Content);
                $time = time();
                $textTpl = "<xml>
							<ToUserName><![CDATA[%s]]></ToUserName>
							<FromUserName><![CDATA[%s]]></FromUserName>
							<CreateTime>%s</CreateTime>
							<MsgType><![CDATA[%s]]></MsgType>
							<Content><![CDATA[%s]]></Content>
							<FuncFlag>0</FuncFlag>
							</xml>";             
				switch ($type)
			{   case "event";
				if ($customevent=="subscribe")
				    {$contentStr = "      
1
2
3 ";} break; case "image"; $contentStr = " !"; break; case "location"; $contentStr = " {$latitude}, {$longitude}, !"; break; case "link" ; $contentStr = " !"; break; case "text"; switch($keyword) { case "1"; $contentStr = " : 703,1341702551, email:[email protected]"; break; case "2"; $contentStr = " :《 》 8 1 。"; break; case "3"; $contentStr = "31
32
33 "; break; default; $contentStr ="hi"; } break; default; $contentStr =" "; } $msgType="text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else { echo ""; exit; } } private function checkSignature() { $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; } } } ?>

저작권 성명: 본 고 는 블 로 거들 이 창작 한 글 로 블 로 거들 의 허락 없 이 전재 할 수 없다.

좋은 웹페이지 즐겨찾기