01开发者--基本配置--url服务器地址---填写好--需要开通微信接口的域名 http://www.cctv.com/xxx.php文件

xxx.php文件

01参考wx_sample.php

02写上设置的token-->存入微信库中

02提交这个配置的---触发微信---获取到这个域名http://www.cctv.com/xxx.php

03微信拼接这个域名.get传递参数--请求这个域名http://www.cctv.com/xxx.php

04在xxx.php文件中,接收到微信发送过来的get参数

复制微信提供的代码-->到xxx.php到即可

wx_sample.php

<?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)){
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$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()
{
// you must define TOKEN by yourself
if (!defined("TOKEN")) {
throw new Exception('TOKEN is not defined!');
}

$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];

$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
// use SORT_STRING rule
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );

if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}

?>

开始工作----微信通过get检查当前网站---是否可用的更多相关文章

  1. 网站提供的下载IE8很慢 由于Microsoft 联机服务暂时不可用,SmartScreen筛选器无法检查此网站。

    在内网环境中,网站系统提供了一个下载功能,用ie8下载特别慢,一个20kb的文件,下载要10分钟,但是在其他环境中是很快的,试了半天,原来是:由于Microsoft 联机服务暂时不可用,SmartSc ...

  2. 我们无法找到服务器加载工作簿的数据模型"的 SharePoint 网站,当您刷新 Excel 2013 工作簿中的数据透视表时出错

    假定您使用 Analysis Services 源在 Microsoft Excel 2013 中创建数据透视表.将 Excel 工作簿上载到 Microsoft SharePoint 网站中.当您尝 ...

  3. winform执行程序报错:已停止工作,windows正在检查该问题的解决方案

    每次运行程序时都会弹出错误框:winform已停止工作,windows正在检查该问题的解决方案 事件查看器错位信息: 错误应用程序名称: TMS_winform.exe,版本: 1.0.0.0,时间戳 ...

  4. Cordova 微信分享插件,安卓亲测可用

    Cordova 微信分享插件,安卓亲测可用,收藏 https://github.com/vilic/cordova-plugin-wechat

  5. K3中间层配置不成功 kdsvrmgr组件不工作 问题 客户端需要检查的设置

    苏州K3刘保平电脑安装的K3装有中间层组件,导致中间层死配都配不成功  以后中间层配置不成功的时候除了检查能否访问K3服务器之外,还要检查一下是否安装了中间层http://wenku.baidu.co ...

  6. keepalived + lvs 网站高可用集群

    一 ,四台服务器 master 端 : 192.168.1.3 backup 端: 192.168.1.4 REserver1 端 : 192.168.1.5 REserver2 端: 192.168 ...

  7. Android 检查手机网络是否可用

    添加网络状态权限 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 代 ...

  8. 迁移桌面程序到MS Store(13)——动态检查Win10 API是否可用

    假设我们现有一个WPF程序,需要支持1903以前的Windows 10版本.同时在1903以后的版本上,额外多出一个Ink的功能.那么我们就可以通过ApiInformation.IsApiContra ...

  9. 微信小程序 scroll-view 填满剩余可用高度

    根据微信小程序 scroll-view 文档所述,scroll-view必须给定一个固定高度.那么如果我们想要让它自动填充剩余高度,该怎么办呢? 前言 在说出我的解决方案之前,先来看一下我的页面设计, ...

随机推荐

  1. svn的基本配置及安装

    1.检查是否已安装 rpm -qa subversion 如果要卸载旧版本: yum remove subversion 2.安装 yum install subversion 3.检查是否安装成功 ...

  2. ServiceContract,OperationContract

    代码如下 [ServiceContract] //服务协定定义 using System.ServiceModel; public interface IInterface1 { [Operation ...

  3. linux中找不到/etc/sysconfig/iptables

    解决办法初始化iptables. #iptables -F #service iptables save #service iptables restart

  4. jQuery切换网页皮肤并保存到Cookie示例代码

    经过使用,靠谱! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  5. js--事件对象的理解5-

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 利用H5新特性判断文件大小

    HTML代码部分: 思路:下面代码中我利用css的z-index属性将input="file”标签隐藏在了id=btnSelect元素下面,通过触发a标签的点击后,弹出文件选择框.下面的ma ...

  7. ubuntu通过tnvm安装Nodejs

    第一步,先安装tvm tnvm(Taobao Node Version Manager)淘宝Node版本管理器 安装: 直接输入 wget -O- https://raw.githubusercont ...

  8. c#.net 获取时间日期年月日时分秒格式

    今天写代码发现两个比较不错的分享下:1.DateTime.ParseExact很多时候我们获取的时间是数字形式表示的,好比20140127134015.927856,通过这个方法DateTime.Pa ...

  9. bzoj1338: Pku1981 Circle and Points单位圆覆盖

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1338 1338: Pku1981 Circle and Points单位圆覆盖 Time ...

  10. 浙大pat1042题解

    1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...