一、access_token

1)两种access_token,网页授权access_token和普通access_token

1、微信网页授权是通过OAuth2.0机制实现的,在用户授权给公众号后,公众号可以获取到一个网页授权特有的接口调用凭证(网页授权access_token),通过网页授权access_token可以进行授权后接口调用,如获取用户基本信息。

2、其他微信接口,需要通过基础支持中的“获取access_token”接口来获取到的普通access_token调用。access_token是公众号的全局唯一票据,access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。

2)分别获取access_token

1、网页授权的:点击查看网页授权获取用户基本信息文档,通过查看这个文档,

可以看到通过code换取网页授权access_token,而这个code是通过微信的一个授权链接获取到的,然后再根据文档中的请求获取到的,具体的链接地址和参数可以参考文档。

/**
* 创建一个需要通过微信的OAuth2.0认证的服务url
* @param $url 服务号需要认证访问的url
* @param $scope string snsapi_userinfo | snsapi_base
* snsapi_userinfo 可以用来获取用户信息
* snsapi_base 可以用来获取openid
* @param string $state 自定义状态值
* 此处约定为from_weixin代表是从微信认证过来,一般无需轻易变化
* @return string 返回认证url地址
*/
public function createAuthUrl($url, $scope = 'snsapi_base', $state = 'from_weixin')
{
$url = strval($url);
$authUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize';
/**
* 此处有大坑,请不要打乱param的顺序
* 否则微信认证界面会出现白屏
*/
$param = array(
'appid' => $this->appId,
'redirect_uri' => urlencode($url),
'response_type' => 'code',
'scope' => $scope,
'state' => $state
); $seg = array();
foreach ($param as $k => $v) {
$seg[] = "{$k}={$v}";
}
return $authUrl . '?' . join('&', $seg) . '#wechat_redirect';
}

2、普通的:点击查看获取access token文档,通过三个参数获取到。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqgAAABrCAIAAAA0Oec4AAAPNUlEQVR4nO3dO3LiShiG4bMnqrwRaw/kmIg9UAVF5JAitQICV7EBR9iBgkOd2M7tVJHnBLr0//dNkgED0+8TeWxZUrda+voiM//8AQAAyfjn0icAAAB+D8EPAEBCCH4AABJC8AMAkBCCHwCAhBD8AAAkhOAHACAhBD8AAAk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nOd5WKt+unsI73sfzi1hJaLqfctBmMx76zWFePCXsks731kLVL6yiHevrLdgxOyofwTvDf7IPLZnz71f7lv7dhILfveOFe2ku3RmUBK5UvqIpf26UL+Site4dh0jfqsIluY8PV2NSDXKkWK4VyGIm8JqkNH34ELB32wZeLnPc+eqp7No7b6X7NZi+/7XUdakZwXKXEpnjd9ZCBibl3OHPEl2ViW7i82eAoavl91gmrTrH/z9/44/Wg+ytR/s7f03hbeD4rw/6HYyvHS/RNXPsBG/+6f59oyLf7mwLoW127Y7omfadIUkFPyD9VvxakVe6zvVIS7q9z/ta/Bfsp2rQfd4T+2X/fqte+xnUuG8ArehP4yB63ZDwf+jJyPBH9Frz81Ea+m8En8619FBPltJ7SXMwF91qq7PtQe/vUR9Zf220yP48Re5oeC/1kOczO+P+PsRuTVoeuD2XKakYp1CffOqgz85BD/+IvzvfAAAJITgBwAgIQQ/AAAJIfgBAEgIwQ8AQEIIfgAAEjIg+Iui+Pz8vPQJAwCAH/r6+iqKom/wv7+/Hw6Hr6+vS582AAAY7Ovr67///nt/f+8b/N/f3x8fH0VRvAIAgFtTFMX7+/v393ff4AcAAH8lgh8AgIQQ/AAAJITgBwAgIQQ/AAAJIfgBAEgIwQ8AQEIIfgAAEkLwAwCQEIIfAICEEPwAACSE4AcAICEEPwAACfkfr0rOpAtcJNEAAAAASUVORK5CYII=" alt="" />

