Home > Backend Development > PHP Tutorial > 关于微信开发模式的PHP代码,该怎么解决

关于微信开发模式的PHP代码,该怎么解决

WBOY
Release: 2016-06-13 11:55:35
Original
970 people have browsed it

关于微信开发模式的PHP代码

<?php<br />/**<br />  * wechat php test<br />  */<br /><br />//define your token<br />define("TOKEN", "weixin");<br />$wechatObj = new wechatCallbackapiTest();<br />//$wechatObj->valid();<br />$wechatObj->responseMsg();<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 />				$type =$postObj->MsgType;<br />				$customevent = $postObj->Event;<br />				$latitude =$postObj->Location_X;<br />				$longitude =$postObj->Location_Y;<br />                $keyword = trim($postObj->Content);<br />                $time = time();<br />                $textTpl = "<xml><br />							<ToUserName><![CDATA[%s]]></ToUserName><br />							<FromUserName><![CDATA[%s]]></FromUserName><br />							<CreateTime>%s</CreateTime><br />							<MsgType><![CDATA[%s]]></MsgType><br />							<Content><![CDATA[%s]]></Content><br />							<FuncFlag>0</FuncFlag><br />							</xml>";             <br />			switch($type)<br />			{<br />			case "event";<br />			if($customevent == "subscribe")<br />			{$contentStr = "感谢关注"}<br />			break;<br />			case "image"<br />			$contentStr ="图片很棒";<br />		    break;<br />			case "location";<br />			$contentStr ="{$latitude},{longitude}";<br />			break;<br />			case "text";<br />			switch($keyword)<br />			{case "1"<br />			 $contentStr="1"<br />			 break;<br />			 case "2"<br />			 $contentStr ="2"<br />			 break;<br />			 default;<br />			 $contentStr= "hi";}<br />			 break;<br />			 }<br />			 $msgType = "text";<br />			 $resultStr = sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr);<br />			 echo $resultStr;<br />			 }else             	<br />              {<br />        	echo "";<br />        	exit;<br />        }<br />    }<br />		<br />	private function checkSignature()<br />	{<br />        $signature = $_GET["signature"];<br />        $timestamp = $_GET["timestamp"];<br />        $nonce = $_GET["nonce"];	<br />        		<br />		$token = TOKEN;<br />		$tmpArr = array($token, $timestamp, $nonce);<br />		sort($tmpArr, SORT_STRING);<br />		$tmpStr = implode( $tmpArr );<br />		$tmpStr = sha1( $tmpStr );<br />		<br />		if( $tmpStr == $signature ){<br />			return true;<br />		}else{<br />			return false;<br />		}<br />	}<br />}<br /><br />?>
Copy after login

代码检查了N遍但是功能一个都不能实现 !球大神帮帮~另外怎么也做不出来微信调用百度地图来实现导航如果能一起帮助就更好了
------解决方案--------------------
public function valid()<br />    {<br />        $echoStr = $_GET["echostr"];<br /> <br />        //valid signature , option<br />        if($this->checkSignature()){<br />            echo $echoStr;<br />            exit;<br />        }<br />    }
Copy after login
这代码是为了填写url 通过验证, 通过之后 ,可以把这个代码改了。如改成

public function valid()<br>    {<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template