<?php
namespace?Home\Controller;
use?Think\Controller;
class?IndexController?extends?Controller?{
????
????public?function?index(){
???????
}
?
??public?function?check()
{??????????????????
????????????????/**
??????????????????*?wechat?php?test
??????????????????*/
????????????????
????????????????//define?your?token
????????????????define("TOKEN",?"weixin");
??????$this->valid();
}
?????????????????public?function?valid()
????????????????????{
????????????????????????$echoStr?=?$_GET["echostr"];
????????????????
????????????????????????//valid?signature?,?option
????????????????????????if($this->checkSignature()){
????????????????????????????echo?$echoStr;
????????????????????????????exit;
????????????????????????}
????????????????????}
????????????????
????????????????????????
????????????????????public?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;
????????????????????????}
????????????????????}
}
?>微信公眾平臺那邊填寫是沒有錯的,我懷疑是代碼的問題,我用的是thinkphp,服務(wù)器用新浪云。一直提示驗證失敗。大家能幫我看下是什么問題嗎,非常感謝!
接入微信的時候TOKEN驗證失敗
qq_學(xué)渣君_0
2016-10-11 15:15:45