这里需要注意的是,获取到的token,是有时效性的,2 个小时,所以我会保存在MongoDB中,先从数据库中比对超时了没有,没有的话就直接从数据库中获取,减少不必要的请求。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAacAAACNCAIAAACczSIrAAAdoUlEQVR4nO1dy3IcN5bF52irZdXGZpCaCH0B/yCnZZGUppdaau+oMmXLG2lRMdELOuxQaIpOSaOexcy2YxTu8Vupnle7Ldu03pbstj1ds8gX7gPIm6hEZhV5T9xQFFFI4OLg4iSALCXM7GCupqamdnLMhF32T7f/dXDX18WUK+VKuRqcq4UF89OviwCbHczDLjyBplwp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PKi3cmUP2sR09LoHp+UTcd1FeNptqzqsfGAKqc96OxTPvaYHTqbQ5hJktILuLjytLFyj8Y2TTluwKqnJ0PGxrr9hn7IzZ1142pIKFdyYNXTkyFjY92iU1VvPaBcyYFVT0+GjI11i05VvfWAciUHVj09GTI2NDrlUK7kUK7kwKqnJ0PGhkanHMqVHMqVHFj19GTI2NDolEO5kkO5kgOrnp4MGdv0BD/lSrkanCugenoyZGzc13uyGMqVHMqVHIgrPRkyOjQ65VCu5FCu5EBc/T8EvFQCWQzAaAAAAABJRU5ErkJggg==" alt="" />

二、推送日志

  在与微信的交互中,会产生很多日志信息,并且开发的时候经常需要分析这些日志,这里我将日志都保存在了MongoDB中。MongoDB方便的地方是任何结构的数据都能放在一个document中,不像MySQL要定义好字段名,我经常调试的时候将各种结构放在一个document中。

在微信的入口页面中,也就是前面提到的URL(服务器地址),会在这里面做保存日志的逻辑。逻辑包括关注的时候推送一条消息,二维码扫描关注,点击某个菜单产生事件,点击菜单的超链接等。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmsAAAB0CAIAAABVMeLUAAAShUlEQVR4nO3dvW8bSZrHcXlsj4nbPXiVDIybwdqgg13MAjcYLGA4OMCDSejMExzgDTZaYwEDw2CDu1jxBgL/gA4Y9yYMO7rIMhiMAEEzwQQtxf4HrFDgBf1WT9VT3V1Fii2a309isdlvlFn101P9drACAADhDobeAQAAdhIJCgBADBIUAIAYJCgAADFIUAAAYpCgAADEIEEBAIhBggIAEIMEBQAgBgkKAEAMEhTYX7/++ut8Pj/SzOfzs7OzoXcQuNVI0H13AOyNoVsbPjV8pfbd0H0asD1DtzZ8avhK7buh+zRge4ZubfjU6F+pZXp8nC7905bpsSnJ8tZFC3mWFHPmWWIuar6syVX4VypmsZZXJtXzmrvsnVZMdjacZ4mYdZkeq8t2O59NxpPZecSSgRbT8Xi6UKcM3acB23PzTQ37JT5B6/fzLDESxBd2eZZU0+sfi9Qy3qlntTPZw5jNSMBqhcoke95m+hoJ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yASAC/4A8ArgoWC4AROAflDz6CQAAAHB5/h8jiUO7GkyJHwAAAABJRU5ErkJggg==" alt="" />

1、代码中包括签名验证逻辑

2、通过file_get_contents('php://input')来获取请求数据,就是下面的getRawMsg方法

3、将推送日志直接塞入到MongoDB中

4、将接收到的请求信息SimpleXMLElement对象,就是下面的parseMsg方法

5、handleEventMsg就是在处理各种不同情况了

/**
* 微信公众号入口
*/
public function actionPortal()
{
$weixin = new Weixin();
//签名验证逻辑
// if($weixin->checkSignature()){
// echo $_GET['echostr'];
// }
// exit;
//读取原始请求数据
$msg = $weixin->getRawMsg(); //推送日志
$pushlog = new WeixinPushLog();
$pushlog->logWeixinPush($msg); $msgObj = $weixin->parseMsg($msg);
if ($msgObj === false || !is_object($msgObj)) {
exit;
}
switch ($msgObj->MsgType) {
case 'event' : //接收事件消息
$this->handleEventMsg($msgObj);
break;
default :
//todo
break;
}
}
    public function getRawMsg()
{
return file_get_contents('php://input');
} /**
* 解析接收到的消息
* @param string $msg 消息体
* @return bool|SimpleXMLElement
*/
public function parseMsg($msg = '')
{
if (!$msg || empty($msg)) {
return false;
}
$msgObj = simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($msgObj === false || !($msgObj instanceof \SimpleXMLElement)) {
return false;
}
return $msgObj;
}

