没看到加密的方案。我把我的贴一下,这几个函数都是官方的:
但是我无法验证通过,提示token不对。我核对了token是没错的
验证URL的部分,取信息就不贴了。
public function VerifyURL($sMsgSignature, $sTimeStamp, $sNonce, $sEchoStr, &$sReplyEchoStr){ if (strlen($this->m_sEncodingAesKey) != 43) { return JOrigin_Wechat_Model_ErrorCode::$IllegalAesKey; } $pc=Mage::getModel('jorigin_wechat/prpcrypt'); $pc->setKey($this->m_sEncodingAesKey); //verify msg_signature $array = $this->getSHA1($this->m_sToken, $sTimeStamp, $sNonce, $sEchoStr); $ret = $array[0]; if ($ret != 0) { return $ret; } $signature = $array[1]; if ($signature != $sMsgSignature) { return JOrigin_Wechat_Model_ErrorCode::$ValidateSignatureError; } $result = $pc->decrypt($sEchoStr, $this->m_sCorpid); if ($result[0] != 0) { return $result[0]; } $sReplyEchoStr = $result[1]; return JOrigin_Wechat_Model_ErrorCode::$OK;} /** * 用SHA1算法生成安全签名 * @param string $token 票据 * @param string $timestamp 时间戳 * @param string $nonce 随机字符串 * @param string $encrypt 密文消息 */public function getSHA1($token, $timestamp, $nonce, $encrypt_msg){ //排序 try { $array = array($encrypt_msg, $token, $timestamp, $nonce); sort($array, SORT_STRING); $str = implode($array); return array(JOrigin_Wechat_Model_ErrorCode::$OK, sha1($str)); } catch (Exception $e) { print $e . "\n"; return array(JOrigin_Wechat_Model_ErrorCode::$ComputeSignatureError, null); }} |
现在这个社区,有bug没解决,标记为解决真的不好,应该是提问者来标记。 腾讯要改下,不然都懒得说问题。

这个还是未加密的。
url填index的,
public function index() {
if ($this->checkSignature()) {
echo $_GET['echostr'];
} else {
echo 'error';
}
}
private function checkSignature() {
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = 'app';
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}