• <b id="l3qpx"><abbr id="l3qpx"></abbr></b>
  • <th id="l3qpx"><progress id="l3qpx"></progress></th>
      <th id="l3qpx"></th>
      <dd id="l3qpx"><font id="l3qpx"></font></dd>
      <th id="l3qpx"></th>
      0712-2888027 189-8648-0214
      微信公眾號(hào)

      孝感風(fēng)信網(wǎng)絡(luò)科技有限公司微信公眾號(hào)

      當(dāng)前位置:主頁(yè) > 技術(shù)支持 > PHP > 微信公眾號(hào)token驗(yàn)證php代碼

      微信公眾號(hào)token驗(yàn)證php代碼

      時(shí)間:2017-11-08來(lái)源:風(fēng)信官網(wǎng) 點(diǎn)擊: 1623次
      微信公眾號(hào)開(kāi)發(fā)過(guò)程中,都是使用自有服務(wù)器,所以我們需要對(duì)現(xiàn)有公眾號(hào)進(jìn)行配置,才能將公眾號(hào)中的消息轉(zhuǎn)發(fā)到自有服務(wù)器上,但很多時(shí)候,我們?cè)诠娞?hào)平臺(tái)服務(wù)器配置已經(jīng)填寫(xiě)正確的信息,提交確認(rèn)信息的時(shí)候,總是提示:token驗(yàn)證失敗,很是惱火,借助以下php代碼,可快速驗(yàn)證服務(wù)器令牌(Token)的有效性。
      微信公眾號(hào)token驗(yàn)證php代碼

      微信公眾號(hào)token驗(yàn)證php代碼如下:

      <?php
      /**
       * wechat php test
       * update time: 20141008
       */
      //define your token
      define("TOKEN", "weixin");
      $wechatObj = new wechatCallbackapiTest();
      $wechatObj->valid();
      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 (!emptyempty($postStr)){
                  $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                  $fromUsername = $postObj->FromUserName;
                  $toUsername = $postObj->ToUserName;
                  $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>";
                  if(!emptyempty( $keyword ))
                  {
                      $msgType = "text";
                      $contentStr = "Welcome to wechat world!";
                      $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                      echo $resultStr;
                  }else{
                      echo "Input something...";
                  }
              }else {
                  echo "";
                  exit;
              }
          }
      
          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;
              }
          }
      }
      ?>
      熱門(mén)關(guān)鍵詞: 微信公眾號(hào) token驗(yàn)證 php代碼

      您可能感興趣的相關(guān)文章:

      欄目列表
      推薦內(nèi)容
      熱點(diǎn)內(nèi)容
      展開(kāi)
      欧美一区二区三区免费A级视频,亚洲精品中文字幕综合,动漫精品中文字幕无码第一页,1024亚洲国产综合 亚太影院 柯西贝尔-游戏赚网
    1. <b id="l3qpx"><abbr id="l3qpx"></abbr></b>
    2. <th id="l3qpx"><progress id="l3qpx"></progress></th>
        <th id="l3qpx"></th>
        <dd id="l3qpx"><font id="l3qpx"></font></dd>
        <th id="l3qpx"></th>