admin 管理员组文章数量: 1086019
2024年4月24日发(作者:oracle数据备份命令)
微信公众平台接口开发验证程序
URL
、
TOKEN
认证
2
种方式
成为开发者的第一步就是填写URL、TOKEN信息,来对你服务器进行验证
1)把下面代码复制并保存为一个php文件(如)
/**
*wechatphptest
*/
//defineyourtoken
define("TOKEN","weixin");
$wechatObj=newwechatCallbackapiTest();
$wechatObj->valid();
classwechatCallbackapiTest
{
publicfunctionvalid()
{
$echoStr=$_GET["echostr"];
//validsignature,option
if($this->checkSignature()){
echo$echoStr;
exit;
}
}
publicfunctionresponseMsg()
{
//getpostdata,Maybeduetothedifferentenvironments
$postStr=$GLOBALS["HTTP_RAW_POST_DATA"];
//extractpostdata
if(!empty($postStr)){
$postObj=simplexml_load_string($postStr,
LIBXML_NOCDATA);
'SimpleXMLElement',
$fromUsername=$postObj->FromUserName;
$toUsername=$postObj->ToUserName;
$keyword=trim($postObj->Content);
$time=time();
$textTpl="
";
if(!empty($keyword))
{
$msgType="text";
$contentStr="Welcometowechatworld!";
$resultStr=sprintf($textTpl,$fromUsername,$toUsername,$time,
$msgType,$contentStr);
echo$resultStr;
}else{
";
}
}else{
echo"";
exit;
}
}
privatefunctioncheckSignature()
{
$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){
returntrue;
}else{
版权声明:本文标题:微信开发者验证方法及程序 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1713963429a659554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论