濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > php微信公眾號(hào)開(kāi)發(fā)之翻頁(yè)查詢

php微信公眾號(hào)開(kāi)發(fā)之翻頁(yè)查詢

熱門(mén)標(biāo)簽:亳州企業(yè)外呼系統(tǒng) 兼職做地圖標(biāo)注好賺錢(qián)嗎 地圖標(biāo)注怎么做商戶驗(yàn)證 400 電話 辦理 智能電銷(xiāo)語(yǔ)音機(jī)器人資訊 打開(kāi)百度地圖標(biāo)注 山東電銷(xiāo)卡外呼系統(tǒng)原理是什么 海南外呼系統(tǒng)方案 蘇州外呼系統(tǒng)有效果嗎

本文為大家分享了php微信公眾號(hào)開(kāi)發(fā)之翻頁(yè)查詢的具體代碼,供大家參考,具體內(nèi)容如下

注意:公眾號(hào)列表最多只能列出8列,超出會(huì)報(bào)錯(cuò)

  • 分頁(yè)原理
  • limit 開(kāi)始位置 , 條數(shù)
  • (當(dāng)前頁(yè)數(shù) - 1) x 每頁(yè)條數(shù) , 每頁(yè)條數(shù)
  • limit ($Page - 1) * $PageSize , $PageSize
  • 0 為開(kāi)始位置
  • mysql_num_rows 條數(shù)
  • require() 與 require_once() 開(kāi)始加載,錯(cuò)誤停止
  • include() 與 include_once() 使用加載,錯(cuò)誤跳過(guò)
  • ceil 進(jìn)一 向上取整

原理:

  • 總共10條,每頁(yè)9條
  • n條
  • sum 總共幾頁(yè) ceil ( n / 9 )
  • 開(kāi)始條數(shù) : (當(dāng)前頁(yè)數(shù) - 1 ) x 每頁(yè)條數(shù)
  • (key - 1)* 9

注釋?zhuān)?1 是為了說(shuō)明有多少頁(yè)

>10 10

核心代碼如下:

$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>%s/Content>
              FuncFlag>0/FuncFlag>
              /xml>";       
        switch ($type)
        {  
        case "event";
        if ($customevent=="subscribe")
          {$contentStr = "感謝你的關(guān)注\n欄目正在搭建,敬請(qǐng)期待\n回復(fù)1看視頻教程";}
        break;
        case "image";
          $contentStr = "你的圖片很棒!";
          break;
        case "location";
          $contentStr = "你的緯度是{$latitude},經(jīng)度是{$longitude},我已經(jīng)鎖定!";
          break;
        case "link" ;
          $contentStr = "你的鏈接有病毒吧!";
          break;
        case "text";
           include("coon.php");
           $num = "SELECT * FROM `kecheng` ";
           $que=mysql_query($num);
           $no=mysql_num_rows($que);//獲得條數(shù)
           $sumpage=ceil($no/7);
           $page=(intval($keyword)-1)*7;
           $total=$no-$page+1;
           if($total>8)
           {$total=8;} 
           $sql = "SELECT * FROM `kecheng` ORDER BY `id` DESC LIMIT {$page},7";
           $query=mysql_query($sql);        
           $newsTpl = "xml>
            ToUserName>![CDATA[%s]]>/ToUserName>
            FromUserName>![CDATA[%s]]>/FromUserName>
            CreateTime>%s/CreateTime>
            MsgType>![CDATA[news]]>/MsgType>
            ArticleCount>$total/ArticleCount>
            Articles>
            item>
            Title>![CDATA[總共{$sumpage}頁(yè),輸入頁(yè)數(shù)翻頁(yè)]]>/Title>
            Description>![CDATA[]]>/Description>
            PicUrl>http://autoguitar.duapp.com/1.jpg/PicUrl>
            Url>![CDATA[]]>/Url>
            /item>";
              while($rs=mysql_fetch_array($query)){    
              $newsTpl.="item>
                   Title>$rs[content]/Title> 
                   Description>![CDATA[]]>/Description>
                   PicUrl>http://dq095.applinzi.com/2.jpg/PicUrl>
                   Url>![CDATA[]]>/Url>
                   /item>";
                   }
              $newsTpl.="/Articles>
                   FuncFlag>0/FuncFlag>
                  /xml>";
           $myresultStr = sprintf($newsTpl, $fromUsername, $toUsername, $time);
           echo $myresultStr;
           break;         
        default;
          $contentStr ="此項(xiàng)功能尚未開(kāi)發(fā)";  
        }
        $msgType="text";
        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
        echo $resultStr;


coon.php連接數(shù)據(jù)庫(kù)代碼如下:

