event = $postobj->event; //关注事件
$this->evenkey = $postobj->eventkey;//菜单事件
$this->myid = $postobj->tousername;
$this->userid = $postobj->fromusername;
$this->picurl=$postobj->picurl;
$this->msgtype=$postobj->msgtype;
if($this->msgtype==text){
$this->keyword = trim($postobj->content);
}else if($this->msgtype==location){
$this->location_x=$postobj->location_x;
$this->location_y=$postobj->location_y;
}
}
}
function index(){
//如果 是验证的时候,请把下面一行的注释去了
// $this->valid();
if($this->msgtype==text){
$this->sendmessage($this->keyword);
}else if($this->msgtype==location){
}
}
/**
* @param 回复消息的内容 $content
*
*/
function sendmessage($content){
$this->texttpl =
%s
0
;
$this->msgtype = text;
$resultstr = sprintf($this->texttpl, $this->userid, $this->myid, time(), $this->msgtype, $content);
echo $resultstr;
exit();
}
/**
* @param unknown $arr
* $arr包括title标题,intro简介,imagepath图片路径,url访问路径,四个属性
* 图片路径用绝对路径,即http://开头
*/
function sendnews($arr){
$this->msgtype = news;
$this->texttpl=
userid.]]>
myid.]]>
.time().
msgtype.]]>
.count($arr).
;
foreach ($arr as $key =>$list){
$this->texttpl.=
;
}
$this->texttpl.=;
echo $this->texttpl;
exit();
}
/**
*验证token方法
*/
public function valid(){
$echostr = $_get[echostr];
if($this->checksignature()){
echo $echostr;
exit;
}
}
function checksignature(){
$signature = $_get[signature];
$timestamp = $_get[timestamp];
$nonce = $_get[nonce];
$tmparr = array($this->token, $timestamp, $nonce);
sort($tmparr);
$tmpstr = implode( $tmparr );
$tmpstr = sha1( $tmpstr );
if( $tmpstr == $signature ){
return true;
}else{
return false;
}
}
function startmemu(){
header(content-type: text/html; charset=utf-8);
$appid = wx01bee286793e0383;
$appsecret = 84e324cb2daec6a8a1aea8b19cce465d;
$access_token = kgfind;
$data = ' {
button:[
{
type:click,
name:今日歌曲,
key:v1001_today_music
},
{
type:click,
name:歌手简介,
key:v1001_today_singer
},
{
name:菜单,
sub_button:[
{
type:view,
name:搜索,
url:http://www.soso.com/
},
{
type:view,
name:视频,
url:http://v.qq.com/
},
{
type:click,
name:赞一下我们,
key:v1001_good
}]
}]
}';
$ch = curl_init();
curl_setopt($ch, curlopt_url, https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=.$this->appid.&secret=.$this->appsecret.);
curl_setopt($ch, curlopt_customrequest, post);
curl_setopt($ch, curlopt_ssl_verifypeer, false);
curl_setopt($ch, curlopt_ssl_verifyhost, false);
curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (compatible; msie 5.01; windows nt 5.0)');
curl_setopt($ch, curlopt_followlocation, 1);
curl_setopt($ch, curlopt_autoreferer, 1);
curl_setopt($ch, curlopt_postfields, $data);
curl_setopt($ch, curlopt_returntransfer, true);
$token = curl_exec($ch);
if (curl_errno($ch)) {
echo 'curl error on:'.curl_error($ch);
} else {
$arr = json_decode($token, true);
$access_token = $arr['access_token'];
curl_setopt($ch, curlopt_url, https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$access_token});
$rs = curl_exec($ch);
if (curl_errno($ch)) {
echo 'curl error on:'.curl_error($ch);
} else {
$arr = json_decode($rs, true);
echo code: . $arr['errcode'];
echo
message: . $arr['errmsg'];
}
}
curl_close($ch);
}
}
?>
ad:真正免费,域名+虚机+企业邮箱=0元