代码拉取完成,页面将自动刷新
微信公众平台php开发包,细化各项接口操作,支持链式调用,欢迎Fork此项目
weixin developer SDK.
使用前需先打开微信帐号的开发模式,详细步骤请查看微信公众平台接口使用说明:
http://mp.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
var dataForWeixin={
appId:"",
MsgImg:"消息图片路径",
TLImg:"时间线图路径",
url:"分享url路径",
title:"标题",
desc:"描述",
fakeid:"",
callback:function(){}
};
//test1.php
include "wechat.class.php";
$options = array(
'token'=>'tokenaccesskey' //填写你设定的key
);
$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();
}
//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']);
}
//test3.php
include "../wechatauth.class.php";
session_start();
$sid = session_id();
$options = array(
'account'=>$sid,
'datapath'=>'../data/cookiecode_',
);
$wechat = new Wechatauth($options);
if (isset($_POST['code'])) {
$logincode = $_POST['code'];
$vres = $wechat->set_login_code($logincode)->verify_code();
if ($vres===false) {
$result = array('status'=>0);
} else {
$result = array('status'=>$vres);
if ($vres==200) {
$result['info'] = $wechat->get_login_info();
$result['cookie'] = $wechat->get_login_cookie(true);
}
}
die(json_encode($result));
}
$logincode = $wechat->get_login_code(); //获取授权码
$qrimg = $wechat->get_code_image(); //待输出的二维码图片
HTML部分请看test/test3.php, 主要是定时ajax查询是否已经授权成功
This is licensed under the GNU LGPL, version 2.1 or later.
For details, see: http://creativecommons.org/licenses/LGPL/2.1/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。