createMenu() public method

创建菜单(认证后的订阅号可用)
public createMenu ( array $data )
$data array 菜单数组数据 example: array ( 'button' => array ( 0 => array ( 'name' => '扫码', 'sub_button' => array ( 0 => array ( 'type' => 'scancode_waitmsg', 'name' => '扫码带提示', 'key' => 'rselfmenu_0_0', ), 1 => array ( 'type' => 'scancode_push', 'name' => '扫码推事件', 'key' => 'rselfmenu_0_1', ), ), ), 1 => array ( 'name' => '发图', 'sub_button' => array ( 0 => array ( 'type' => 'pic_sysphoto', 'name' => '系统拍照发图', 'key' => 'rselfmenu_1_0', ), 1 => array ( 'type' => 'pic_photo_or_album', 'name' => '拍照或者相册发图', 'key' => 'rselfmenu_1_1', ) ), ), 2 => array ( 'type' => 'location_select', 'name' => '发送位置', 'key' => 'rselfmenu_2_0' ), ), ) type可以选择为以下几种,其中5-8除了收到菜单事件以外,还会单独收到对应类型的信息。 1、click:点击推事件 2、view:跳转URL 3、scancode_push:扫码推事件 4、scancode_waitmsg:扫码推事件且弹出“消息接收中”提示框 5、pic_sysphoto:弹出系统拍照发图 6、pic_photo_or_album:弹出拍照或者相册发图 7、pic_weixin:弹出微信相册发图器 8、location_select:弹出地理位置选择器
 public function index()
 {
     import('Vendor.Wechat.Wechat');
     $option = array('token' => 'weixin', 'appid' => 'wx444c22311a33b40d', 'secret' => 'f39ae15e9d86c293edbff26a9c47af6e');
     $wechatObj = new \Wechat($option);
     $wechatObj->valid();
     //解析来向XML
     $msg = $wechatObj->getRev();
     $message['fromUsername'] = $msg->getRevFrom();
     $message['toUsername'] = $msg->getRevTo();
     $message['type'] = $msg->getRevType();
     $message['createtime'] = $msg->getRevCtime();
     $message['keyword'] = $msg->getRevContent();
     $message['event'] = $msg->getRevEvent();
     //保存新用户相关信息
     $status = D('Member');
     $status->InsertNewer($message['fromUsername']);
     //主要部分,暂时仅使用TEXT,EVENT两种
     switch ($message['type']) {
         case $wechatObj::MSGTYPE_TEXT:
             $text = A('Text');
             $ret = $text->textSkip($message);
             if ('text' == $ret['type']) {
                 $wechatObj->text($ret['content'])->reply();
             } else {
                 if ('news' == $ret['type']) {
                     $wechatObj->news($ret['content'])->reply();
                 }
             }
             break;
         case $wechatObj::MSGTYPE_EVENT:
             $event = A('Event');
             $ret = $event->eventSkip($message);
             if ('text' == $ret['type']) {
                 $wechatObj->text($ret['content'])->reply();
             } else {
                 if ('news' == $ret['type']) {
                     $wechatObj->news($ret['content'])->reply();
                 }
             }
             break;
         default:
             $wechatObj->text('更多功能正在研发中,敬请期待')->reply();
     }
     //获取菜单
     $menu = $wechatObj->getMenu();
     //创建菜单
     $newmenu = array('小瓜神力' => array(array('type' => 'click', 'name' => '新生专题', 'key' => 'V1001_01_01'), array('type' => 'click', 'name' => '校车时刻', 'key' => 'V1001_01_02'), array('type' => 'click', 'name' => '交通导航', 'key' => 'V1001_01_03'), array('type' => 'click', 'name' => '考试成绩', 'key' => 'V1001_01_04'), array('type' => 'click', 'name' => '图书信息', 'key' => 'V1001_01_05')), '军训专题' => array(array('type' => 'click', 'name' => '通知公告', 'key' => 'V1001_02_01'), array('type' => 'click', 'name' => '军训快报', 'key' => 'V1001_02_02'), array('type' => 'click', 'name' => '军营风采', 'key' => 'V1001_02_03'), array('type' => 'view', 'name' => '军歌嘹亮', 'url' => 'http://mp.weixin.qq.com/s?__biz=MjM5OTIxMTM2Mg==&mid=209183345&idx=1&sn=96c4cf9ad618e5e051167456210d9fe8&scene=5&srcid=OJ8qMfaW9nS5T0jFFjQj#rd'), array('type' => 'click', 'name' => '微军训', 'key' => 'V1001_02_05')), '小瓜威武' => array(array('type' => 'click', 'name' => '小瓜在线', 'key' => 'V1001_03_01'), array('type' => 'click', 'name' => '跑操查询', 'key' => 'V1001_03_02'), array('type' => 'view', 'name' => '瓜棚论坛', 'url' => 'http://npuxiaogua.mgschool.cn/wx/apps/liuyan/'), array('type' => 'view', 'name' => '失物招领', 'url' => 'http://npuxiaogua.mgschool.cn/wx/npuxg_blog/wxq/index.php'), array('type' => 'click', 'name' => '表白墙', 'key' => 'V1001_03_05')));
     $result = $wechatObj->createMenu($newmenu);
 }
Example #2
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
include "../wechat.class.php";
$options = array();
$weObj = new Wechat($options);
$newmenu = array("button" => array(array('type' => 'click', 'name' => '最新消息', 'key' => 'MENU_KEY_NEWS'), array('type' => 'view', 'name' => '分享', 'url' => 'http://1.derekwechat.sinaapp.com/test/weshare.html'), array('name' => '菜单', 'sub_button' => array(array('type' => 'view', 'name' => '视频', 'url' => 'http://v.qq.com/'), array('type' => 'view', 'name' => '搜索', 'url' => 'http://www.soso.com/'), array('type' => 'click', 'name' => '测试', 'key' => 'MENU_KEY_TEST')))));
$result = $weObj->createMenu($newmenu);
if ($result) {
    echo 'create menu success';
} else {
    echo 'create menu failed';
    echo $weObj->errCode;
    echo $weObj->errMsg;
}
Example #3
0
include "../qy-sdk/wechat.class.php";
function _log($text)
{
    //$result = file_put_contents('wechat.log.'.date('Y-m-d'), $text."\n", FILE_APPEND);
    //if (!$result) {
    openlog("wechat", LOG_PID | LOG_PERROR, LOG_LOCAL0);
    syslog(LOG_DEBUG, $text);
    closelog();
    //}
}
$options = ['token' => 'nizhidaoma', 'encodingaeskey' => 'IXR7m0K8Q7KOIC4z9s1CRHNQBqrJfFGTUT86CECPaXM', 'appid' => 'wx6bc0c53a3a1c150d', 'appsecret' => '3888ccc01ec4e5d6e0e673308e92e627', 'debug' => true, 'logcallback' => '_log'];
$pe_url_base = 'https://wechat.gds-services.com';
$pe_url_alarm_view = $pe_url_base . '/dynamic/index_pe.php?bcb=pe_alarm_view';
$pe_url_dc_view = $pe_url_base . '/dynamic/index_pe.php?bcb=pe_dc_view';
$pe_url_dc_report = $pe_url_base . '/dynamic/index_pe.php?bcb=pe_dc_report';
$pe_url_urgent_view = $pe_url_base . '/dynamic/index_pe.php?bcb=pe_urgent_view';
$pe_url_ppm_view = $pe_url_base . '/dynamic/index_pe.php?bcb=pe_ppm_view';
$pe_url_training = $pe_url_base . '/dynamic/index_pe.php?bcb=pe_training';
$pe_url_bind_check = $pe_url_base . '/dynamic/index_pe.php?bcb=user_bind_check_pe';
$pe_url_notice_pre = $pe_url_base . '/dynamic/index_pe.php?bcb=user_notice_prefer_pe';
$weObj = new Wechat($options);
$result = $weObj->createMenu(['button' => [0 => ['name' => '运营管理', 'sub_button' => [0 => ['type' => 'view', 'name' => '运营异动监测', 'url' => $weObj->getOauthRedirect($pe_url_alarm_view, '', 'snsapi_base')], 1 => ['type' => 'view', 'name' => '数据中心档案', 'url' => $weObj->getOauthRedirect($pe_url_dc_view, '', 'snsapi_base')]]], 1 => ['name' => '功能中心', 'sub_button' => [0 => ['type' => 'view', 'name' => '场地资源概览', 'url' => $weObj->getOauthRedirect($pe_url_dc_report, '', 'snsapi_base')], 1 => ['type' => 'view', 'name' => '应急管理系统', 'url' => $weObj->getOauthRedirect($pe_url_urgent_view, '', 'snsapi_base')], 2 => ['type' => 'view', 'name' => 'PPM维护保养', 'url' => $weObj->getOauthRedirect($pe_url_ppm_view, '', 'snsapi_base')], 3 => ['type' => 'view', 'name' => '视频培训', 'url' => $weObj->getOauthRedirect($pe_url_training, '', 'snsapi_base')]]], 2 => ['name' => '我的账号', 'sub_button' => [0 => ['type' => 'view', 'name' => '绑定账号', 'url' => $weObj->getOauthRedirect($pe_url_bind_check, '', 'snsapi_base')], 1 => ['type' => 'view', 'name' => '通知设置', 'url' => $weObj->getOauthRedirect($pe_url_notice_pre, '', 'snsapi_base')]]]], $agentid = '3']);
echo var_export($result, true);
echo '\\n';
if ($result == false) {
    echo $weObj->errCode;
    echo '\\n';
    echo $weObj->errMsg;
    echo '\\n';
}
die;
Example #4
0
                    $userInfo = $db->getInfo($weObj->getRevFrom());
                    $db->disconnect();
                    switch ($userInfo['state']) {
                        case 0:
                            $weObj->text("您目前处于未认证状态,请先认证!\n\n<a href='" . $authURI . "'>点此开始你的" . WX_TITLE . "!</a>")->reply();
                            break;
                        case 1:
                            $weObj->text("<a href='{$authURI2}'>确认借车                                           </a>")->reply();
                            break;
                        case 2:
                            $weObj->text("您目前处于已借车状态,不能再次借车!\n\n<a href='" . $authURI . "'>点此开始你的" . WX_TITLE . "!</a>")->reply();
                            break;
                        case 3:
                            $weObj->text("您目前处于被禁用状态!\n\n<a href='" . $authURI . "'>点此查看原因</a>")->reply();
                            break;
                    }
                } else {
                    if (substr($scan, 0, 5) == "prizea") {
                        // Prize
                        $redirectURI3 = urlencode("http://" . WX_URL . "/main.php?a=prize");
                        $authURI3 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . WX_APPID . "&redirect_uri=" . $redirectURI3 . "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
                        $weObj->text("<a href='{$authURI3}'>点此抽奖~</a>")->reply();
                    }
                }
                break;
        }
        break;
}
$weObj->checkAuth();
$weObj->createMenu(array('button' => array(0 => array('name' => '慈善商店', 'type' => 'view', 'url' => 'http://www.imall365.org/'), 1 => array('name' => WX_TITLE . emoji_docomo_to_unified(utf8_bytes(0x1f6b2)), 'type' => 'view', 'url' => $authURI))));
Example #5
0
    openlog("wechat", LOG_PID | LOG_PERROR, LOG_LOCAL0);
    syslog(LOG_DEBUG, $text);
    closelog();
    //}
}
$options = ['token' => 'nizhidaoma', 'encodingaeskey' => 'xc8rRK4iOQjTJK9hOYhRrC9sPBJvF5Jhjq203iMC7vF', 'appid' => 'wxe85832e232e73f41', 'appsecret' => '4c8f1aa381675dd2569fc9482052afdc', 'debug' => true, 'logcallback' => '_log'];
$csc_url_base = 'https://wechat.gds-services.com';
$csc_url_submit_srv = $csc_url_base . '/dynamic/index_csc.php?bcb=submit_srv_req';
$csc_url_query_srv = $csc_url_base . '/dynamic/index_csc.php?bcb=query_srv_req';
$csc_url_find_doc = $csc_url_base . '/dynamic/index_csc.php?bcb=extra_docs';
$csc_url_spitslot = $csc_url_base . '/dynamic/index_csc.php?bcb=user_spitslot_1_csc';
$csc_url_complain = $csc_url_base . '/dynamic/index_csc.php?bcb=user_complain_1_csc';
$csc_url_bind_check = $csc_url_base . '/dynamic/index_csc.php?bcb=user_bind_check_csc';
$csc_url_notice_pre = $csc_url_base . '/dynamic/index_csc.php?bcb=user_notice_prefer_csc';
$csc_url_task_list = $csc_url_base . '/dynamic/index_csc.php?bcb=user_tasks';
$csc_url_dc_list = $csc_url_base . '/dynamic/index_csc.php?bcb=user_dcs';
$csc_url_service_neighbour = $csc_url_base . '/dynamic/index_csc.php?bcb=extra_neighbour';
$csc_url_about_us = $csc_url_base . '/dynamic/index_csc.php?bcb=dc_guide';
$csc_url_contact_us = $csc_url_base . '/dynamic/index_csc.php?bcb=extra_contact';
$csc_url_survey = $csc_url_base . '/dynamic/index_csc.php?bcb=survey_1_csc';
$weObj = new Wechat($options);
$result = $weObj->createMenu(['button' => [0 => ['name' => '我要', 'sub_button' => [0 => ['type' => 'view', 'name' => '我要提交', 'url' => $weObj->getOauthRedirect($csc_url_submit_srv, '', 'snsapi_base')], 1 => ['type' => 'view', 'name' => '我要查询', 'url' => $weObj->getOauthRedirect($csc_url_query_srv, '', 'snsapi_base')], 2 => ['type' => 'view', 'name' => '我要吐槽', 'url' => $weObj->getOauthRedirect($csc_url_spitslot, '', 'snsapi_base')]]], 1 => ['name' => '我的', 'sub_button' => [0 => ['type' => 'view', 'name' => '我的个人信息', 'url' => $weObj->getOauthRedirect($csc_url_bind_check, '', 'snsapi_base')], 1 => ['type' => 'view', 'name' => '我的通知设置', 'url' => $weObj->getOauthRedirect($csc_url_notice_pre, '', 'snsapi_base')], 2 => ['type' => 'view', 'name' => '我的工作安排', 'url' => $weObj->getOauthRedirect($csc_url_task_list, '', 'snsapi_base')], 3 => ['type' => 'view', 'name' => '我的数据中心', 'url' => $weObj->getOauthRedirect($csc_url_dc_list, '', 'snsapi_base')]]], 2 => ['name' => '随便看看', 'sub_button' => [0 => ['type' => 'view', 'name' => '数据中心集群', 'url' => $weObj->getOauthRedirect($csc_url_about_us, '', 'snsapi_base')], 1 => ['type' => 'view', 'name' => '联系我们', 'url' => $weObj->getOauthRedirect($csc_url_contact_us, '', 'snsapi_base')], 2 => ['type' => 'view', 'name' => '用户体验调研', 'url' => $weObj->getOauthRedirect($csc_url_survey, '', 'snsapi_base')]]]], $agentid = '3']);
echo var_export($result, true);
echo '\\n';
if ($result == false) {
    echo $weObj->errCode;
    echo '\\n';
    echo $weObj->errMsg;
    echo '\\n';
}
die;
Example #6
0
                $weObj->news($subscribe)->reply();
                break;
            case 'CLICK':
                switch ($event['key']) {
                    case 'god':
                        $god = array("0" => array('Title' => '神制作我的时候【第二弹夏日特制版】', 'Description' => '神制作我的时候【第二弹夏日特制版】', 'PicUrl' => 'http://cdn-cn.vonvon.net/vonvon-cn-real/editor/1435891488403-VNAPCjjJcyU3cqxw.jpg', 'Url' => 'http://cn.vonvon.net/quiz/380'), "1" => array('Title' => '神制作我的时候', 'Description' => '神制作我的时候', 'PicUrl' => 'http://cdn-cn.vonvon.net/vonvon-cn-real/editor/mig/2015-06-11/a63b5eb123914f85a5e15ede5561c80b', 'Url' => 'http://cn.vonvon.net/quiz/341'));
                        $weObj->news($god)->reply();
                        break;
                    case 'game':
                        $game = array("0" => array('Title' => '彩色方块', 'Description' => '彩色方块', 'PicUrl' => 'http://cdn-cn.vonvon.net/vonvon-cn-real/editor/mig/2015-06-29/aa40c3ab06a84125b5cf6eda3725f6f0', 'Url' => 'http://cn.vonvon.net/quiz/394'), "1" => array('Title' => '色盲测试', 'Description' => '色盲测试', 'PicUrl' => 'http://cdn-cn.vonvon.net/vonvon-cn-real/editor/mig/2015-07-06/e5cb7e65b69d4239a9419a223e0e51b3', 'Url' => 'http://cn.vonvon.net/quiz/391'));
                        $weObj->news($game)->reply();
                        break;
                    default:
                        $weObj->text("click info")->reply();
                }
                break;
            default:
                $weObj->text("event info")->reply();
        }
        break;
    case Wechat::MSGTYPE_IMAGE:
        break;
    default:
        $weObj->text("help info")->reply();
}
//获取菜单操作:
$menu = $weObj->getMenu();
//设置菜单
$newmenu = array("button" => array(0 => array('type' => 'click', 'name' => '最新测试', 'sub_button' => array(0 => array('type' => 'click', 'name' => '【神制作】系列', 'key' => 'god'), 1 => array('type' => 'view', 'name' => '盗墓笔记', 'url' => 'http://cn.vonvon.net/quiz/424'), 2 => array('type' => 'view', 'name' => '你的身体结构', 'url' => 'http://cn.vonvon.net/quiz/421'), 3 => array('type' => 'view', 'name' => '我的右脑有多聪明', 'url' => 'http://cn.vonvon.net/quiz/387'), 4 => array('type' => 'view', 'name' => '【门萨】IQ测试', 'url' => 'http://cn.vonvon.net/quiz/318'))), 1 => array('type' => 'click', 'name' => '人气测试', 'sub_button' => array(0 => array('type' => 'view', 'name' => '神在制作我的时候', 'url' => 'http://cn.vonvon.net/quiz/341'), 1 => array('type' => 'view', 'name' => '多久后我才脱单', 'url' => 'http://cn.vonvon.net/quiz/319'), 2 => array('type' => 'view', 'name' => '最适合我的别名', 'url' => 'http://cn.vonvon.net/quiz/361'), 3 => array('type' => 'view', 'name' => '我的相关关键字', 'url' => 'http://cn.vonvon.net/quiz/364'), 4 => array('type' => 'click', 'name' => 'vonvon游戏', 'key' => 'game'))), 2 => array('type' => 'view', 'name' => '更多测试', 'url' => 'http://cn.vonvon.net')));
$weObj->createMenu($newmenu);
Example #7
0
<?php

include './qy-sdk/qywechat.class.php';
function _log($text)
{
    file_put_contents('/opt/gdsserver/logs/wechat_log.txt', $text . "\r\n\r\n", FILE_APPEND);
}
$options = array('token' => 'N6cq3R', 'encodingaeskey' => 'nil3OzTxXoPHx4mvx0GLbyECkPYrfyiB9ca4Iz61ny3', 'appid' => 'wx926454a4965d2b7c', 'appsecret' => 'PsPkG1V74sWm6V2mNN3F2NOHKQT696g1wrmJZhB7WT-8xcLmt-3rez3FfuH3SzCf', 'agentid' => '3', 'debug' => true, 'logcallback' => '_log');
$menu = array('button' => array(0 => array('name' => '常用链接', 'sub_button' => array(0 => array('type' => 'view', 'name' => '公司主页', 'key' => 'rselfmenu_0_0', 'url' => 'https://www.gds-services.com/'), 1 => array('type' => 'click', 'name' => '抽奖', 'key' => 'rselfmenu_0_1'))), 1 => array('name' => '上传图片', 'sub_button' => array(0 => array('type' => 'pic_sysphoto', 'name' => '系统拍照发图', 'key' => 'rselfmenu_1_0'), 1 => array('type' => 'pic_photo_or_album', 'name' => '拍照或者相册发图', 'key' => 'rselfmenu_1_1'))), 2 => array('type' => 'location_select', 'name' => '发送位置', 'key' => 'rselfmenu_2_0')));
$weObj = new Wechat($options);
$result = $weObj->createMenu($menu, $agentid = '3');
echo var_export($result, true);
Example #8
0
<?php

include 'config.php';
include 'wechat-php-sdk/wechat.class.php';
$key = $_GET['key'];
$act = $_GET['act'];
$id = $_GET['id'];
if (strlen($siteData['getKey']) && $key !== $siteData['getKey']) {
    header('Location:' . $siteData['homePage']);
}
$options = array('token' => $siteData['wechatToken'], 'appid' => $siteData['wechatAppID'], 'appsecret' => $siteData['wechatAppSecret']);
$weObj = new Wechat($options);
// 查询菜单
if ($act === 'getMenu') {
    var_dump($weObj->getMenu());
    exit;
}
if ($act === 'createMenu') {
    $data = array('button' => array(array('type' => 'view', 'name' => '伍 & 熊', 'url' => 'http://wedding.ciaoca.com/'), array('name' => '参加婚礼', 'sub_button' => array(array('type' => 'click', 'name' => '我的喜帖', 'key' => '喜帖'), array('type' => 'click', 'name' => '婚宴酒店', 'key' => '地址'))), array('name' => '精彩互动', 'sub_button' => array(array('type' => 'view', 'name' => '祝福新人', 'url' => 'http://wedding.ciaoca.com/blessing.php'), array('type' => 'click', 'name' => '幸福瞬间', 'key' => '照片分享'), array('type' => 'pic_photo_or_album', 'name' => '照片分享', 'key' => 'photo_share')))));
    $weObj->createMenu($data);
    exit;
}
Example #9
0
<?php

//请勿随意访问该文件
//创建微信自定义菜单
require './wechat/wechat.class.php';
$options = array('token' => 'scubike', 'appid' => 'YOUR_APPID', 'appsecret' => 'YOUR_APPSECRET');
$w = new Wechat($options);
$data = array('button' => array(0 => array('name' => '借', 'type' => 'click', 'key' => 'lend'), 1 => array('name' => '还', 'type' => 'click', 'key' => 'return'), 2 => array('name' => '发现', 'sub_button' => array(0 => array('type' => 'scancode_push', 'name' => '扫二维码', 'key' => 'qrcode'), 1 => array('type' => 'location_select', 'name' => '附近自行车', 'key' => 'nearby')))));
$w->createMenu($data);