当前位置:Gxlcms > PHP教程 > 求一个微信公共平台给公共号发消息成功的代码

求一个微信公共平台给公共号发消息成功的代码

时间:2021-07-01 10:21:17 帮助过:8人阅读

求一个微信公共平台给公共号发消息成功的代码
在腾讯api上的网页调试成功,但是自己用php代码post过去就不行


回复讨论(解决方案)

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 = "																					%s																					0							";             				if(!empty( $keyword ))                {              		$msgType = "text";                	$contentStr = $keyword;                	$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;		}	}}?>


直接用官方的就可以了啊

有一种开源微信管理平台叫微擎.....

人气教程排行