php实现基于微信公众平台开发SDK(demo)扩展的方法(2)

//处理事件消息
      private function handleEvent($obj){
          $content='';
          switch($obj->Event){
              case 'subscribe':
                  $content.="welcome-欢迎关注该公众号号!";
                  break;
              case 'unsubscribe':
                  $content.="感谢您一直以来对该公众号的关注,再见!";
                  break;
              default:
                  $content.="";
                  break;
          }
          return $this->handleStr($obj,$content);
      }
     
      //处理回复消息字符串
      private function handleStr($obj,$content='',$flag=0){
       $textTpl = "";
       return sprintf($textTpl, $obj->FromUserName, $obj->ToUserName, time(), $content,$flag);
      }
  
   //签名验证函数
   private function checkSignature()
   {
       $signature = $_GET["signature"];
       $timestamp = $_GET["timestamp"];
       $nonce = $_GET["nonce"];   
       $token = TOKEN;
       $tmpArr = array($token, $timestamp, $nonce);
       sort($tmpArr, SORT_STRING);
       $tmpStr = implode( $tmpArr );
       $tmpStr = sha1( $tmpStr );
       if( $tmpStr == $signature ){
           return true;
       }else{
           return false;
       }
   }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b426b69994e32d2f00ee800a1905b2f3.html