调用官方API,具有更灵活的消息分类响应方式,支持链式调用操作 ;
$options = array(
'token'=>'tokenaccesskey', //填写应用接口的Token
'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey
'appid'=>'wxdk1234567890', //填写高级调用功能的app id
'appsecret'=>'xxxxxxxxxxxxxxxxxxx', //填写高级调用功能的密钥
'agentid'=>'1', //应用的id
'debug'=>false, //调试开关
'_logcallback'=>'logg', //调试输出方法,需要有一个string类型的参数
);
$weObj = new Wechat($options); //创建实例对象
//TODO:调用$weObj各实例方法
scancode_push
或scancode_waitmsg
返回数组array ('ScanType'=>'qrcode','ScanResult'=>'123123')pic_sysphoto
或pic_photo_or_album
或pic_weixin
数组结构见php文件内方法说明location_select
数组结构见php文件内方法说明////消息类型,使用实例调用getRevType()方法取得
const MSGTYPE_TEXT = 'text';
const MSGTYPE_IMAGE = 'image';
const MSGTYPE_LOCATION = 'location';
const MSGTYPE_LINK = 'link'; //暂不支持
const MSGTYPE_EVENT = 'event';
const MSGTYPE_MUSIC = 'music'; //暂不支持
const MSGTYPE_NEWS = 'news';
const MSGTYPE_VOICE = 'voice';
const MSGTYPE_VIDEO = 'video';
////事件类型,使用实例调用getRevEvent()方法取得
const EVENT_SUBSCRIBE = 'subscribe'; //订阅
const EVENT_UNSUBSCRIBE = 'unsubscribe'; //取消订阅
const EVENT_LOCATION = 'LOCATION'; //上报地理位置
const EVENT_ENTER_AGENT = 'enter_agent'; //用户进入应用
const EVENT_MENU_VIEW = 'VIEW'; //菜单 - 点击菜单跳转链接
const EVENT_MENU_CLICK = 'CLICK'; //菜单 - 点击菜单拉取消息
const EVENT_MENU_SCAN_PUSH = 'scancode_push'; //菜单 - 扫码推事件(客户端跳URL)
const EVENT_MENU_SCAN_WAITMSG = 'scancode_waitmsg'; //菜单 - 扫码推事件(客户端不跳URL)
const EVENT_MENU_PIC_SYS = 'pic_sysphoto'; //菜单 - 弹出系统拍照发图
const EVENT_MENU_PIC_PHOTO = 'pic_photo_or_album'; //菜单 - 弹出拍照或者相册发图
const EVENT_MENU_PIC_WEIXIN = 'pic_weixin'; //菜单 - 弹出微信相册发图器
const EVENT_MENU_LOCATION = 'location_select'; //菜单 - 弹出地理位置选择器
const EVENT_SEND_MASS = 'MASSSENDJOBFINISH'; //发送结果 - 高级群发完成
const EVENT_SEND_TEMPLATE = 'TEMPLATESENDJOBFINISH';//发送结果 - 模板消息发送结果
$token
可参考test目录下的qydemo.php
include "wechat.class.php";
$options = array(
'token'=>'9Ixxxxxxx', //填写应用接口的Token
'encodingaeskey'=>'d4o9WVg8sxxxxxxxxxxxxxxxxxxxxxx',//填写加密用的EncodingAESKey
'appid'=>'wxa07979baxxxxxxxx', //填写高级调用功能的appid
);
$weObj = new Wechat($options);
$weObj->valid(); //注意, 企业号与普通公众号不同,必须打开验证,不要注释掉
$type = $weObj->getRev()->getRevType();
switch($type) {
case Wechat::MSGTYPE_TEXT:
$weObj->text("hello, I'm wechat")->reply();
exit;
break;
case Wechat::MSGTYPE_EVENT:
break;
case Wechat::MSGTYPE_IMAGE:
break;
default:
$weObj->text("help info")->reply();
}