$wechatObj = new wechatCallbackapiTest(); if (isset($_GET['echostr'])) { $wechatObj->valid(); }else{
$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 = \"
case \"1\"; $contentStr = \"易伟律师,擅长交通事故、保险纠纷、医疗损害\"; break; case \"2\"; $contentStr = \"联系方式:汕头市金平区华乾大厦703,1341702551,email:30090032@qq.com。\"; break; case \"3\"; $contentStr = \"31离婚协议\\n32租房合同\\n33交通事故协议书\"; 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; } } } ?>
因篇幅问题不能全部显示,请点此查看更多更全内容