Beispiel #1
0
<?php

//引入库
require_once 'Weixin.php';
//创建SDK实例
$weixin = Weixin::init('vrobin', 'wx047be627bb7116c3', '392f899f7e6c57c0ffeb588cf01674bc', true);
/**
 * 创建自定义菜单菜单
 */
$menu = new WeixinMenu();
$menu->addButton('按钮1', 'click', 'EVENT_CLICK_1');
$menu->addButton('按钮2', 'click', 'EVENT_CLICK_2');
$menu->addButton('菜单');
$menu->addSubButton(1, '按钮1-1', 'click', 'EVENT_CLICK_1_1');
$menu->addSubButton(3, '谷歌', 'view', 'http://google.com');
print_r($menu->toArray());
$weixin->createMenu($menu);
print_r($weixin->getMenu());
/**
 * 获取关注用户列表
 */
print_r($weixin->getUserList());
Beispiel #2
0
<?php

//引入库
require_once 'Weixin.php';
//使用init方法创建SDK实例
Weixin::init('vrobin');
/**
 * 监听用户消息
 * 用DemoClass类的subscribe方法处理 事件-订阅
 * 用DemoClass类的otherEvent方法处理其余事件
 * 用匿名函数处理location消息
 * 用catchAll函数处理其余消息
 */
$class = new DemoClass();
$location = function ($data) {
    //使用instance方法获取已经创建好的weixin实例
    Weixin::instance()->responseText('Hello World,这是一条位置消息,你的位置为' . $data->Label);
};
Weixin::instance()->setCallback(Weixin::TYPE_UNDEFINED, 'catchAll')->setCallback(array(Weixin::TYPE_EVENT, Weixin::EVENT_SUBSCRIBE), array($class, 'subscribe'))->setCallback(Weixin::TYPE_EVENT, array($class, 'otherEvent'))->setCallback(Weixin::TYPE_LOCATION, $location)->listen();
function catchAll(WeixinResult $data)
{
    $weixin = Weixin::instance();
    $weixin->responseText('Hello World,接受到一条' . $data->MsgType . '消息');
}
class DemoClass
{
    function __construct()
    {
        $this->weixin = Weixin::instance();
    }
    function subscribe(WeixinResult $data)