微信公众号后台PHP源代码.doc_第1页
微信公众号后台PHP源代码.doc_第2页
微信公众号后台PHP源代码.doc_第3页
微信公众号后台PHP源代码.doc_第4页
微信公众号后台PHP源代码.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

.responseMsg(); class wechatCallbackapiTest private $app_id; private $app_secret; public function valid() $echoStr = $_GETechostr; /valid signature , option if($this-checkSignature() ob_clean(); echo $echoStr; exit; function txt($fu,$tu,$content,$flag = 0) $tpl=.$_SERVERREQUEST_TIME.$flag.; echo $tpl; function news($fu,$tu,$data,$flag = 0) $num=count($data); if($num 1) $add = $this-news_add($data); $tpl = .$_SERVERREQUEST_TIME. .$num. .$add. .$flag. ; echo $tpl; else $tpl = .$_SERVERREQUEST_TIME. 1 .$flag. ; echo $tpl; function news_add($data) $add=; foreach ($data as $k) $add.= ; return $add; /* function audio($fu,$tu,$data,$flag = 0) $tpl= .$_SERVERREQUEST_TIME. .$flag. ; echo $tpl; */ function audio($fu,$tu,$data,$flag = 0) $num=count($data); if($num 1) $add = $this-audio_add($data); $tpl = .$_SERVERREQUEST_TIME. .$num. .$add. .$flag. ; echo $tpl; else $tpl = .$_SERVERREQUEST_TIME. 1 .$flag. ; echo $tpl; function audio_add($data) $add=; foreach ($data as $k) $add.= ; return $add; public function receiveEvent($object) $contentStr = ok!; $fu = (string)$object-FromUserName; /取出用户的账号 $tu = (string)$object-ToUserName; /公众账号 txt($fu,$tu,begin receiveEvent,0); /* switch ($object-Event) case subscribe: $contentStr = 欢迎关注清华纸飞机传媒; break; case unsubscribe: break; case CLICK:/ $postObj-EventKey; txt($fu,$tu,回复数字050课程号,收听机灵狗英文启蒙课程); switch ($object-EventKey) case leve0: txt($fu,$tu,回复数字050课程号,收听机灵狗英文启蒙课程); /$contentStr = array(Title =机灵狗启蒙英文读物, /Description =输入数字150,听取课程, /PicUrl =/weixin/weather/icon/cartoon.jpg, /Url =weixin:/addfriend/pondbaystudio); break; case leve1: $contentStr = array(Title =机灵狗启蒙英文读物, Description =输入数字150,听取课程, PicUrl =/weixin/weather/icon/cartoon.jpg, Url =http:/bbs.binguo.me); break; default: $contentStr = array(Title =默认菜单回复, Description =您正在使用的是自定义菜单测试接口, PicUrl =/weixin/weather/icon/cartoon.jpg, Url =http:/bbs.binguo.me); break; break; default: txt($fu,$tu,receiveEvent default); break; if (is_array($contentStr) $resultStr = news($fu,$tu, $contentStr); else $resultStr = txt($fu,$tu, $contentStr,0); /txt($fu,$tu,你发送了数字 0 ,所以你就看到了这么多 000000000000。); /txt($fu,$tu,你发送的内容是。.$content); */ return $resultStr; private function transmitText($object, $content, $funcFlag = 0) $textTpl = %s%d; $resultStr = sprintf($textTpl, $object-FromUserName, $object-ToUserName, time(), $content, $funcFlag); return $resultStr; private function transmitNews($object, $arr_item, $funcFlag = 0) /首条标题28字,其他标题39字 if(!is_array($arr_item) return; $itemTpl = ; $item_str = ; foreach ($arr_item as $item) $item_str .= sprintf($itemTpl, $itemTitle, $itemDescription, $itemPicUrl, $itemUrl); $newsTpl = %s %s $item_str %s ; $resultStr = sprintf($newsTpl, $object-FromUserName, $object-ToUserName, time(), count($arr_item), $funcFlag); return $resultStr; public function responseMsg() /获取post数据 /$postStr = $GLOBALSHTTP_RAW_POST_DATA; $postStr = isset($GLOBALSHTTP_RAW_POST_DATA) ? $GLOBALSHTTP_RAW_POST_DATA : ;/运用三目运算符,使用isset函数检测变量是否已经设置或者存在(使用数组时,其索引有可能不存在,比如此例的HTTP_RAW_POST_DATA可能不存在) /解析post数据 if (!empty($postStr) /$access_token = $this-get_access_token();/获取access_token /$this-createmenu($access_token);/创建菜单 $postObj = simplexml_load_string($postStr, SimpleXMLElement, LIBXML_NOCDATA); $type= $postObj-MsgType; $fu = (string)$postObj-FromUserName; /取出用户的账号 $tu = (string)$postObj-ToUserName; /公众账号 switch($type) case voice; $resultStr= $this-getMusicContent($postObj); echo $resultStr; exit; break; case event: /$this-txt($fu,$tu,回复数字050课程号,收听机灵狗英文启蒙课程); /$resultStr = $this-receiveEvent($postObj); switch ($postObj-Event) case subscribe: $contentStr = 欢迎关注跨界交流; break; case unsubscribe: break; case CLICK:/ $postObj-EventKey; /$this-txt($fu,$tu,回复数字050课程号,收听机灵狗英文启蒙课程); switch ($postObj-EventKey) case introduce: /$this-txt($fu,$tu,回复数字050课程号,收听机灵狗英文启蒙课程); /$this-txt($fu,$tu,leve0); /$contentStr = array(Title =机灵狗启蒙英文读物, /Description =输入数字150,听取课程, /PicUrl =/weixin/weather/icon/cartoon.jpg, /Url =weixin:/addfriend/pondbaystudio); $msg0title = 这里是标题; $msg0intro = 简介; $msg0pic = /weixin/weather/icon/cartoon.jpg; /图片URL 这里是返回发送的原图 URL 要使用绝对完整地址 $msg0url = /s?_biz=MzAwNTI5NTQwMw=&mid=203760231&idx=1&sn=2dfbe17ad8aa46fc10fd32d088aeb428&scene=4#wechat_redirect; /这里是超链接 $this-news($fu,$tu,$msg); break; case game: $this-txt($fu,$tu,语音输入进行点歌游戏 nr 输入课程数字号听英文录音); break; default: /$this-txt($fu,$tu,default-0); $contentStr = array(Title =默认菜单回复, Description =您正在使用的是自定义菜单测试接口, PicUrl =/weixin/weather/icon/cartoon.jpg, Url =weixin:/addfriend/pondbaystudio); break; break; default: /$this-txt($fu,$tu,receiveEvent default-1); break; if (is_array($contentStr) $resultStr = $this-transmitNews($postObj, $contentStr); else /$resultStr = $this-transmitText($postObj, $contentStr); $this-txt($fu,$tu,回复数字050课程号,收听机灵狗英文启蒙课程); break; case image: /图像消息类型 $pic=(string)$postObj-PicUrl; /取出图片url /回复一个图文 开始定义数组 $msg0title = 这里是标题; $msg0intro = 简介; $msg0pic = $pic; /图片URL 这里是返回发送的原图 URL 要使用绝对完整地址 $msg0url = http:/bbs.binguo.me; /这里是超链接 $this-news($fu,$tu,$msg); /如要回复多条图文,可对该二维数组赋值多个元素 如 $msg0 $msg1 $msg2 。 break; case location: /地理位置消息类型 $l_x = $postObj-Location_X; /取出 x 坐标 $l_y = $postObj-Location_Y; /取出 y 坐标 $scale = $postObj-Scale; /取出 缩放等级 $lable = $postObj-Label; /取出 位置信息 /回复文字消息 $this-txt($fu,$tu,你所处位置是:.$lable.坐标为 X:.$l_x.Y:.$l_y); break; case text; /$resultStr= $this-getMenu($postObj); /echo $resultStr; /exit; /break; $content = trim($postObj-Content); / 取出消息内容 /根据发送的内容回复相应的内容 switch($content) case 0: /如果发送的是数字0则回复以下内容 $this-txt($fu,$tu,你发送了数字 0 ,所以你就看到了这么多 000000000000。); break; case 1: /如果发送的是数字1则回复以下内容 $this-txt($fu,$tu,你发送了数字 1 ,所以你就看到了这么多 111111111111。); break; case 2: /如果发送的是数字2 则回复以下内容 $msgtitle=机灵狗英文启蒙教育; $msgintro=清华出版社亲情推荐; $msgurl=/GrandfathersClock.mp3; /音频文件的绝对完整 url $msghqurl=/GrandfathersClock.mp3; /音频文件的高清绝对完整 url wifi下优先播放此url. $this-audio($fu,$tu,$msg); /回复一个可播放的音频消息 break; default: /如果是其他内容则回复 /$this-txt($fu,$tu,你发送的内容是。.$content); $resultStr= $this-inputgetMusicContent($postObj); echo $resultStr; break; private function checkSignature() $signature = $_GETsignature; $timestamp = $_GETtimestamp; $nonce = $_GETnonce; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr = $signature ) return true; else return false; public function getMusicContent($postObj) $ret= %s ; $recognition=$postObj-Recognition; $keywordc= urlencode($recognition); $musicapi = /x?op=12&count=1&title=$keywordc$; $simstr=file_get_contents($musicapi); $musicobj=simplexml_load_string($simstr); $i=0; $music

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论