我的步骤如下
1、在新浪云中创建一个应用
2、在微信中下载wx_sample.zip ,其实就以一个php文件,修改文件中的Token后再次上传到新浪云应用中
3、在威信的回调模式中输入相应的参数(如下)
•URL: http://1.lcbweixin.sinaapp.com/lcbweixin.php
•Token: lcbweixin
•EncodingAESKey: (随机生成)
提交校验后提示我echosstr校验错误,请问这么怎么处理 ?????、
我下载并编辑的PHP文件代码如下:
<?php
/**
* wechat php test
*/
//define your token
define("TOKEN", "lcbweixin");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//extract post data
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";
if(!empty( $keyword ))
{
$msgType = "text";
$contentStr = "Welcome to wechat world!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}else{
echo "Input something...";
}
}else {
echo "";
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}
?>
10 个解决方案
#1
同问。。。。
#2
哥们儿,解决了记得通知我一声,多谢了
#3
public function vaild(){
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
if($sVerifyEchoStr){
$sEchoStr = "";// 需要返回的明文
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
print($sEchoStr);
} else {
print("ERR1: " . $errCode . "\n\n");
}
exit;
}
}
这是我的代码,已经实现功能,你可以试试。
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
if($sVerifyEchoStr){
$sEchoStr = "";// 需要返回的明文
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
print($sEchoStr);
} else {
print("ERR1: " . $errCode . "\n\n");
}
exit;
}
}
这是我的代码,已经实现功能,你可以试试。
#4
我也遇到这样的问题 别沉
#5
你这是验证微信订阅号和服务号的,这是微信企业号,经过加密的,你需要先解密!你可以参考http://blog.csdn.net/k8080880/article/details/40342929
#6
哥们,我只能告诉你,你的代码是服务号的,不是企业号接口的代码,
但是我遇到的问题跟你一样。
但是我遇到的问题跟你一样。
#7
楼主你这个问题解决了么...
#8
<?php
include_once '../qiyehao/weixinPHP/WXBizMsgCrypt.php';
$token = "sbao";
$encodingAesKey = "aVeADrhHlb8GBniQXqOFveeyIWdWUHYhpSifqHiCMyD";
$corpId = "---------------------------";
if (isset($_GET['echostr'])) {
$sVerifyMsgSig = ($_GET['msg_signature']);
$sVerifyTimeStamp = ($_GET['timestamp']);
$sVerifyNonce = ($_GET['nonce']);
$sVerifyEchoStr = ($_GET['echostr']);
$sEchoStr = "";
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
echo $sEchoStr;
} else {
echo (date("Y-m-d H:i:s") . " ERR : " . $errCode);
}
}
?>
include_once '../qiyehao/weixinPHP/WXBizMsgCrypt.php';
$token = "sbao";
$encodingAesKey = "aVeADrhHlb8GBniQXqOFveeyIWdWUHYhpSifqHiCMyD";
$corpId = "---------------------------";
if (isset($_GET['echostr'])) {
$sVerifyMsgSig = ($_GET['msg_signature']);
$sVerifyTimeStamp = ($_GET['timestamp']);
$sVerifyNonce = ($_GET['nonce']);
$sVerifyEchoStr = ($_GET['echostr']);
$sEchoStr = "";
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
echo $sEchoStr;
} else {
echo (date("Y-m-d H:i:s") . " ERR : " . $errCode);
}
}
?>
#9
include_once '../qiyehao/weixinPHP/WXBizMsgCrypt.php';
下载地址 是:
http://qydev.weixin.qq.com/download/php.zip
下载地址 是:
http://qydev.weixin.qq.com/download/php.zip
#10
获得的参数要解码才能用
#1
同问。。。。
#2
哥们儿,解决了记得通知我一声,多谢了
#3
public function vaild(){
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
if($sVerifyEchoStr){
$sEchoStr = "";// 需要返回的明文
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
print($sEchoStr);
} else {
print("ERR1: " . $errCode . "\n\n");
}
exit;
}
}
这是我的代码,已经实现功能,你可以试试。
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
if($sVerifyEchoStr){
$sEchoStr = "";// 需要返回的明文
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
print($sEchoStr);
} else {
print("ERR1: " . $errCode . "\n\n");
}
exit;
}
}
这是我的代码,已经实现功能,你可以试试。
#4
我也遇到这样的问题 别沉
#5
你这是验证微信订阅号和服务号的,这是微信企业号,经过加密的,你需要先解密!你可以参考http://blog.csdn.net/k8080880/article/details/40342929
#6
哥们,我只能告诉你,你的代码是服务号的,不是企业号接口的代码,
但是我遇到的问题跟你一样。
但是我遇到的问题跟你一样。
#7
楼主你这个问题解决了么...
#8
<?php
include_once '../qiyehao/weixinPHP/WXBizMsgCrypt.php';
$token = "sbao";
$encodingAesKey = "aVeADrhHlb8GBniQXqOFveeyIWdWUHYhpSifqHiCMyD";
$corpId = "---------------------------";
if (isset($_GET['echostr'])) {
$sVerifyMsgSig = ($_GET['msg_signature']);
$sVerifyTimeStamp = ($_GET['timestamp']);
$sVerifyNonce = ($_GET['nonce']);
$sVerifyEchoStr = ($_GET['echostr']);
$sEchoStr = "";
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
echo $sEchoStr;
} else {
echo (date("Y-m-d H:i:s") . " ERR : " . $errCode);
}
}
?>
include_once '../qiyehao/weixinPHP/WXBizMsgCrypt.php';
$token = "sbao";
$encodingAesKey = "aVeADrhHlb8GBniQXqOFveeyIWdWUHYhpSifqHiCMyD";
$corpId = "---------------------------";
if (isset($_GET['echostr'])) {
$sVerifyMsgSig = ($_GET['msg_signature']);
$sVerifyTimeStamp = ($_GET['timestamp']);
$sVerifyNonce = ($_GET['nonce']);
$sVerifyEchoStr = ($_GET['echostr']);
$sEchoStr = "";
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
echo $sEchoStr;
} else {
echo (date("Y-m-d H:i:s") . " ERR : " . $errCode);
}
}
?>
#9
include_once '../qiyehao/weixinPHP/WXBizMsgCrypt.php';
下载地址 是:
http://qydev.weixin.qq.com/download/php.zip
下载地址 是:
http://qydev.weixin.qq.com/download/php.zip
#10
获得的参数要解码才能用