ホームページ  >  記事  >  WeChat アプレット  >  WeChat パブリック プラットフォーム開発の歴史の現在

WeChat パブリック プラットフォーム開発の歴史の現在

高洛峰
高洛峰オリジナル
2017-03-04 11:33:501846ブラウズ

1. 歴史の今日

歴史の長い流れを振り返ると、歴史は人生の鏡として捉えられ、私たちは歴史の中での栄枯盛衰を知ることができます。歴史の中でこの日に起こった出来事を理解することはできますが、過去は現在への指針として役立ちますが、歴史を忘れることはできません。 ここでは、毎日の歴史的な物語、毎日起こった大きな出来事、歴史の中で誰が生まれ誰が亡くなったか、毎日どのような記念日や祭りが祝われているか、ここで簡単に閲覧できます。
カレンダーは私たちの生活においてシンプルですが重要なツールです。さまざまな年のカレンダーを開くと、日付の配置が常に同じであることがわかります。元旦やクリスマスなど、私たちは毎年同じ日を経験します。 , 毎日出かけるときと同じように、私たちは必ず玄関の前を通ります。この何気ない日に、歴史の中で多くの異常な出来事、さらには世界の歴史を変える出来事さえも起こりました。これらの歴史的出来事の時期と重要性は歴史書にしっかりと記録されているので、もしかしたら、いくつかの重要な歴史的出来事の日付が自分の生まれ​​た日であることに気づくかもしれません。運が良ければ、あなたの誕生日が重要な祝日と重なるかもしれません。なんと興味深いことでしょう。そこで、読者が自分が生まれた日を誇りに思っていただけるよう、読者の誕生日や興味のある日に歴史上で何が起こったのかを日付順にまとめた読書百科事典です。読者に理想に向けて頑張るよう促してください

2. データソース

以下は、年間 366 日です (閏年の 2 月 29 日を含む)。日付をクリックすると、その日の過去の履歴が表示されます。

4月 1234567891011 1213141516171 8192021222324252627282930 5月 12345678910111213141516171819202122232425262728293031 6月1日 2345678910111213141516 1718192021222324252627282930 7月 12345678910111213141516171819202122232425262728293 031 10月 1234567891011121314151617181920212223242526272 8293031
1月 12345678910111213141516171819202122232425262728293031 2月 12345678910111213141516171819202 23242526272829 3月 12345678910111213141516171819202122232425262728293031
8月 123456789 10111213141516171819202122232425262728293031 9月 123456789101112131415161718192021222324252627282930
11月 12345678910111213141516171819202122232425262728 2930 12月 12345678910111213141516171819202 122232425262728293031

3.

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

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

詳細についてはWeChat パブリック プラットフォーム開発の歴史におけるこの日の記事は、PHP 中国語 Web サイトに注目してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。