Home  >  Article  >  WeChat Applet  >  Today in the history of WeChat public platform development

Today in the history of WeChat public platform development

高洛峰
高洛峰Original
2017-03-04 11:33:501845browse

1. Today in History

Looking back on the long river of history, history is a mirror of life; taking history as a mirror, we can know the rise and fall; every day in history is a mixed blessing; we can Understanding the events that occurred on this day in history can help us draw lessons from the past, and history cannot be forgotten. Here you can read the historical stories of each day, what major events happened every day, who was born and died in history, what anniversaries and festivals are celebrated every day, you can easily browse here!
In our lives, the calendar is a simple but important tool. As long as you open the calendars of different years, you will find that the arrangement of dates is always the same. We will experience the same day every year, such as New Year's Day. Or Christmas, just like when we go out every day, we always pass by the door. On this simple day, many extraordinary things happened in history, even things that changed the history of the world. The time and significance of these historical events are firmly recorded in history books. Maybe you will happen to find that the date of some important historical events is the day you were born. If you are lucky, maybe your birthday will coincide with an important holiday. What an interesting thing! Therefore, we have compiled this set of reading encyclopedias in date order to let readers know what important things happened in history on their birthdays or on the day they are interested in, so that readers can Be proud of the day you were born, and inspire readers to work hard for their ideals

2. Data source

The following are three hundred and sixty-six in a year Sixteen days (including February 29 in leap years). Click on a day to view the history of that day in the past.

January 12345678910111213141516171819202122232425262728293031 February 1234567891011121314151617181920212223242 526272829 March12345678910111213141516171819202122232425262728293031
April 123456789101112131415161718192021222324252627282930 May 12345678910111213141516171819202122232425262728293031 June 123456789101112131415161718192021222324252627282930
July 123456789101112131415161718192021222324252627 28293031 August 12345678910111213141516171819202122232425262728293031 9 Month 123456789101112131415161718192021222324252627282930
31 November123456789101112131415161718192021222324252627282930 December123456789101112131415161718192021222324252 62728293031

3. Preview

微信公众平台开发历史上的今天

## Implementation code:

<?php

define("TOKEN", "weixin");

$wechatObj = new wechatCallbackapiTest();
if (!isset($_GET[&#39;echostr&#39;])) {
    $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;
    }
}
?>

For more related articles on this day in the history of WeChat public platform development, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn