|
@@ -10,8 +10,29 @@ weixin developer SDK.
|
|
|
http://mp.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3%E6%8C%87%E5%8D%97
|
|
|
|
|
|
wechat.class.php调用官方API, 支持链式调用操作 ;
|
|
|
-wechatext.class.php为非官方API,需要配置公众平台账户和密码,能实现主动点对点微信,此方式不保证长期有效。
|
|
|
-wechatauth.class.php为通过微信二维码登陆微信的API, 能同时实现在网站同步登陆.
|
|
|
+wechatext.class.php为非官方API,需要配置公众平台账户和密码,能实现对已关注用户的点对点微信,此方式不保证长期有效。
|
|
|
+类方法里提及的用户id在接口返回结构里表述为FakeId是同一概念, 在下面wechatauth类里则表示为Uin, 用户id对应的微信号必须通过getInfo()方法通过返回数组的Username值获取, 但非关注关系用户资料不能获取.
|
|
|
+调用下列方法前必须经过login()方法和checkValid()验证方法才能获得调用权限.
|
|
|
+类主要方法:
|
|
|
+ * send($id,$content) 向某用户id发送微信文字信息
|
|
|
+ * batch($ids,$content) 批量向一批用户发送微信文字信息
|
|
|
+ * sendNews($account,$title,$summary,$content,$pic,$srcurl='') 向一个微信账户发送图文信息
|
|
|
+ * getInfo($id) 根据id获取用户资料,注: 非关注关系用户资料不能获取
|
|
|
+ * getNewMsgNum($lastid) 获取从$lastid算起新消息的数目
|
|
|
+ * getTopMsg() 获取最新一条消息的数据, 此方法获取的消息id可以作为检测新消息的$lastid依据
|
|
|
+ * getMsg($lastid,$offset=0,$perpage=50,$day=0,$today=0,$star=0) 获取最新的消息列表, 列表将返回消息id, 用户id, 消息类型, 文字消息等参数
|
|
|
+ * 消息返回结构: {"id":"消息id","type":"类型号(1为文字,2为图片,3为语音)","fileId":"0","hasReply":"0","fakeId":"用户uid","nickName":"昵称","dateTime":"时间戳","content":"文字内容"}
|
|
|
+ * getMsgImage($msgid,$mode='large') 若消息type类型为2, 调用此方法获取图片数据
|
|
|
+ * getMsgVoice($msgid) 若消息type类型为3, 调用此方法获取语音数据
|
|
|
+
|
|
|
+wechatauth.class.php为通过微信二维码登陆微信的API, 能实现第三方网站同步登陆, 验证步骤请看test3.php例子.
|
|
|
+类主要方法:
|
|
|
+ * get_login_code() 获取登陆授权码, 通过授权码才能获取二维码
|
|
|
+ * get_code_image($code='') 将上面获取的授权码转换为图片二维码
|
|
|
+ * verify_code() 鉴定是否登陆成功,返回200为最终授权成功.
|
|
|
+ * get_login_cookie() 鉴定成功后调用此方法即可获取用户基本信息
|
|
|
+ * sendNews($account,$title,$summary,$content,$pic,$srcurl='') 向一个微信账户发送图文信息
|
|
|
+ * get_avatar($url) 获取用户头像图片数据
|
|
|
|
|
|
* 基础API调用示例:
|
|
|
```php
|
|
@@ -57,9 +78,13 @@ switch($type) {
|
|
|
if ($wechat->checkValid()) {
|
|
|
// 获取用户信息
|
|
|
$data = $wechat->getInfo('3974255');
|
|
|
- // 主动发消息
|
|
|
- //$wechat->send('3974255','hello '.time());
|
|
|
var_dump($data);
|
|
|
+ // 获取最新一条消息
|
|
|
+ $topmsg = $wechat->getTopMsg();
|
|
|
+ var_dump($topmsg);
|
|
|
+ // 主动回复消息
|
|
|
+ if ($topmsg && $topmsg['hasReply']==0)
|
|
|
+ $wechat->send($topmsg['fakeId'],'hi '.$topmsg['nickName'].',rev:'.$topmsg['content']);
|
|
|
}
|
|
|
```
|
|
|
|