>  기사  >  백엔드 개발  >  微信调试有关问题

微信调试有关问题

WBOY
WBOY원래의
2016-06-13 12:12:441142검색

微信调试问题
微信回复关键字  服务器接收    这里的逻辑怎么输出?? 比方说我收到了 xml数据 然后输出 但有时候我这里需要写个数组 然后输出 怎么做

如果写入文件和数据库表只能输出xml和字符串 不能输出数组  
------解决思路----------------------

<?php <br />define("TOKEN", "bjcy");#这里定义你留下的tooken<br />#这里是你定义好的消息回复<br />$default="";<br /><br />$address="http://www.bjcy07.com";<br />#这里是规则,判断用户发送过来的信息所包含的关键字,你可以定义更多,这里只是一个教程<br />$rule=Array("竞猜","竞猜送话费","送话费","竞猜白银");<br />#初始化<br />$Msg = new Msg();<br />$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];<br />$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);<br />$fromUsername = $postObj->FromUserName;<br />$toUsername = $postObj->ToUserName;<br />$keyword = trim($postObj->Content);<br />$key=$Msg->match($rule,$keyword);<br />#循环开始,判断用户所发送过来的消息,参数作用在下面的方法介绍里面<br />	switch ( $key )<br />	{<br /><br />		<br />		case "竞猜":<br />		$Msg->picMsg($fromUsername,$toUsername,"合创盈丰上线有礼:免费竞猜四位数,就中话费300元!","http://www.hcyf07.com/weixin/sdd2.jpg",'竞猜',"http://www.hcyf07.com");<br />		exit();<br />		<br />	<br />		<br />		case "竞猜送话费":<br />		$Msg->picMsg($fromUsername,$toUsername,"合创盈丰上线有礼:免费竞猜四位数,就中话费300元!","http://www.hcyf07.com/weixin/sdd2.jpg",'竞猜送话费',"http://www.hcyf07.com");<br />		exit();<br />		<br />		<br />		case "送话费":<br />		$Msg->picMsg($fromUsername,$toUsername,"合创盈丰上线有礼:免费竞猜四位数,就中话费300元!","http://www.hcyf07.com/weixin/sdd2.jpg",'送话费',"http://www.hcyf07.com");<br />		exit();<br />		<br />		case "竞猜白银":<br />		$Msg->picMsg($fromUsername,$toUsername,"合创盈丰上线有礼:免费竞猜四位数,就中话费300元!","http://www.hcyf07.com/weixin/sdd2.jpg",'竞猜白银',"http://www.hcyf07.com");<br />		exit();<br />		<br />		<br />		default:<br />		$Msg->txtMsg($fromUsername,$toUsername,$default);<br />	}<br /><br /><br />if(!empty( $keyword ))  <br />                {  <br />          <br />                $msgType = "text";  <br />        //入库试一下  <br />   <br />        //在这里可以判断接收到的keyword  <br />                      <br />                echo $resultStr;  <br />            }else{  <br />            if($event=="subscribe"){//首次关注  <br />                     $msgType = "text";  <br />                     $url = "http://www.bjcy07.com/";  <br />                     $contentStr = "您好,感谢关北京合创盈丰商品经营有限公司,北京合创盈丰商品经营有限公司是北京大宗商品交易所会员单位(会员席位号为007号),以现货白银等贵金属的销售、回购为主要经营项目,实行24小时买卖报价交易,同时提供贵金属投资咨询服务。".$url;  <br />                     $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);  <br />                    echo  $resultStr;  <br />                      <br />                }  <br />                echo "Input something...";  <br />            }  <br /><br />/* class of msg */<br />class Msg<br />{ <br /> public function valid()<br />    {<br />        $echoStr = $_GET["echostr"];<br />        //valid signature , option<br />        if($this->checkSignature()){<br />         echo $echoStr;<br />         exit;<br />        }<br />    }<br />	#依次为 来源用户,发送到用户,时间,标题,图片地址,简介,点击微信消息时候的链接,当然你可以修改这个顺序<br />    function picMsg($fromUsername,$toUsername,$title,$PicUrl,$Discription,$Url)<br />    {<br />		//get post data, May be due to the different environments<br />		$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];<br />			$time = time();<br />			$textTpl = "<xml> <br />			<ToUserName><![CDATA[%s]]></ToUserName> <br />			<FromUserName><![CDATA[%s]]></FromUserName> <br />			<CreateTime>%s</CreateTime> <br />			<MsgType><![CDATA[news]]></MsgType> <br />			<Content> </Content> <br />			<ArticleCount>1</ArticleCount> <br />			<Articles> <br />			<item><Title><![CDATA[%s]]></Title> <br />			<Discription><![CDATA[%s]]></Discription> <br />			<PicUrl><![CDATA[%s]]></PicUrl> <br />			<Url><![CDATA[%s]]></Url></item> <br />			</Articles> <br />			<FuncFlag>1</FuncFlag> <br />			</xml> ";    <br />				$resultStr = sprintf($textTpl,$fromUsername,$toUsername,$time,$title,$Discription,$PicUrl,$Url);<br />				echo $resultStr;<br />	}<br />		<br />	<br />	function txtMsg($fromUsername,$toUsername,$contentStr) <br />	{ <br />		$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; <br />			$time = time(); <br />			$textTpl = "<xml> <br />			<ToUserName><![CDATA[%s]]></ToUserName> <br />			<FromUserName><![CDATA[%s]]></FromUserName> <br />			<CreateTime>%s</CreateTime> <br />			<MsgType><![CDATA[text]]></MsgType> <br />			<Content><![CDATA[%s]]></Content> <br />			<FuncFlag>0<FuncFlag> <br />			</xml>"; <br />			$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $contentStr); <br />			echo $resultStr; <br />			<br />	}<br />  <br />	private function checkSignature()<br />	{<br />		$signature = $_GET["signature"];<br />		$timestamp = $_GET["timestamp"];<br />		$nonce = $_GET["nonce"]; <br />		$token = TOKEN;<br />		$tmpArr = array($token, $timestamp, $nonce);<br />		sort($tmpArr);<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 />	function match($rule,$keyword){ <br />		$num=count($rule)+1; <br />		for($i=0;$i<$num;$i++){ <br />			if( preg_match( "/$rule[$i]/",$keyword ) ){<br />				return $rule[$i];<br />				exit();<br />			}<br />		} <br />	} <br />	<br />} ?>

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.