zoukankan      html  css  js  c++  java
  • 代码作色测试

    <?php
    /**
    * wechat php test
    */

     
    //define your token
    define("TOKEN", "weixin");
    $wechatObj = new wechatCallbackapiTest();
    $wechatObj -> valid();
     
    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;
                $keyword = trim($postObj -> Content);
                $time = time();
                $textTpl = "
                                <xml>
                                    <ToUserName>
                                        <![CDATA[%s]]>
                                    </ToUserName>
                                    <FromUserName>
                                        <![CDATA[%s]]>
                                    </FromUserName>
                                    <CreateTime>
                                        %s
                                    </CreateTime>
                                    <MsgType>
                                        <![CDATA[%s]]>
                                    </MsgType>
                                    <Content>
                                        <![CDATA[%s]]>
                                    </Content>
                                    <FuncFlag>
                                        0
                                    </FuncFlag>
                                </xml>"
    ;
                if (!empty($keyword)) {
                    $msgType = "text";
                    $contentStr = "Welcome to wechat world!";
                    $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                    echo $resultStr;
                } else {
                    echo "Input something...";
                }
     
            } else {
                echo "";
                exit ;
            }
        }
     
        private function checkSignature() {
            $signature = $_GET["signature"];
            $timestamp = $_GET["timestamp"];
            $nonce = $_GET["nonce"];
     
            $token = TOKEN;
            $tmpArr = array($token, $timestamp, $nonce);
            sort($tmpArr, SORT_STRING);
            $tmpStr = implode($tmpArr);
            $tmpStr = sha1($tmpStr);
     
            if ($tmpStr == $signature) {
                return true;
            } else {
                return false;
            }
        }
     
    }




  • 相关阅读:
    python学习之模块(pip),列表生成式,模块操作mysql,excel
    python学习之非空即为真,函数,集合,解包与打包
    配置虚拟机和网络配置
    python学习之文件读写,序列化(json,pickle,shelve)
    python学习之列表,元祖,字典
    盒子内部文字超出不换行
    织梦dedecms文章发布日期时间调用标签大全
    贝塞尔曲线值
    CSS解决border影响元素宽高的问题(box-sizing属性)
    pc建站自适应
  • 原文地址:https://www.cnblogs.com/sanpoye/p/3667336.html
Copyright © 2011-2022 走看看