6、如果要推送消息,die这个方法得要加上

7、下面的代码只列举了两种事件情况,一种是订阅、一种是点击事件

8、createRawTuWenMsg是在拼接XML,点击查看模板消息接口

private function handleEventMsg($msgObj)
{
$weixin = new Weixin();
$openId = $msgObj->FromUserName;
$fromUserName = $msgObj->ToUserName;
//未关注,关注后推送
if ($msgObj->Event == 'subscribe') {
$pushData['PicUrl'] = 'http://mmbiz.qpic.cn/';
$pushData['Title'] = '基因检测,带你一起探索生命的奥妙 ';
$pushData['Description'] = '为什么不同人在身高、体重、肤色和形状上长得不一样?但是往往又和自己的父母相似?';
$pushData['Url'] = 'http://mp.weixin.qq.com';
$msg = $weixin->createRawTuWenMsg($fromUserName, $openId, array($pushData)); die($msg);
}elseif($msgObj->Event == 'CLICK'){
//die($msg);
}
}
public function createRawTuWenMsg($fromUserName, $toUserName, $items = array())
{
if (!is_array($items)) {
return '';
}
$count = count($items);
$its = '';
foreach ($items as $item) {
$its .= <<<ITEMTPL
<item>
<Title><![CDATA[{$item['Title']}]]></Title>
<Description><![CDATA[{$item['Description']}]]></Description>
<PicUrl><![CDATA[{$item['PicUrl']}]]></PicUrl>
<Url><![CDATA[{$item['Url']}]]></Url>
</item>
ITEMTPL;
} $msg = <<<MSG
<xml>
<ToUserName><![CDATA[{$toUserName}]]></ToUserName>
<FromUserName><![CDATA[{$fromUserName}]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>{$count}</ArticleCount>
<Articles>
{$its}
</Articles>
</xml>
MSG;
return $msg;
}

demo下载:

github地址:https://github.com/pwstrick/weixin_demo

CSDN地址:http://download.csdn.net/detail/loneleaf1/9045731

微信公众平台开发(二)——access_token、日志的更多相关文章

  1. Java微信公众平台开发(二)--微信服务器post消息体的接收

    转自: http://www.cuiyongzhi.com/post/39.html 在上一篇的文章中我们详细讲述了如何将我们的应用服务器和微信腾讯服务器之间的对接操作,最后接入成功,不知道你有没有发 ...

  2. 第五篇 :微信公众平台开发实战Java版之如何获取公众号的access_token以及缓存access_token

    一.access_token简介 为了使第三方开发者能够为用户提供更多更有价值的个性化服务,微信公众平台 开放了许多接口,包括自定义菜单接口.客服接口.获取用户信息接口.用户分组接口.群发接口等, 开 ...

  3. Senparc.Weixin.MP SDK 微信公众平台开发教程(十二):OAuth2.0说明

    紧接上一篇<Senparc.Weixin.MP SDK 微信公众平台开发教程(十一):高级接口说明>,这里专讲OAuth2.0. 理解OAuth2.0 首先我们通过一张图片来了解一下OAu ...

  4. 微信公众平台开发-access_token获取及应用(含源码)

    微信公众平台开发-access_token获取及应用(含源码)作者: 孟祥磊-<微信公众平台开发实例教程> 很多系统中都有access_token参数,对于微信公众平台的access_to ...

  5. Java微信公众平台开发(十二)--微信用户信息的获取

    转自:http://www.cuiyongzhi.com/post/56.html 前面的文章有讲到微信的一系列开发文章,包括token获取.菜单创建等,在这一篇将讲述在微信公众平台开发中如何获取微信 ...

  6. Senparc.Weixin.MP SDK 微信公众平台开发教程(二):成为开发者

    Senparc.Weixin.MP SDK 微信公众平台开发教程(二):成为开发者 这一篇主要讲作为一名使用公众平台接口的开发者,你需要知道的一些东西.其中也涉及到一些微信官方的规定或比较掩蔽的注意点 ...

  7. Senparc.Weixin.MP SDK 微信公众平台开发教程(二十):使用菜单消息功能

    在<Senparc.Weixin.MP SDK 微信公众平台开发教程(十一):高级接口说明>教程中,我们介绍了如何使用“客服接口”,即在服务器后台,在任意时间向微信发送文本.图文.图片等不 ...

  8. Java开发微信公众号(二)---开启开发者模式,接入微信公众平台开发

    接入微信公众平台开发,开发者需要按照如下步骤完成: 1.填写服务器配置 2.验证服务器地址的有效性 3.依据接口文档实现业务逻辑 资料准备: 1.一个可以访问的外网,即80的访问端口,因为微信公众号接 ...

  9. Senparc.Weixin.MP SDK 微信公众平台开发教程(二十一):在小程序中使用 WebSocket (.NET Core)

    本文将介绍如何在 .NET Core 环境下,借助 SignalR 在小程序内使用 WebSocket.关于 WebSocket 和 SignalR 的基础理论知识不在这里展开,已经有足够的参考资料, ...

  10. Senparc.Weixin.MP SDK 微信公众平台开发教程(二十二):如何安装 Nuget(dll) 后使用项目源代码调试

    最近碰到开发者问:我使用 nuget 安装了 Senparc.Weixin SDK,但是有一些已经封装好的过程想要调试,我又不想直接附加源代码项目,这样就没有办法同步更新了,我应该怎么办? 这其实是一 ...

随机推荐

  1. Ubuntu下安装mod_python报错(GIT错误)

    Ubuntu下安装mod_python3.4.1版本报出如下错误: writing byte-compilation script '/tmp/tmpE91VXZ.py' /usr/bin/pytho ...

  2. content内网,会显示内容,没有内容可地址存在就是这个情况

    漏洞地址:http://note.youdao.com/memory/?url=http://www.wooyun.org(如需登录,请注册登录) 正文预览的地方会读取URL地址的<meta n ...

  3. 执行CSRF令牌所有形式使用POST方法

    从而在并未授权的情况下执行在权限保护之下的操作,有很大的危害性. php CSRF Guardfunction csrfguard_generate_token($unique_form_name){ ...

  4. PHP好任性 —— 大小写敏感有两种规则,然而并没有什么特别原因

    大小写敏感 变量.常量大小写敏感 大小写不敏感 类名.方法名.函数名.魔法变量大小写不敏感 原因 有人原引了Rasmus 在一次会议上的发言大意: "I'm definitely not a ...

  5. 用rem实现WebApp自适应的优劣分析

    关于rem实现屏幕自适应布局的讨论还是比较多的,刚好我也看到使用rem实现自适应的web app,所以也来凑下热闹. 说起rem,免不了要联系到em.px,这里简单提提他们的定义和特点. 1. px: ...

  6. .NET中那些所谓的新语法之三:系统预定义委托与Lambda表达式

    开篇:在上一篇中,我们了解了匿名类.匿名方法与扩展方法等所谓的新语法,这一篇我们继续征程,看看系统预定义委托(Action/Func/Predicate)和超爱的Lambda表达式.为了方便码农们,. ...

  7. 《R in Action》读书笔记(2)

    MindMapper 原文件

  8. [备忘]Redis运行出现Client sent AUTH, but no password is set

    原因:程序提供了密码,但是redis.conf中并没有设置密码. 附加问题:如果redis.conf中设置了密码,有可能会导致服务无法启动,报5013错误.可能是访问权限的问题.

  9. [Hadoop大数据]——Hive部署入门教程

    Hive是为了解决hadoop中mapreduce编写困难,提供给熟悉sql的人使用的.只要你对SQL有一定的了解,就能通过Hive写出mapreduce的程序,而不需要去学习hadoop中的api. ...

  10. salesforce 零基础学习(四十六)动态美观显示列表中记录的审批状态

    项目中,申请者申请某些事项以后,常常需要在申请列表中查看当前申请的记录所在的审批状态,动态美观的显示状态可以使UI更符合客户要求,比如下面这样. 以Goods__c表为例,申请者申请的一些采购以前需要 ...