微信,新浪云,配置php,验证
来源:互联网 发布:手机图片制作软件 编辑:程序博客网 时间:2024/04/29 16:15
<?php
header('Content-type:text');
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest;
if (!isset($_GET['echostr'])) {
$wechatObj->responseMsg();
}else{
$wechatObj->valid();
}
class wechatCallbackapiTest
{
//验证签名
public function valid()
{
$echoStr = $_GET["echostr"];
$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){
echo $echoStr;
exit;
}
}
//响应消息
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
//$this->logger("R \r\n".$postStr);
$postObj = simplexml_load_string($postStr);
$RX_TYPE = trim($postObj->MsgType);
//消息类型分离
$result = $this->receiveText($postObj);
//$this->logger("T \r\n".$result);
echo $result;
}else {
echo "";
exit;
}
}
//接收文本消息
private function receiveText($object)
{
//自动回复模式
//$content = date("Y-m-d H:i:s",time())."\n\n".'<a href="http://m.cnblogs.com/?u=txw1958">技术支持 uuuuuu</a>';
$content = $object->FromUserName." ".$object->ToUserName;
$result = $this->transmitText($object, $content);
return $result;
}
//回复文本消息
private function transmitText($object, $content)
{
$xmlTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$result = sprintf($xmlTpl, $object->FromUserName, $object->ToUserName, time(), $content);
return $result;
}
}
?>
header('Content-type:text');
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest;
if (!isset($_GET['echostr'])) {
$wechatObj->responseMsg();
}else{
$wechatObj->valid();
}
class wechatCallbackapiTest
{
//验证签名
public function valid()
{
$echoStr = $_GET["echostr"];
$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){
echo $echoStr;
exit;
}
}
//响应消息
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
//$this->logger("R \r\n".$postStr);
$postObj = simplexml_load_string($postStr);
$RX_TYPE = trim($postObj->MsgType);
//消息类型分离
$result = $this->receiveText($postObj);
//$this->logger("T \r\n".$result);
echo $result;
}else {
echo "";
exit;
}
}
//接收文本消息
private function receiveText($object)
{
//自动回复模式
//$content = date("Y-m-d H:i:s",time())."\n\n".'<a href="http://m.cnblogs.com/?u=txw1958">技术支持 uuuuuu</a>';
$content = $object->FromUserName." ".$object->ToUserName;
$result = $this->transmitText($object, $content);
return $result;
}
//回复文本消息
private function transmitText($object, $content)
{
$xmlTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$result = sprintf($xmlTpl, $object->FromUserName, $object->ToUserName, time(), $content);
return $result;
}
}
?>
0 0
- 微信,新浪云,配置php,验证
- 微信二次开发 新浪云应用SAE Token验证失败
- PHP微信开发新浪sea服务器提示token验证失败
- 微信接口开发,新浪云无法写入jssdk.php
- PHP微信公众平台开发:配置、微信api接入验证
- PHP微信公众平台开发:配置、微信api接入验证
- 微信开发中验证 基本配置 的token验证 及自动回复代码(PHP)
- php 新浪微博OAuth开发配置
- 关于新浪云中php和微信平台的总结
- 微信公众号新浪百度云做服务器 (上传php文件,开发微信公众平台)
- 微信开发:申请新浪云空间
- 关于 微信配置 未认证的新浪云应用SAE token认证失败的分析
- php 微信第三方登录验证
- 微信接口验证(php)
- 微信公众号+Flask+新浪SAE 配置
- PHP实现微信JsApi接口--权限验证配置参数的获取
- PHP+TP框架生成使用微信JS-SDK所需的配置信息,并验证
- php 新浪微博第三方登录验证/OAuth2.0
- spring 多数据源 ,mybatis和hibernet版本
- HDU1069——Monkey and Banana(动态规划)
- 优驾行easy
- Ubuntu14.04 + NVIDIA8.0 + cuda + cudnn + opencv 3 + matlab
- exynos4412内存分析
- 微信,新浪云,配置php,验证
- ValueError: invalid \x escape
- ROADS poj 1724(dfs + 剪枝)
- PHP延迟静态绑定
- Hbase客户端的写缓冲区和put列表
- mysqlreport使用详解
- (译)让CSS更完美:PostCSS-modules
- 40.before伪类的添加
- Spring的Assert工具类的用法