您好,欢迎访问一九零五行业门户网

用过微信公众账号的要小心了

新用户订阅,将由之前推送一条“hello2bizuser”文本,变化为推送一条“subscribe”的事件。
这个在php里怎么写啊,我现在有一个公众账号,可是别人关注我后,不能马上发一条消息。
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 = welcome to wechat world!; $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; } }}?>
这是微信官方的demo,求大神指教
回复讨论(解决方案) 26号 前 给你发是一段 文本 就是 xml 中 的 content 。。。
之后给你发的 时间 event 你在读取 的时候 $keyword = trim($postobj->content); 改成
$keyword = trim($postobj->event); 然后判断
恩恩 现在可以了,谢谢楼上。
responsemsg();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; $msgtype = strtolower(trim($postobj->msgtype)); if($msgtype == 'event'){ $keyword = trim($postobj->event); }else{ $keyword = trim($postobj->content); } $time = time(); $texttpl = %s 0 ; if(!empty( $keyword )) { if($keyword == 'subscribe'){ $contentstr = even; }else{ $contentstr = text; } $msgtype = text; $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; } }}?>
其它类似信息

推荐信息