首页 > 作文

php的微信公众平台开发接口类

更新时间:2023-04-07 06:59:51 阅读: 评论:0

<?phpdefine("token", "weixin");$wechatobj = new wechatcallbackapitest();if (!ist($_get['echostr'])) {$wechatobj->responmsg();}el{$wechatobj->valid();}class wechatcallbackapitest{//验证消息public function valid(){$echostr = $_get["echostr"];if($this->checksignature()){echo $echostr;exit;}}//检查签名private function checksignature(){$signature = $_get["signature"];$timestamp = $_get["timestamp"];$nonce = $_get["nonce"];$token = token;$tmparr = array($token, $timestamp, $nonce);sort($tmparr, sort_string);$tmpstr = implode($tmparr);$tmpstr = sha1($tmpstr);if($tmpstr == $signature){return true;}el{return fal;}}//响应消息public function responmsg(){$poststr = $globals["http_raw_post_data"];if (!empty($poststr)){$this->logger("r ".$poststr);$postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata);$rx_type = trim($postobj->msgtype);switch ($rx_type){ca "event":$result = $this->receiveevent($postobj);break;ca "text":$result = $this->receivetext($postobj);break;ca "image":$result = $this->receiveimage($postobj);break;ca "location":$result = $this->receivelocation($postobj);break;ca "voice":$result = $this->receivevoice($postobj);break;ca "video":$result = $this->receivevideo($postobj);break;ca "link":$result = $this->receivelink($postobj);break;default:$result = "unknow msg type: ".$rx_type;break;}$this->logger("t ".$result);echo $result;}el {echo "";exit;}}//接收事件消息private function receiveevent($object){$content = "";switch ($object->event){ca "subscribe":$content = "欢迎关注方倍工作室 ";$content .= (!empty($object-&安全模式进不去gt;eventkey))?("\n来自二维码场景 ".str_replace("qrscene_","",$object->eventkey)):"";break;ca "unsubscribe":$content = "取消关注";break;ca "scan":$content = "扫描场景 ".$object->eventkey;break;ca "click":switch ($object->eventkey){ca "company":$content = "方倍工作室提供互联网相关产品与服务。";break;default:$content = "点击菜单:".$object->eventkey;break;}break;ca "location":$content = "上传位置:纬度 ".$object->latitude.";经度 ".$object->longitude;break;ca "view":$content 大雪 节气= "跳转链接 ".$object->eventkey;break;default:$content = "receive a new event: ".$object->event;break;}$result = $this->transmittext($object, $content);return $result;}//接收文本消息private function receivetext($object){switch ($object->content){ca "文本":$content = "这是个文本消息";break;ca "图文":ca "单图文":$content = array();$content[] = array("title"=>"单图文标题",  "description"=>"单图文内容", "picurl"=>"/d/file/titlepic/cartoon.jpg", "url" =>"/d/file/titlepic/u=txw1958%22);break;ca "多图文":$content = array();$content[] = array("title"=>"多图文1标题", "description"=>"", "picurl"=>"/d/file/titlepic/cartoon.jpg", "url" =>"/d/file/titlepic/u=txw1958%22);$content%5B%5D = array("title"=>"多图文2标题", "description"=>"", "picurl"=>"/d/file/titlepic/f3529822720e0cf3ac9f1ada0846f21fbe09aaa3.png "url" =>"/d/file/titlepic/u=txw1958%22);$content%5B%5D = array("title"=>"多图文3标题", "description"=>"", "picurl"=>"/d/file/titlepic/18cb0a46f21fbe090d338acc6a600c338644adfd.png "url" =>"/d/file/titlepic/u=txw1958%22);break;ca "音乐":$content = array("title"=>"最炫民族风", "description"=>"歌手:凤凰传奇", "musicurl"=>"http://121.199.4.61/music/zxmzf.mp3", "hqmusicurl"=>"http://121.199.4.61/music/zxmzf.mp3");break;default:$content = date("y-m-d h:i:s",time());break;}if(is_array($content)){if (ist($content[0]['picurl'])){$result = $this->transmitnews($object, $content);}el if (ist欧沃顿桥($content['musicurl'])){$result = $this->transmitmusic($object, $content);}}el{$result = $this->transmittext($object, $content);}return $result;}private function receiveimage($object){$content = array("mediaid"=>$object->mediaid);$result = $this->transmitimage($object, $content);return $result;}private function receivelocation($object){$content = "你发送的是位置,纬度为:".$object->location_x.";经度为:".$object->location_y.";缩放级别为:".$object->scale.";位置为:".$object->label;$result = $this->transmittext($object, $content);return $result;}private function receivevoice($object){if (ist($object->recognition) && !empty($object->recognition)){$content = "你刚才说的是:".$object->recognition;$result = $this->transmittext($object, $content);}el{$content = array("mediaid"=>$object->mediaid);$result = $this->transmitvoice($object, $content);}return $result;}private function receivevideo($object){$content = array("mediaid"=>$object->mediaid, "thumbmediaid"=>$object->thumbmediaid, "title"=>"", "description"=>"");$result = $this->transmitvideo($object, $content);return $result;}private function receivelink($object){$content = "你发送的是链接,标题为:".$object->title.";内容为:".$object->description.";链接地址为:".$object->url;$result = $this->transmittext($object, $content);return $result;}private function transmittext($object, $content){$texttpl = "<xml><tourname><![cdata[%s]]></tourname><fromurname><![cdata[%s]]></fromurname><createtime>%s</createtime><msgtype><![cdata[text]]></msgtype><content><![cdata[%s]]></content></xml>";$result = sprintf($texttpl, $object->fromurname, $object->tourname, time(), $content);return $result;}private function transmitimage($object, $imagearray){$itemtpl = "<image><mediaid><![cdata[%s]]></mediaid></image>";$item_str = sprintf($itemtpl, $imagearray['mediaid']);$texttpl = "<xml><tourname><![cdata[%s]]></tourname><fromurname><![cdata[%s]]></fromurname><createtime>%s</createtime><msgtype><![cdata[image]]></msgtype>$item_str</xml>";$result = sprintf($texttpl, $object->fromurname, $object->tourname, time());return $result;}private function transmitvoice($object, $voicearray){$itemtpl = "<voice><mediaid><![cdata[%s]]></mediaid></voice>";$item_str = sprintf($itemtpl, $voicearray['mediaid']);$texttpl = "<xml><tourname><![cdata[%s]]></tourname><fromurname><![cdata[%s]]></fromurname><createtime>%s</createtime><msgtype><![cdata[voice]]></msgtype>$item_str</xml>";$result = sprintf($texttpl, $object->fromurname, $object->tourname, time());return $result;}private function transmitvideo($object, $videoarray){$itemtpl = "<video><mediaid><![cdata[%s]]></mediaid><thumbmediaid><![cdata[%s]]></thumbmediaid><title><![cdata[%s]]></title><description><![cdata[%s]]></description></video>";$item_str = sprintf($itemtpl, $videoarray['mediaid'], $videoarray['thumbmediaid'], $videoarray['title'], $videoarray['description']);$texttpl = "<xml><tourname><![cdata[%s]]></tourname><fromurname><![cdata[%s]]></fromurname><createtime>%s</createtime><msgtype><![cdata]></msgtype>$item_str</xml>";$result = sprintf($texttpl, $object->fromurname, $object->tourname, time());return $result;}private function transmitnews($object, $newsarray){if(!is_array($newsarray)){return;}$itemtpl = "    <item><title><![cdata[%s]]></title><description><![cdata[%s]]></description><picurl><![cdata[%s]]></picurl><url><![cdata[%s]]></url></item>";$item_str = "";foreach ($newsarray as $item){$item_str .= sprintf($itemtpl, $item['title'], $item['description'], $item['picurl'], $item['url']);}$newstpl = "<xml><tourname><![cdata[%s]]></tourname><fromurname><![cdata[%s]]></fromurname><createtime>%s</createtime><msgtype><![cdata[news]]></msgtype><content><![cdata[]]></content><articlecount>%s</articlecount><articles>$item_str</articles></xml>";$result = sprintf($newstpl, $object->fromurname, $object->tourname, time(), count($newsarray));return $result;}private function transmitmusic($object, $musicarray){$itemtpl = "<music><title><![cdata[%s]]></title><descriptio养两只狗必死一只n><![cdata[%s]]></description><musicurl><![cdata[%s]]></musicurl><hqmusicurl><![cdata[%s]]></hqmusicurl></music>";$item_str = sprintf($itemtpl, $musicarray['title'], $musicarray['description'], $musicarray['musicurl'], $musicarray['hqmusicurl']);$texttpl = "<xml><tourname><![cdata[%s]]></tourname><fromurname><![cdata[%s]]></fromurname><createtime>%s</createtime><msgtype><![cdata[music]]></msgtype>$item_str</xml>";$result = sprintf($texttpl, $object->fromurname, $object->tourname, time());return $result;}private function logger($log_content){if(ist($_rver['http_appname'])){   //saesae_t_display_errors(fal);sae_debug($log_content);sae_t_display_errors(true);}el if($_rver['remote_addr'] != "127.0.0.1"){ //local$max_size = 10000;法国英文怎么说$log_filename = "log.xml";if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}file_put_contents($log_filename, date('h:i:s')." ".$log_content."\r\n", file_append);}}}?>

本文发布于:2023-04-07 06:57:31,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/b219772e8655fc71fcfb9e76ffeed3f6.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:php的微信公众平台开发接口类.doc

本文 PDF 下载地址:php的微信公众平台开发接口类.pdf

标签:的是   多图   消息   标题
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图