微信服务器配置Token验证失败问题
目前存放平台系统配置新服务号token验证一直不成功,写其他测试服务器路径可以成功.验证返回值也有,问题可能出在微信服务器响应者一块 求吊大的给个解释?tell me why?
下面是源码及日志截图
class WxapiAction extends Action {
public $wxcode ='';
public $wxconfig =array();
public $opensession =array();
public $dbprefix="";
function _initialize() {
ob_clean();
$this->dbprefix=C('DB_PREFIX');
//判断是否获取当前微信用户的基本信息
//session_destroy();
if(session("wxcode")){
$wxcode=session('wxcode');
$sessions=$wxcode."_openid";
$this->opensession= (array)session($sessions);
$this->wxconfig= $this->opensession['wxconfig'];
$this->wxcode= $this->wxconfig['num'];
$rows=M("wxconfig")->field("a.*,m.*")->alias("a")->join(C('DB_PREFIX')."info m on a.tenantcode=m.tenantcode")->where("num='".$this->wxcode."'")->find();
$theme=$this->wxconfig['theme'];
if($theme!=$rows['theme']){
$_SESSION[$sessions]['wxconfig']=$rows;
}
if(empty($this->opensession['openid'])||empty($this->wxconfig['theme']))
{
unset($_SESSION[$sessions]);
unset($_SESSION["wxconfig"]);
}
}
else{
//如果也不带参数,第一次访问授权
$code = $_GET['code'];
$wxcode = $_GET['wxc']; pre($code."|".$wxcode);//die;
//开启pc端(1)
//$wxcode= APP_DEBUG?'klclub168':$wxcode;
if(empty($wxcode)){
$this->logger("微信设置参数错误");
$this->redirect ("App/Services/Error",array("msg"=>urldecode("微信设置参数错误")));
exit;
}
$this->wxcode=$wxcode;
$this->wxconfig= $this->getwxconfig($wxcode);
//是否获取到微信帐号信息
if($code){
$this->getwxopenid();
$sessions=$wxcode."_openid";
$this->opensession= (array)session($sessions);
}
else{
//没有code,则拉起授权,请求授权
$appid=$this->wxconfig['appid'];
$rand_num=rand(20,'0123456789');
$redirect_uri=C("WEBURL").U('App/Wxredirect/code');
$url_now="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".urlencode($redirect_uri)."&response_type=code&scope=snsapi_userinfo&state=".$wxcode."_".$rand_num."#wechat_redirect";pre($_SESSION);pre($url_now);//die;
header("Location: $url_now");
}
//开启pc端(2)
}
//echo $this->wxconfig['tenantcode'];
//pre($_SESSION);die;
// echo $this->wxcode.'<br/>';
// echo $_SESSION['openid']['openid'];
// pre($_SESSION);
// pre($this->opensession);die;
$count=M('visit')->where("data='".date('Y-m-d 00:00:00')."'")->select();
if($count[0]['data']!==date('Y-m-d 00:00:00')){
$where['count']=1;
$where['data']=date('Y-m-d 00:00:00');
$where['tenantcode']=$this->wxconfig['tenantcode'];
$r=M('visit')->add($where);
}else{
$where['id']=$count[0]['id'];
$where['count']=$count[0]['count']+1;
$where['data']=date('Y-m-d 00:00:00');
$r=M('visit')->save($where);
}
$ceurl=C("WEBURL")."/".APP_NAME."/Tpl/";
$this->assign("tpl", $ceurl);
//地址目录资源模板路径
$sourceurl=C("WEBURL")."/".APP_NAME."/Tpl/App/".$this->wxconfig['theme'];
$this->assign("sourceurl", $sourceurl);
$this->assign("wxcode", $this->wxcode);
}
//菜单验证
public function verifyurl($url='')
{
if(empty($this->wxcode)|| empty($url))
{
$api =C('WEBURL').'/index.php/App/Services/Error';
header("Location:$api");
exit;
}
$ret=$this->wxconfig;
$api = $url;
if (!isset($_SESSION['openid']) ) {
$urlU = urlencode($url);
$api = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$ret['appid']."&redirect_uri=".$urlU."&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
}
header("Location:$api");
}
//验证签名
public function valid($ary){
$echoStr = isset($_GET["echostr"])?$_GET["echostr"]:$_POST['echostr'];
$signature = isset($_GET["signature"])?$_GET["signature"]:$_POST['signature']; //$_GET["signature"];
$timestamp = isset($_GET["timestamp"])?$_GET["timestamp"]:$_POST['timestamp']; //$_GET["timestamp"];
$nonce = isset($_GET["nonce"])?$_GET["nonce"]:$_POST['nonce']; //$_GET["nonce"];
$token = $ary['token']; //是开发应用设置的token值
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr,SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
$ret=array('str'=>$tmpStr,'c'=>$signature,'s'=>$tmpArr,'o'=>$echoStr);
$this->logger("验证".json_encode($ret));
if($tmpStr == $signature){
echo $echoStr;
exit();
}
}
class IndexAction extends WxapiAction {
function _initialize() {
parent::_initialize ();
}
public function index(){
$echoStr = isset($_GET["echostr"])?$_GET["echostr"]:$_POST['echostr'];
//$this->logger($echoStr."-token验证|".json_encode($this->wxconfig));
if (isset($_GET['echostr'])) {
$this->valid($this->wxconfig);
}else{
$this->responseMsg();
}
}
![图片描述][1]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论