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="

%s

0

";

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{


本文标签: 保存 验证 开发者 填写 接口