access_token=$ResArr['access_token']; } protected function onSubscribe() { $openid=$this->getRequest('fromusername'); //$uid=M('user')->getFieldByOpenid($openid, 'uid'); $userinfo=''; if(empty($uid)){ $userinfo=file_get_contents($this->getInfoUrl.'access_token='.$this->access_token.'&openid='.$openid.'&lang=zh_CN'); } $this -> responseText('您好,欢迎关注!分享别人会的,跟别人分享你会的 —— 源自Halo精神'); } /** * 用户取消关注时触发 * * @return void */ protected function onUnsubscribe() { // 「悄悄的我走了,正如我悄悄的来;我挥一挥衣袖,不带走一片云彩。」 } /** * 收到文本消息时触发,回复收到的文本消息内容 * * @return void */ protected function onText() { // $items = array(new NewsResponseItem('Halo分享网', '最新文章', 'http://www.haloxin.me/zb_users/theme/summer/style/img/bg09.jpg', "http://www.haloxin.me")); // $this -> responseNews($items); $this->responseText('消息回复功能正在开发中,请稍后!您也可以尝试访问 http://www.haloxin.me/ 获取最新资源。'); } /** * 收到图片消息时触发,回复由收到的图片组成的图文消息 * * @return void */ protected function onImage() { $items = array(new NewsResponseItem('标题一', '描述一', $this -> getRequest('picurl'), $this -> getRequest('picurl')), new NewsResponseItem('标题二', '描述二', $this -> getRequest('picurl'), $this -> getRequest('picurl')), ); $this -> responseNews($items); } protected function onClickEvent(){ $keyevent = $this->getRequest('EventKey'); switch($keyevent){ case 'halo_hot': $this->responseNews(array(new NewsResponseItem('Halo分享网', '最热文章', 'http://www.haloxin.me/zb_users/theme/summer/style/img/bg09.jpg', "http://www.haloxin.me"))); break; case 'halo_new': $this->responseNews(array(new NewsResponseItem('Halo分享网', '最新文章', 'http://www.haloxin.me/zb_users/theme/summer/style/img/bg09.jpg', "http://www.haloxin.me"))); break; case 'halo_share': $this -> responseText('投稿请发送至tougao@haloxin.me'); break; case 'halo_about': $this -> responseText('Resmic个人网站主页、论坛。“分享别人会的,跟别人分享你会的 —— 这就是学习”,我一直坚信每一个走在IT道路上的人,走的是否远近完全取决于个人的眼光及思想。你可以会的东西并不多,但是会的必须得精!一论坛,一梦想。我喜欢IT技术,更喜欢分享!我喜欢玩儿音乐,也喜欢旅游。我希望未来可以在梦想的支撑下,凭着自己的努力可以走的更远。'); break; default: $this -> responseText('未知消息类型!请稍后重试'); break; } } /** * 收到地理位置消息时触发,回复收到的地理位置 * * @return void */ protected function onLocation() { //$num = 1 / 0; // 故意触发错误,用于演示调试功能 $this -> responseText('收到了位置消息:' . $this -> getRequest('location_x') . ',' . $this -> getRequest('location_y')); } /** * 收到链接消息时触发,回复收到的链接地址 * * @return void */ protected function onLink() { $this -> responseText('收到了链接:' . $this -> getRequest('url')); } /** * 收到未知类型消息时触发,回复收到的消息类型 * * @return void */ protected function onUnknown() { $this -> responseText('收到了未知类型消息:' . $this -> getRequest('msgtype')); } public function CreateMenu($menudata) { $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$this->access_token; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $menudata); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $result = curl_exec($ch); curl_close($ch); return $result; } }