非官方扩展API,需要配置公众平台账户和密码,能实现对已关注用户的点对点微信,此方式不保证长期有效。
类方法里提及的用户id在接口返回结构里表述为FakeId, 属同一概念, 在下面wechatauth类里则表示为Uin, 用户id对应的微信号必须通过getInfo()方法通过返回数组的Username值获取, 但非关注关系用户资料不能获取.
调用下列方法前必须经过login()方法和checkValid()验证方法才能获得调用权限. 有的账户无法通过登陆可能因为要求提供验证码, 可以手动登陆后把获取到的cookie写进程序存放cookie的文件解决.
程序使用了经过修改的snoopy兼容式HTTP类方法, 在类似BAE/SAE云服务器上可能不能正常运行, 因为云服务的curl方法是经过重写的, 某些header参数如网站来源参数不被支持.
//test2.php
include "wechatext.class.php";
function logdebug($text){
file_put_contents('./data/log.txt',$text."\n",FILE_APPEND);
};
$options = array(
'account'=>'demo@domain.com',
'password'=>'demo',
'datapath'=>'./data/cookie_',
'debug'=>true,
'logcallback'=>'logdebug'
);
$wechat = new Wechatext($options);
if ($wechat->checkValid()) {
// 获取用户信息
$data = $wechat->getInfo('3974255');
var_dump($data);
// 获取最新一条消息
$topmsg = $wechat->getTopMsg();
var_dump($topmsg);
// 主动回复消息
if ($topmsg && $topmsg['has_reply']==0)
$wechat->send($topmsg['fakeid'],'hi '.$topmsg['nick_name'].',rev:'.$topmsg['content']);
}