首頁 >後端開發 >php教程 >微信大众平台接口

微信大众平台接口

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-13 11:26:18936瀏覽

微信公众平台接口

<?php <br />/**<br>  * wechat php test<br>  */<br><br>//define your token<br>define("TOKEN", "qianshou");<br>$wechatObj = new wechatCallbackapiTest();<br>$wechatObj->valid();<br>$wechatObj->responseMsg();<br><br>class wechatCallbackapiTest<br>{<br>	public function valid()<br>    {<br>        $echoStr = $_GET["echostr"];<br><br>        //valid signature , option<br>        if($this->checkSignature()){<br>        	echo $echoStr;<br>        	exit;<br>        }<br>    }<br><br>    public function responseMsg()<br>    {<br>		//get post data, May be due to the different environments<br>		$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];<br><br>      	//extract post data<br>		if (!empty($postStr)){<br>                <br>              	$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);<br>                $fromUsername = $postObj->FromUserName;<br>                $toUsername = $postObj->ToUserName;<br>                $keyword = trim($postObj->Content);<br>                $time = time();<br>                $textTpl = "<xml><br>							<tousername></tousername><br>							<fromusername></fromusername><br>							<createtime>%s</createtime><br>							<msgtype></msgtype><br>							<content></content><br>							<funcflag>0</funcflag><br>							</xml>";             <br>				if(!empty( $keyword ))<br>                {<br>              		$msgType = "text";<br>                	$contentStr = "Welcome to wechat world!";<br>                	$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);<br>                	echo $resultStr;<br>                }else{<br>                	echo "Input something...";<br>                }<br><br>        }else {<br>        	echo "qianshouerror";<div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn