修改后的php示例代码!

<?php
/**
* wechat php test
*/ //define your token
define("TOKEN", "wechatbyzp");
$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
/**
* wechat php test
*/ //define your token
define("TOKEN", "wechatbyzp");
$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;
}
}
} ?>

wechat开发笔记之1.接口示例代码的更多相关文章

  1. EasyNVR网页Chrome无插件播放摄像机视频功能二次开发之云台控制接口示例代码

    随着多媒体技术和网络通信技术的迅速发展,视频监控技术在电力系统.电信行业.工业监控.工地.城市交通.水利系统.社区安防等领域得到越来越广泛的应用.摄像头直播视频监控通过网络直接连接,可达到的世界任何角 ...

  2. wechat开发笔记之1.线上环境搭建与测试

    Wechat开发笔记 线上环境搭建: 申请一个wechat公众平台. 手机个人微信可以用webwechat来测试. Website:https://web.weixin.qq.com/ 手机客户端扫一 ...

  3. EasyNVR网页H5无插件播放摄像机视频功能二次开发之直播通道接口保活示例代码

    背景需求 随着雪亮工程.明厨亮灶.手机看店.智慧幼儿园监控等行业开始将传统的安防摄像头进行互联网.微信直播,我们知道摄像头直播的春天了.将安防摄像头或NVR上的视频流转成互联网直播常用的RTMP.HT ...

  4. redis 学习笔记(2)-client端示例代码

    redis提供了几乎所有主流语言的client,java中主要使用二种:Jedis与Redisson 一.Jedis的使用 <dependency> <groupId>redi ...

  5. java对接申通下单接口示例代码

    上面是控制台示例代码 public class Sample{ private final static String URL = "http://order.sto-express.cn: ...

  6. java开发笔记——表映射实体类代码示例

    package com.special.ipmsdm; import java.io.Serializable; import javax.persistence.Column; import jav ...

  7. Android开发笔记之《特斯拉-Tesla 代码分析》

    转载请注明出处 一.反编译APK文件,查看包结构 // Android库,不多解释android.support // HttpClient 4.1 repackaged for Android // ...

  8. 【搜索引擎Jediael开发笔记】v0.1完整代码

    详细代码请见 E:\Project\[重要]归档代码\SearchEngine归档代码 或 https://code.csdn.net/jediael_lu/jediael/tree/10991c83 ...

  9. 【搜索引擎Jediael开发笔记】v0.1完整代码 2014-05-26 15:17 463人阅读 评论(0) 收藏

    详细代码请见 E:\Project\[重要]归档代码\SearchEngine归档代码 或 https://code.csdn.net/jediael_lu/jediael/tree/10991c83 ...

随机推荐

  1. <c和指针>学习笔记6输入输出函数

    1 错误报告 (1)perror函数 void perror(char const *message) error是标准库的一个外部整型变量(errno.h),保存错误代码之后就会把这个信息传递给用户 ...

  2. Struts2学习第三课 Action

    action  VS  Action类 action:代表一个Struts2的请求 Action类:能够处理struts2请求的类. 属性的名字必须遵守与JavaBean属性名相同的命名规则. 属性的 ...

  3. 9. CTF综合靶机渗透(二)

    靶机说明 Welcome to the world of Acid. Fairy tails uses secret keys to open the magical doors. 欢迎来到酸的世界. ...

  4. hdu1084

    #include<iostream> #include<algorithm> using namespace std; #define N 101 struct node { ...

  5. idea中,使用facets添加完web后,项目已变为web项目,但web.xml中内容经常变为红色,并报错,如何解决?

    这中错误经常是由于配置facets并添加完web后,没有进一步配置web.xml文件,导致web.xml是使用系统默认的. 如图:需要进一步配置web.xml文件,使用我们src/main/webap ...

  6. 交叉编译Spice-gtk

    Fedora环境 编译环境 操作系统: 64位 Fedora23 下载源文件 spice-gtk.spice-protocol 安装依赖 $ sudo yum install -y dh-autore ...

  7. ElasticSearch 学习一: 基本命令

    1. 启动时指定集群和节点的名字./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_namee.g. ./elasti ...

  8. hdu6070(分数规划/二分+线段树区间更新,区间最值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意: 给出一个题目提交序列, 从中选出一个正确率最小的子串. 选中的子串中每个题目当且仅当最 ...

  9. Repeater+AspNetPager+Ajax留言板

    最近想要巩固下基础知识,于是写了一个比较简单易懂实用的留言板. 部分样式参考了CSDN(貌似最近一直很火),部分源码参照了Alexis. 主要结构: 1.前期准备 2.Repeater+AspNetP ...

  10. Clean Code之JavaScript代码示例

    译者按: 简洁的代码可以避免写出过多的BUG. 原文: JavaScript Clean Code - Best Practices 译者: Fundebug 本文采用意译,版权归原作者所有 引文 作 ...