呵呵,大家好。这个微信php类库来自于网络上多人智慧的结晶,特别是被动响应部分基本上都是来自于:dodgepudding。在此向那些牛人们致敬。 说明一下,我是个菜鸟,所以在代码上特别的凌乱,希望有热心人士指点。主动发送部分可能因为腾讯的调整失效,发现问题请联系我:ligboy#gmail.com 欢迎大家fork或者push 特别感谢
感谢各位的支持,很高兴能给你们提供一点思路。在很多问题上我都与pinghui大哥讨论,他给我提供了很多建议,我没有资格感谢,嘿嘿,因为这里包含了他的很多贡献,Wechat-php同样属于他。 特性说明
被动响应端没有什么好讲的,依旧是没有解决语音消息获取问题。
主动发送方面,群发的效率还是比较高的,测试,一次群发80条消息,耗时9950.0999ms,还是很不错的。主动发送单挑消息也没什么好讲的,跟大家的都差不多,只是这里要说如果大家要用,尽量建立一个消息队列,然后批量发送,这样的效率比较高,后面更新加入针对消息队列的批量发送,不仅仅是现在的群发同一条小时,另外谁有兴趣写一下可以提交一下。
这么久没有更新,其实是一直在测试比较重点的关联fakeid和openid的部分,现在放出其中的一种简单实现:被动响应依据时间戳判断关联fakeid与openid。
- 采用另外一种主动方式获取关联fakeid与openid的关联。
date_default_timezone_set('Asia/Shanghai');
include "../Wechat.class.php";
//加载设置文件
$wechatOptions = require('./configure.php');
$wechatObj = new Wechat($wechatOptions);
$wechatObj->valid();//可以在认证后注释掉(只是这样可能不安全)
$wechatObj->positiveInit(); //主动响应组件初始化
$wechatObj->setAutoSendOpenidSwitch(TRUE); //设置自动附带发送Openid
$wechatObj->setPassiveAscSwitch(TRUE, TRUE); //设置打开被动关联组件,并获取用户详细信息
$wechatObj->getRev();
//被动响应实例
$wechatObj->valid(); //验证请求来源是否合法,在通过平台验证后可以去掉,但是不安全啊。
$msgtype = $weObj->getRev()->getRevType();
switch(msg$type) {
case Wechat::MSGTYPE_TEXT:
$wechatObj->text("你好我是微信小机器人")->reply();
exit;
break;
case Wechat::MSGTYPE_EVENT:
$revEvent = array();
$revEvent = $this->wechatObj->getRevEvent();
switch ($revEvent['event']) {
//关注订阅事件
case "subscribe":
$wechatObj->text("你好我是微信小机器人")->reply();
break;
//取消关注订阅事件
case "unsubscribe":
//做一些删除用户记录之类的事情
break;
}
break;
case Wechat::MSGTYPE_IMAGE:
break;
case Wechat::MSGTYPE_VOICE:
break;
case Wechat::MSGTYPE_MUSIC:
break;
case Wechat::MSGTYPE_LOCATION:
break;
case Wechat::MSGTYPE_LINK:
break;
default:
$wechatObj->text($wechatObj->wechatObj)->reply();
}
//主动发送消息示例
//群发消息
$fakeids = array("823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881","823058881");
//接收返回结果数组
$batresult = $wechatObj->batSend($fakeids,"这是一种问候啊!\n下个10分钟再见。");
//单条消息发送
$singleresult = $wechatObj->send("823058881", "这是一种问候啊!");