|
本帖最后由 宿海仁太 于 2014-10-18 22:57 编辑
<?php
/**
*+------------------------------------------------------------------------------
* 微信服务号通用配置类
*+------------------------------------------------------------------------------
* @author liujiebin * liujiebin's version 3.12
* @copyright Copyright (c) 2012 - 2014, AllRight By liujiebin, Studio.
* @website
* @param _initialize 自动加载
* @param token token验证
* @access public
*+------------------------------------------------------------------------------
* 开发时间: 2014 - 10 - 18
* 更新时间: 2014 - -
* 更新内容: 暂未更新
*
*/
namespace Home\Controller;
use Think\Controller;
class WeixinController extends Controller {
public function _initialize(){
session('OriginalId',"gh_ac0b5ed6d32b");
session('AppToken',"otofuturestore");
session('AppId',"验证时候不需要填写");
session('AppSecret',"验证时候不需要填写");
}
public function token(){if (isset($_GET['echostr'])) {$this->valid();}else{$this->responseMsg();}}
public function valid(){$echoStr = $_GET["echostr"];if($this->checkSignature()){echo $echoStr;exit;}}
private function checkSignature(){
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = session('AppToken');
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
public function responseMsg(){
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$RX_TYPE = trim($postObj->MsgType);
switch ($RX_TYPE){
case "text":
$resultStr = $this->receiveText($postObj);
break;
case "event":
$resultStr = $this->receiveEvent($postObj);
break;
default:
$resultStr = "";
break;
}
echo $resultStr;
}else {
echo "";
exit;
}
}
}
|
评分
-
查看全部评分
|