?php

    //用 戶 名 : $user
    //密  碼 : $pwd
    //主庫(kù)域名 : $host
    //從庫(kù)域名 : SAE_MYSQL_HOST_S
    //端  口 : $port
    //數(shù)據(jù)庫(kù)名 : $dbname

    $dbname = "app_dq095";
    $host = "w.rdc.sae.sina.com.cn";
    $port = "3306";
    $user = "4k514n103z";
    $pwd = "2402314li2j1i5im1xy2xizj5y332w2x41k2z203";

    /*接著調(diào)用mysql_connect()連接服務(wù)器*/
    // 連主庫(kù)
    $db = mysql_connect($host,$user,$pwd);

    if(!$db){
      die("Connect Server Failed: " . mysql_error($db));
    }

    /*連接成功后立即調(diào)用mysql_select_db()選中需要連接的數(shù)據(jù)庫(kù)*/
    if (!mysql_select_db($dbname)) {
      die("Select Database Failed: " . mysql_error($db));
    }
    mysql_query("set names utf-8",$db); 

    /*至此連接已完全建立,就可對(duì)當(dāng)前數(shù)據(jù)庫(kù)進(jìn)行相應(yīng)的操作了*/
    /*?。。∽⒁?,無(wú)法再通過(guò)本次連接調(diào)用mysql_select_db來(lái)切換到其它數(shù)據(jù)庫(kù)了!?。?/
    /* 需要再連接其它數(shù)據(jù)庫(kù),請(qǐng)?jiān)偈褂胢ysql_connect+mysql_select_db啟動(dòng)另一個(gè)連接*/

    /**
       * 接下來(lái)就可以使用其它標(biāo)準(zhǔn)php mysql函數(shù)操作進(jìn)行數(shù)據(jù)庫(kù)操作
    */

index.php整體代碼如下:

?php
/**
 * wechat php test
 */



//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
$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>%s/Content>
              FuncFlag>0/FuncFlag>
              /xml>";       
        switch ($type)
        {  
        case "event";
        if ($customevent=="subscribe")
          {$contentStr = "感謝你的關(guān)注\n欄目正在搭建,敬請(qǐng)期待\n回復(fù)1看視頻教程";}
        break;
        case "image";
          $contentStr = "你的圖片很棒!";
          break;
        case "location";
          $contentStr = "你的緯度是{$latitude},經(jīng)度是{$longitude},我已經(jīng)鎖定!";
          break;
        case "link" ;
          $contentStr = "你的鏈接有病毒吧!";
          break;
        case "text";
           include("coon.php");
           $num = "SELECT * FROM `kecheng` ";
           $que=mysql_query($num);
           $no=mysql_num_rows($que);//獲得條數(shù)
           $sumpage=ceil($no/7);
           $page=(intval($keyword)-1)*7;
           $total=$no-$page+1;
           if($total>8)
           {$total=8;} 
           $sql = "SELECT * FROM `kecheng` ORDER BY `id` DESC LIMIT {$page},7";
           $query=mysql_query($sql);        
           $newsTpl = "xml>
            ToUserName>![CDATA[%s]]>/ToUserName>
            FromUserName>![CDATA[%s]]>/FromUserName>
            CreateTime>%s/CreateTime>
            MsgType>![CDATA[news]]>/MsgType>
            ArticleCount>$total/ArticleCount>
            Articles>
            item>
            Title>![CDATA[總共{$sumpage}頁(yè),輸入頁(yè)數(shù)翻頁(yè)]]>/Title>
            Description>![CDATA[]]>/Description>
            PicUrl>http://autoguitar.duapp.com/1.jpg/PicUrl>
            Url>![CDATA[]]>/Url>
            /item>";
              while($rs=mysql_fetch_array($query)){    
              $newsTpl.="item>
                   Title>$rs[content]/Title> 
                   Description>![CDATA[]]>/Description>
                   PicUrl>http://dq095.applinzi.com/2.jpg/PicUrl>
                   Url>![CDATA[]]>/Url>
                   /item>";
                   }
              $newsTpl.="/Articles>
                   FuncFlag>0/FuncFlag>
                  /xml>";
           $myresultStr = sprintf($newsTpl, $fromUsername, $toUsername, $time);
           echo $myresultStr;
           break;         
        default;
          $contentStr ="此項(xiàng)功能尚未開(kāi)發(fā)";  
        }
        $msgType="text";
        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
        echo $resultStr;

      }
  }

  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;
    }
  }
}

?>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • PHP翻頁(yè)跳轉(zhuǎn)功能實(shí)現(xiàn)方法
  • PHP 長(zhǎng)文章分頁(yè)函數(shù) 帶使用方法,不會(huì)分割段落,翻頁(yè)在底部
  • PHP 翻頁(yè) 實(shí)例代碼
  • 一個(gè)很不錯(cuò)的PHP翻頁(yè)類(lèi)
  • php實(shí)現(xiàn)網(wǎng)頁(yè)上一頁(yè)下一頁(yè)翻頁(yè)過(guò)程詳解

標(biāo)簽:綏化 萊蕪 金華 紹興 清遠(yuǎn) 安康 呼倫貝爾 溫州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php微信公眾號(hào)開(kāi)發(fā)之翻頁(yè)查詢》,本文關(guān)鍵詞  php,微信,公眾,號(hào)開(kāi),發(fā)之,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《php微信公眾號(hào)開(kāi)發(fā)之翻頁(yè)查詢》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于php微信公眾號(hào)開(kāi)發(fā)之翻頁(yè)查詢的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    阿拉善右旗| 花垣县| 长白| 东明县| 栖霞市| 保康县| 射阳县| 教育| 格尔木市| 蒙山县| 沈阳市| 乐都县| 象山县| 万山特区| 惠东县| 惠安县| 汤阴县| 青河县| 牡丹江市| 安远县| 攀枝花市| 阿图什市| 吉木萨尔县| 蕉岭县| 英山县| 贺州市| 邹城市| 湘潭县| 六安市| 清丰县| 灵山县| 徐汇区| 巨鹿县| 马边| 民和| 温州市| 山东省| 翼城县| 玉门市| 确山县| 江都市|