智能云排名SEO內測

百度關鍵詞優化三天上首頁!同行都是朋友, 歡迎一起互利共贏。謝絕一切非正規行業服務,感謝以下同行、團隊、平臺和代理的支持:

百度站長平臺、MIP開發小組、SEO焦大老友、SEO每天一貼ZAC大哥、盧松松大哥、海瑤SEO兄弟、附子SEO兄弟、探索者SEO、幫站SEO好友、互點寶、超快排平臺

百億互刷寶、下拉天下、SEO自學網、SEO研究中心、小明SEO、王德春SEO、馬海祥博客、踏雪無痕掛機工作室、SEO云優化好友、云客網、杭州思億歐、網賺吧、北京SEO韓非老弟

需要了解以上同仁的相關信息,我們已經給你做好了搜索框,看右上角綠色那個,輸入搜索即刻直達

網站統計: 共有讀稿:14437部 / 今日更新:篇 / 評論:19條 / 會員:75 名 / 閱讀:1086086
您好,請 【登陸】/【注冊】
軟件內容頁橫幅廣告
您現在的位置:SEO平臺 > PHP網站建設 >

微信公眾平臺DEMO(PHP)

2018.04.20

瀏覽:

【導語】如果您覺得本篇內容還不錯,請點擊文章下面的贊,然后分享給朋友哦!...

微信公眾平臺DEMO(PHP)-破洛洛教學網...請看詳情...

seo

seo

微信公眾平臺DEMO(PHP)


本人在SAE環境下搭建了CI框架(其實這個小東西用不著用框架的),直接把代碼寫在了控制器里面

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
//define your token
define("TOKEN", "109");
 
class Welcome extends CI_Controller {
 
  public function index()
  {
    /*
    $this->load->helper('url');
    $this->load->view('welcome_message');
    */
     
    // use chat response
    $this->responseMsg();
   
  }
   
  // chat response
  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;
      $MsgType = $postObj->MsgType;
      $time = time();
       
      switch($MsgType){
        case('text'):
          $keyword = trim($postObj->Content);
          $textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                </xml>";
          switch($keyword){
            case(1):
              // Need to optimize
              // random read data from jokes
              $sql = 'SELECT * FROM jokes';
              $query = $this->db->query($sql);
              $res = $query->result_array();
              $num_rows = $query->num_rows();
              $key = rand(0, $num_rows - 1); // Notice: The value of key is from 0.
              //$contentStr = $key.'#'.$res[$key ]['content']; // debug
              $contentStr = $res[$key ]['content']; 
              break;
            case(2):
              $contentStr = 'Your fromUsername is: '.$fromUsername; 
              break;             
            case(3):
              $newsTpl = "<xml>
                    <ToUserName><![CDATA[%s]]></ToUserName>
                    <FromUserName><![CDATA[%s]]></FromUserName>
                    <CreateTime>%s</CreateTime>
                    <MsgType><![CDATA[%s]]></MsgType>
                    <ArticleCount>2</ArticleCount>
                     
                    <Articles>
                      <item>
                        <Title><![CDATA[%s]]></Title> 
                        <Description><![CDATA[%s]]></Description>
                        <PicUrl><![CDATA[%s]]></PicUrl>
                        <Url><![CDATA[%s]]></Url>
                      </item>
                      <item>
                        <Title><![CDATA[%s]]></Title>
                        <Description><![CDATA[%s]]></Description>
                        <PicUrl><![CDATA[%s]]></PicUrl>
                        <Url><![CDATA[%s]]></Url>
                      </item>
                    </Articles>
                     
                    </xml> ";
                     
              $resultStr = sprintf($newsTpl, $fromUsername, $toUsername, $time,'news',
                '百度','', 'http://www.baidu.com/img/bdlogo.gif', 'http://www.baidu.com',
                'Google','', '', 'http://www.google.com'); // Notice: Google's logo is not suitable.
              echo $resultStr;
              exit; // Notice: It's exit, not break.                
            case(4):
              $contentStr = "該功能正在開發中,敬請期待..."; 
              break;
               
            /* others */
             
            default:
              $contentStr = "回復數字 選擇服務\n";
              $contentStr .= "1 笑話精選\n";
              $contentStr .= "2 獲取您的Username...\n";  
              $contentStr .= "3 圖文消息示例\n"; 
              $contentStr .= "4 開發中...\n"; 
              break;
          }
          $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, 'text', $contentStr);
          break;
           
        case('image'):
           
          $media_id = $postObj->MediaId;
          $imgTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Image>
                  <MediaId><![CDATA[%s]]></MediaId>
                </Image>
                </xml>";
          $resultStr = sprintf($imgTpl, $fromUsername, $toUsername, $time, 'image', $media_id);
          break;
           
          // try get the id of the receive image and analyse
          /*
          $media_id = $postObj->MediaId;
          $textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                </xml>";
          $length = strlen($media_id);
          $contentStr = "I have received the image message you sent, the id of this image is # $media_id #, and the length of media_id is # $length #";
          $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, 'text', $contentStr);
          break;
          */
           
        case('voice'):
          $textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                </xml>"; 
          $contentStr = '你說啥?俺聽不見...';
          $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, 'text', $contentStr);
          break;
         
        /* others */
         
        default:
          $resultStr = "Input something...";
          break;
      }
      echo $resultStr;
       
    }else {
      echo "";
      exit;
    }
  }
}

 

9
贊一個
關鍵詞:
☆喜歡這篇文章嗎?分享給你的好友吧!點擊這里復制網址☆
共有3127人閱讀,期待你的評論!評論
請先登陸后才能發表評論哦!沒賬號?趕緊注冊一個吧!
最新評論
熱門標簽
回到頂部
英超赛程