|
楼主 |
发表于 2014-3-10 12:15:37
|
显示全部楼层
- <P><?php
- /**
- * 设置回复文本消息
- * @param string $content
- * @param string $openid
- */
- public function text($content='')
- {
- $textTpl = "<xml>
- <ToUserName><![CDATA[%s]]></ToUserName>
- <FromUserName><![CDATA[%s]]></FromUserName>
- <CreateTime>%s</CreateTime>
- <MsgType><![CDATA[%s]]></MsgType>
- <Content><![CDATA[%s]]></Content>
- </xml>";
- $this->_reply = sprintf($textTpl,
- $this->getRevFrom(),
- $this->getRevTo(),
- Date::getTimeStamp(),
- 'text',
- $content
- );
- return $this;
- }
- /**
- * 设置回复音乐信息
- * @param string $title
- * @param string $desc
- * @param string $musicurl
- * @param string $hgmusicurl
- */
- public function music($title, $desc, $musicurl, $hgmusicurl='')
- {
- $textTpl = '<xml>
- <ToUserName><![CDATA[%s]]></ToUserName>
- <FromUserName><![CDATA[%s]]></FromUserName>
- <CreateTime>%s</CreateTime>
- <MsgType><![CDATA[%s]]></MsgType>
- <Music>
- <Title><![CDATA[%s]]></Title>
- <Description><![CDATA[%s]]></Description>
- <MusicUrl><![CDATA[%s]]></MusicUrl>
- <HQMusicUrl><![CDATA[%s]]></HQMusicUrl>
- </Music>
- </xml>';
- //<ThumbMediaId><![CDATA[%s]]></ThumbMediaId>
- $this->_reply = sprintf($textTpl,
- $this->getRevFrom(),
- $this->getRevTo(),
- Date::getTimeStamp(),
- 'music',
- $title,
- $desc,
- $musicurl,
- $hgmusicurl
- );
- return $this;
- }
- /**
- * 回复图文消息
- * @param array
- */
- public function news($data)
- {
- $count = count($data);
- $subText = '';
- if($count > 0)
- {
- foreach($data as $v)
- {
- $tmpText = '<item>
- <Title><![CDATA[%s]]></Title>
- <Description><![CDATA[%s]]></Description>
- <PicUrl><![CDATA[%s]]></PicUrl>
- <Url><![CDATA[%s]]></Url>
- </item>';
- $subText .= sprintf(
- $tmpText, $v['title'],
- isset($v['description']) ? $v['description'] : '',
- isset($v['picUrl']) ? $v['picUrl'] : '',
- isset($v['url']) ? $v['url'] : ''
- );
- }
- }
- $textTpl = '<xml>
- <ToUserName><![CDATA[%s]]></ToUserName>
- <FromUserName><![CDATA[%s]]></FromUserName>
- <CreateTime><![CDATA[%s]]></CreateTime>
- <MsgType><![CDATA[news]]></MsgType>
- <ArticleCount><![CDATA[%d]]></ArticleCount>
- <Articles>%s</Articles>
- </xml>';
- $this->_reply = sprintf(
- $textTpl,
- $this->getRevFrom(),
- $this->getRevTo(),
- Date::getTimeStamp(),
- $count,
- $subText
- );
- return $this;
- }
- /**
- * 回复消息
- * @param array $msg
- * @param bool $return
- */
- public function reply()
- {
- header('Content-Type:text/xml');
- echo $this->_reply;
- exit;
- }
- /**
- * 自定义菜单创建
- * @param array 菜单数据
- */
- public function createMenu($data)
- {
- if(!$this->access_token && !$this->checkAuth()) return false;
- $result = curlRequest(self::API_URL_PREFIX.self::MENU_CREATE_URL.'access_token='.$this->access_token, $this->jsonEncode($data), 'post');
- if($result)
- {
- $jsonArr = json_decode($result, true);
- if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) $this->error($jsonArr);
- else return true;
- }
- return false;
- }
- /**
- * 自定义菜单查询
- */
- public function getMenu()
- {
- if(!$this->access_token && !$this->checkAuth()) return false;
- $result = curlRequest(self::API_URL_PREFIX.self::MENU_GET_URL.'access_token='.$this->access_token);
- if($result)
- {
- $jsonArr = json_decode($result, true);
- if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) $this->error($jsonArr);
- else return $jsonArr;
- }
- return false;
- }
- /**
- * 自定义菜单删除
- */
- public function deleteMenu()
- {
- if(!$this->access_token && !$this->checkAuth()) return false;
- $result = curlRequest(self::API_URL_PREFIX.self::MENU_DELETE_URL.'access_token='.$this->access_token);
- if($result)
- {
- $jsonArr = json_decode($result, true);
- if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) $this->error($jsonArr);
- else return true;
- }
- return false;
- }
- /**
- * 获取用户基本信息
- * @param string $openid 普通用户的标识,对当前公众号唯一
- */
- public function getUserInfo($openid)
- {
- if(!$this->access_token && !$this->checkAuth()) return false;
- $result = curlRequest(self::API_URL_PREFIX.self::USER_INFO_URL.'access_token='.$this->access_token.'&openid='.$openid);
- if($result)
- {
- $jsonArr = json_decode($result, true);
- if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) $this->error($jsonArr);
- else return $jsonArr;
- }
- return false;
- }
- /**
- * 获取关注者列表
- * @param string $next_openid 第一个拉取的OPENID,不填默认从头开始拉取
- */
- public function getUserList($next_openid='')
- {
- if(!$this->access_token && !$this->checkAuth()) return false;
- $result = curlRequest(self::API_URL_PREFIX.self::USER_GET_URL.'access_token='.$this->access_token.'&next_openid='.$next_openid);
- if($result)
- {
- $jsonArr = json_decode($result, true);
- if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) $this->error($jsonArr);
- else return $jsonArr;
- }
- return false;
- }
- </P>
- <P>?>
- </P>
复制代码
|
|