美高梅平台下载-美高梅娱乐平台登录

热门关键词: 美高梅平台下载,美高梅娱乐平台登录

服务号可以申请自定义菜单,服务号可以申请自

日期:2020-01-05编辑作者:美高梅平台下载

本文实例讲述了php实现微信公众平台账号自定义菜单类的方法。分享给大家供大家参考。具体分析如下:

申请自定义菜单

微信公众平台服务号可申请自定义菜单了,其它的号暂时不支持自定义菜单了,这个不但可以使用api来操作,还可以直接在后台定义菜单与参数。

服务号可以申请自定义菜单;使用QQ登录的公众号,可以升级为邮箱登录;使用邮箱登录的公众号,可以修改登录邮箱;群发消息可以同步到腾讯微博。

申请自定义菜单

图片 1

服务号可以申请自定义菜单,使用QQ登录的公众号,可以升级为邮箱登录,使用邮箱登录的公众号,可以修改登录邮箱,群发消息可以同步到腾讯微博.

微信公众平台账号api程序

微信公众平台账号api程序

 

复制代码代码如下:

 代码如下

<?php 
//define your token 
define("TOKEN", "chenxiang",',',');//改成自己的TOKEN 
define('APP_ID', '',',',');//改成自己的APPID 
define('APP_SECRET', '',',',');//改成自己的APPSECRET 
 
$wechatObj = new wechatCallbackapiTest(APP_ID,APP_SECRET,',','); 
$wechatObj->Run(,',','); 
 
class wechatCallbackapiTest 

    private $fromUsername; 
    private $toUsername; 
    private $times; 
    private $keyword; 
    private $app_id; 
    private $app_secret; 
     
    public function __construct($appid,$appsecret) 
    { 
        # code... 
        $this->app_id = $appid; 
        $this->app_secret = $appsecret; 
    } 
    public function valid() 
    { 
        $echoStr = $_GET["echostr"]; 
        if($this->checkSignature()){ 
            echo $echoStr; 
            exit; 
        } 
    } 
    /** 
     * 运行程序 
     * @param string $value [description] 
     */ 
    public function Run() 
    { 
        $this->responseMsg(,',','); 
        $arr[]= "您好,这是自动回复,我现在不在,有事请留言,我会尽快回复你的^_^"; 
        echo $this->make_xml("text",$arr,',','); 
    } 
    public function responseMsg() 
    {    
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];//返回回复数据 
        if (!emptyempty($postStr)){ 
                $access_token = $this->get_access_token(,',',');//获取access_token 
                $this->createmenu($access_token,',',');//创建菜单 
                //$this->delmenu($access_token,',',');//删除菜单 
                $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA,',','); 
                $this->fromUsername = $postObj->FromUserName;//发送消息方ID 
                $this->toUsername = $postObj->ToUserName;//接收消息方ID 
                $this->keyword = trim($postObj->Content,',',');//用户发送的消息 
                $this->times = time(,',',');//发送时间 
                $MsgType = $postObj->MsgType;//消息类型 
                if($MsgType=='event'){ 
                    $MsgEvent = $postObj->Event;//获取事件类型 
                    if ($MsgEvent=='subscribe') {//订阅事件 
                        $arr[] = "你好,我是xxx,现在我们是好友咯![愉快][玫瑰]"; 
                        echo $this->make_xml("text",$arr,',','); 
                        exit; 
                    }elseif ($MsgEvent=='CLICK') {//点击事件 
                        $EventKey = $postObj->EventKey;//菜单的自定义的key值,可以根据此值判断用户点击了什么内容,从而推送不同信息 
                        $arr[] = $EventKey; 
                        echo $this->make_xml("text",$arr,',','); 
                        exit; 
                    } 
                } 
        }else { 
            echo "this a file for weixin API!"; 
            exit; 
        } 
    } 
    /** 
     * 获取access_token 
     */ 
    private function get_access_token() 
    { 
        $url = "; 
        $data = json_decode(file_get_contents($url),true,',','); 
        if($data['access_token']){ 
            return $data['access_token']; 
        }else{ 
            return "获取access_token错误"; 
        } 
    } 
    /** 
     * 创建菜单 
     * @param $access_token 已获取的ACCESS_TOKEN 
     */ 
    public function createmenu($access_token) 
    { 
        $url = "; 
        $arr = array(  
            'button' =>array( 
                array( 
                    'name'=>urlencode("生活查询"), 
                    'sub_button'=>array( 
                        array( 
                            'name'=>urlencode("天气查询"), 
                            'type'=>'click', 
                            'key'=>'VCX_WEATHER' 
                        ), 
                        array( 
                            'name'=>urlencode("身份证查询"), 
                            'type'=>'click', 
                            'key'=>'VCX_IDENT' 
                        ) 
                    ) 
                ), 
                array( 
                    'name'=>urlencode("轻松娱乐"), 
                    'sub_button'=>array( 
                        array( 
                            'name'=>urlencode("刮刮乐"), 
                            'type'=>'click', 
                            'key'=>'VCX_GUAHAPPY' 
                        ), 
                        array( 
                            'name'=>urlencode("幸运大转盘"), 
                            'type'=>'click', 
                            'key'=>'VCX_LUCKPAN' 
                        ) 
                    ) 
                ), 
                array( 
                    'name'=>urlencode("我的信息"), 
                    'sub_button'=>array( 
                        array( 
                            'name'=>urlencode("关于我"), 
                            'type'=>'click', 
                            'key'=>'VCX_ABOUTME' 
                        ), 
                        array( 
                            'name'=>urlencode("工作信息"), 
                            'type'=>'click', 
                            'key'=>'VCX_JOBINFORMATION' 
                        ) 
                    ) 
                ) 
            ) 
        ,',','); 
        $jsondata = urldecode(json_encode($arr),',','); 
        $ch = curl_init(,',','); 
        curl_setopt($ch,CURLOPT_URL,$url,',','); 
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1,',','); 
        curl_setopt($ch,CURLOPT_POST,1,',','); 
        curl_setopt($ch,CURLOPT_POSTFIELDS,$jsondata,',','); 
        curl_exec($ch,',','); 
        curl_close($ch,',','); 
    } 
    /** 
     * 查询菜单 
     * @param $access_token 已获取的ACCESS_TOKEN 
     */ 
     
    private function getmenu($access_token) 
    { 
        # code... 
        $url = "; 
        $data = file_get_contents($url,',','); 
        return $data; 
    } 
    /** 
     * 删除菜单 
     * @param $access_token 已获取的ACCESS_TOKEN 
     */ 
     
    private function delmenu($access_token) 
    { 
        # code... 
        $url = "; 
        $data = json_decode(file_get_contents($url),true,',','); 
        if ($data['errcode']==0) { 
            # code... 
            return true; 
        }else{ 
            return false; 
        } 
    } 
         
    /** 
     *@param type: text 文本类型, news 图文类型 
     *@param value_arr array(内容),array(ID) 
     *@param o_arr array(array(标题,介绍,图片,超链接),...小于10条),array(条数,ID) 
     */ 
     
    private function make_xml($type,$value_arr,$o_arr=array(0)){ 
        //=================xml header============ 
        $con="<xml> 
                    <ToUserName><![CDATA[{$this->fromUsername}]]></ToUserName> 
                    <FromUserName><![CDATA[{$this->toUsername}]]></FromUserName> 
                    <CreateTime>{$this->times}</CreateTime> 
                    <MsgType><![CDATA[{$type}]]></MsgType>"; 
                     
          //=================type content============ 
        switch($type){ 
           
            case "text" :  
                $con.="<Content><![CDATA[{$value_arr[0]}]]></Content> 
                    <FuncFlag>{$o_arr}</FuncFlag>";   
            break; 
             
            case "news" :  
                $con.="<ArticleCount>{$o_arr[0]}</ArticleCount> 
                     <Articles>"; 
                foreach($value_arr as $id=>$v){ 
                    if($id>=$o_arr[0]) break; else null; //判断数组数不超过设置数 
                    $con.="<item> 
                         <Title><![CDATA[{$v[0]}]]></Title>  
                         <Description><![CDATA[{$v[1]}]]></Description> 
                         <PicUrl><![CDATA[{$v[2]}]]></PicUrl> 
                         <Url><![CDATA[{$v[3]}]]></Url> 
                         </item>"; 
                } 
                $con.="</Articles> 
                     <FuncFlag>{$o_arr[1]}</FuncFlag>";   
            break; 
        } //end switch 
         //=================end return============ 
        $con.="</xml>"; 
        return $con; 
    } 
  
    private function checkSignature() 
    { 
        $signature = $_GET["signature"]; 
        $timestamp = $_GET["timestamp"]; 
        $nonce = $_GET["nonce"];     
                 
        $token = TOKEN; 
        $tmpArr = array($token, $timestamp, $nonce,',','); 
        sort($tmpArr,',','); 
        $tmpStr = implode( $tmpArr ,',','); 
        $tmpStr = sha1( $tmpStr ,',','); 
         
        if( $tmpStr == $signature ){ 
            return true; 
        }else{ 
            return false; 
        } 
    } 

?>

<?php
//define your token
define("TOKEN", "chenxiang");//改成自己的TOKEN
define('APP_ID', '');//改成自己的APPID
define('APP_SECRET', '');//改成自己的APPSECRET

原文地址:

$wechatObj = new wechatCallbackapiTest(APP_ID,APP_SECRET);
$wechatObj->Run();

class wechatCallbackapiTest
{
    private $fromUsername;
    private $toUsername;
    private $times;
    private $keyword;
    private $app_id;
    private $app_secret;
   
   
    public function __construct($appid,$appsecret)
    {
        # code...
        $this->app_id = $appid;
        $this->app_secret = $appsecret;
    }

    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }

    /**
     * 运行程序
     * @param string $value [description]
     */
    public function Run()
    {
        $this->responseMsg();
        $arr[]= "您好,这是自动回复,我现在不在,有事请留言,我会尽快回复你的^_^";
        echo $this->make_xml("text",$arr);
    }

    public function responseMsg()
    {  
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];//返回回复数据
        if (!empty($postStr)){
                $access_token = $this->get_access_token();//获取access_token
                $this->createmenu($access_token);//创建菜单
                //$this->delmenu($access_token);//删除菜单
                $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $this->fromUsername = $postObj->FromUserName;//发送消息方ID
                $this->toUsername = $postObj->ToUserName;//接收消息方ID
                $this->keyword = trim($postObj->Content);//用户发送的消息
                $this->times = time();//发送时间
                $MsgType = $postObj->MsgType;//消息类型
                if($MsgType=='event'){
                    $MsgEvent = $postObj->Event;//获取事件类型
                    if ($MsgEvent=='subscribe') {//订阅事件
                        $arr[] = "你好,我是xxx,现在我们是好友咯![愉快][玫瑰]";
                        echo $this->make_xml("text",$arr);
                        exit;
                    }elseif ($MsgEvent=='CLICK') {//点击事件
                        $EventKey = $postObj->EventKey;//菜单的自定义的key值,可以根据此值判断用户点击了什么内容,从而推送不同信息
                        $arr[] = $EventKey;
                        echo $this->make_xml("text",$arr);
                        exit;
                    }
                }
        }else {
            echo "this a file for weixin API!";
            exit;
        }
    }

本文由美高梅平台下载发布于美高梅平台下载,转载请注明出处:服务号可以申请自定义菜单,服务号可以申请自

关键词:

各种免费试用平台陈出不穷,必须要实时关注世

小编在此谢谢大家的观看!Python很容易学!所以小编有弄一个交流,互问互答,资源共享的交流学习基地,如果你也...

详细>>

1.如何使用Ansible 2.0 Python API,3.Client拿着令牌去访

  项目结构 共分为三个组成部分: IdentityServer:用于登录、身份认证与授权 Api:提供获得授权后调用的各接口 Client(客...

详细>>

最后网上找到一个可以用的地址,【美高梅平台

(2018-05-26可用) 美高梅平台下载 ,最新更新 , 美高梅娱乐平台登录 ,http://idea.imsxm.com 这个地址是亲测可用的,针对...

详细>>