Akiraka Akiraka
  • 首页
  • Linux
    • ELK
    • PHP
    • Shell
    • Nginx
    • Docker
      • Docker Compose
    • Centos
    • Ubuntu
    • Jenkins
  • Python
  • Mac OS
  • Windows
  • 大数据
    • Hadoop
    • CDH
    • Hive
    • Spark
    • ZooKeeper
  • 微服务
    • Kubernetes
    • Helm
  • Other
  • Quark
  • 首页
  • Linux
    • ELK
    • PHP
    • Shell
    • Nginx
    • Docker
      • Docker Compose
    • Centos
    • Ubuntu
    • Jenkins
  • Python
  • Mac OS
  • Windows
  • 大数据
    • Hadoop
    • CDH
    • Hive
    • Spark
    • ZooKeeper
  • 微服务
    • Kubernetes
    • Helm
  • Other
  • Quark
首页 › Linux › 微信公众号服务器验证

微信公众号服务器验证

Akiraka1年前
<?php
/**
 * wechat php test
 */
//define your token
define("TOKEN", "wechat");
$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);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        if ($tmpStr == $signature) {
            return true;
        } else {
            return false;
        }
    }
}
?>
#php
0
分享
Akiraka 站长
文章 121评论 10
相关文章
  • Centos/Ubuntu Linux 系统 根目录扩容方法
  • 搭建 Redis 主从搭建配置
  • vim 开启关闭自动缩进
  • Centos 8 更换阿里源
  • Centos 搭建NFS服务
Akiraka
站长
本人擅长 Ai、Au、Fl、Ae、Pr、Ps 等软件的安装与卸载,精通 CSS、JavaScript、PHP、Python、Shell、Go 等单词的拼写,熟悉 Windows、Linux、Mac、Android、IOS 等系统的开关机!
121文章
10评论
47获赞
想找什么搜一下
文章聚合
ubuntu 搭建NFS服务
1年前
使用 Docker 部署 LNMP 环境
1年前
MAC 安装Pyenv-virualemv
1年前
Kubeadm 更改NodePort端口范围
11月前
Mysql增量备份脚本
1年前
微信小程序
微信小程序
标签云
brew cdh centos cmd docker docker compose elasticsearch elk filebase filebeat gitlab grafana hadoop helm hive hue jdk jenkins k8s kibana kubernetes liniux linux logstash mac mikrotik mydumper mysql nfs nginx openssl oss php pip pyspark python RabbitMQ redis rocketmq shell Spark ubuntu windows ZooKeeper 容器编排
Copyright © 2019-2021 Akiraka. Designed by nicetheme. 沪18036911号