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




  • 相关阅读:
    PHP——文件操作
    PHP——注册页面,审核页面,登录页面:加Session和Cookie
    ajax——优化0126(增删改查:添加查看详情,返回结果类型为JSON型,在窗口显示)
    ajax——三级联动下拉列表框的优化(简化页面,用jquery插件代替原来页面代码,返回处理数据类型为"TEXT")
    ajax——实现三级联动下拉列表
    通过view实现字段的只读、隐藏操作【转】
    OpenERP how to set the tree view limit
    OpenERP 疑问之一
    Django 安装
    OpenERP 中国财务模块 调整
  • 原文地址:https://www.cnblogs.com/sanpoye/p/3667336.html
Copyright © 2011-2022 走看看