php case 문장 분점
3902 단어 case
문서 에서 다음 과 같이 말 합 니 다.
케이스 문 구 를 대체 하 는 콜론 을 사용 할 수 있 습 니 다. 예 를 들 어:
<?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;
}
}
}
?>
저작권 성명: 본 고 는 블 로 거들 이 창작 한 글 로 블 로 거들 의 허락 없 이 전재 할 수 없다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Case swappingCase swapping Description: Given a string, swap the case for each of the letters. e.g. CodEwArs --> cODeWaRS Examples 다른...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.