zoukankan      html  css  js  c++  java
  • 微信公众平台开发(44)历史上的今天

    微信公众平台开发 历史上的今天 当年今日
    作者:方倍工作室 
    原文: http://www.cnblogs.com/txw1958/p/weixin-44-history.html

    一、历史上的今天

    回顾历史的长河,历史是生活的一面镜子;以史为鉴,可以知兴衰;历史上的每一天,都是喜忧参半;可以了解历史的这一天发生的事件,借古可以鉴今,历史是不能忘记的。 这里你可以阅读每一天的历史故事,每天发生了哪些大事,历史上谁诞生和逝世了,每天都是什么纪念日、节日,在这里你都可以容易浏览到!
    在我们生活中,日历是一个简单而重要的工具,只要翻开不同年份的日历,你会发现日期的排布总是一样的,在每一年我们都会经历相同的一天,比如元旦或圣诞节,就好像我们每一天出门,总会从门口经过一样。就在这简单的一天里,在历史上曾经发生过许多不同寻常的事情,甚至是改变世界历史的事情。这些历史事件发生的时间和意义被牢牢地记录在历史书籍上,也许你会碰巧发现一些重要的历史事件发生的日期就是你出生的那一天。如果幸运的话,也许你的生日会和某一个重要节日重合,这是多么有趣的事情啊!因此我们编写了这一套以日期为顺序的阅读百科书籍,让读者知道在自己生日那一天,或者是在自己感兴趣的那一天里,在历史上都发生过什么重要的事情,使读者为自己出生的那天而自豪,激励读者为自己的理想而努力奋斗

    二、数据源

    下列一年三百六十六天(含闰年2月29日)。点击某天,可查阅以往该日历史。

    1月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31        
    2月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29            
    3月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31        
    4月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30          
    5月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31        
    6月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30          
    7月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31        
    8月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31        
    9月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30          
    10月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31        
    11月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30          
    12月
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31        

    三、预览

     实现代码:

    <?php
    /*
        方倍工作室
        CopyRight 2013 All Rights Reserved
    */
    
    define("TOKEN", "weixin");
    
    $wechatObj = new wechatCallbackapiTest();
    if (!isset($_GET['echostr'])) {
        $wechatObj->responseMsg();
    }else{
        $wechatObj->valid();
    }
    
    class wechatCallbackapiTest
    {
        public function valid()
        {
            $echoStr = $_GET["echostr"];
            if($this->checkSignature()){
                echo $echoStr;
                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;
            }
        }
    
        public function responseMsg()
        {
            $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
            if (!empty($postStr)){
                $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $RX_TYPE = trim($postObj->MsgType);
    
                switch ($RX_TYPE)
                {
                    case "text":
                        $resultStr = $this->receiveText($postObj);
                        break;
                    case "event":
                        $resultStr = $this->receiveEvent($postObj);
                        break;
                    default:
                        $resultStr = "";
                        break;
                }
                echo $resultStr;
            }else {
                echo "";
                exit;
            }
        }
    
        private function receiveText($object)
        {
            $keyword = trim($object->Content);
            $url = "http://api100.duapp.com/history/?appkey=trialuser";
            $output = file_get_contents($url);
            $contentStr = json_decode($output, true);
            
            if (is_array($contentStr)){
                $resultStr = $this->transmitNews($object, $contentStr);
            }else{
                $resultStr = $this->transmitText($object, $contentStr);
            }
            return $resultStr;
        }
    
        private function receiveEvent($object)
        {
            $contentStr = "";
            switch ($object->Event)
            {
                case "subscribe":
                    $contentStr = "欢迎关注方倍工作室";
                    break;
                default:
                    break;
            }
            $resultStr = $this->transmitText($object, $contentStr);
            return $resultStr;
        }
        
        private function transmitText($object, $content)
        {
            $textTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[text]]></MsgType>
    <Content><![CDATA[%s]]></Content>
    </xml>";
            $resultStr = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content);
            return $resultStr;
        }
    
        private function transmitNews($object, $arr_item)
        {
            if(!is_array($arr_item))
                return;
    
            $itemTpl = "    <item>
            <Title><![CDATA[%s]]></Title>
            <Description><![CDATA[%s]]></Description>
            <PicUrl><![CDATA[%s]]></PicUrl>
            <Url><![CDATA[%s]]></Url>
        </item>
    ";
            $item_str = "";
            foreach ($arr_item as $item)
                $item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);
    
            $newsTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[news]]></MsgType>
    <Content><![CDATA[]]></Content>
    <ArticleCount>%s</ArticleCount>
    <Articles>
    $item_str</Articles>
    </xml>";
    
            $resultStr = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($arr_item));
            return $resultStr;
        }
    }
    ?>
  • 相关阅读:
    [leetcode-604-Design Compressed String Iterator]
    [leetcode-617-Merge Two Binary Trees]
    OpenCV学习1-----打开摄像头并在画面上添加水印
    cvCvtColor与cvtColor区别
    [leetcode-547-Friend Circles]
    [leetcode-260-Single Number III]
    复位电路
    单片机特殊功能寄存器
    单片机的定时器与计数器
    单片机定时/计数工作方式
  • 原文地址:https://www.cnblogs.com/txw1958/p/weixin-44-history.html
Copyright © 2011-2022 走看看