Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #57 from mingyoung/open_platform
Browse files Browse the repository at this point in the history
Add open platform doc
  • Loading branch information
overtrue authored Dec 28, 2016
2 parents ba8f3b5 + 72703e3 commit f946847
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 8 deletions.
14 changes: 7 additions & 7 deletions anaylsis.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ $stats = $app->stats;
+ `array userReadHourly($from, $to)` 获取图文统计分时数据, 最大时间跨度:**1**;
+ `array userShareSummary($from, $to)` 获取图文分享转发数据, 最大时间跨度:**7**;
+ `array userShareHourly($from, $to)` 获取图文分享转发分时数据, 最大时间跨度:**1**;
+ `array upstreamMesssageSummary($from, $to)` 获取消息发送概况数据, 最大时间跨度:**7**;
+ `array upstreamMesssageHourly($from, $to)` 获取消息发送分时数据, 最大时间跨度:**1**;
+ `array upstreamMesssageWeekly($from, $to)` 获取消息发送周数据, 最大时间跨度:**30**;
+ `array upstreamMesssageMonthly($from, $to)` 获取消息发送月数据, 最大时间跨度:**30**;
+ `array upstreamMesssageDistSummary($from, $to)` 获取消息发送分布数据, 最大时间跨度:**15**;
+ `array upstreamMesssageDistWeekly($from, $to)` 获取消息发送分布周数据, 最大时间跨度:**30**;
+ `array upstreamMesssageDistMonthly($from, $to)` 获取消息发送分布月数据, 最大时间跨度:**30**;
+ `array upstreamMessageSummary($from, $to)` 获取消息发送概况数据, 最大时间跨度:**7**;
+ `array upstreamMessageHourly($from, $to)` 获取消息发送分时数据, 最大时间跨度:**1**;
+ `array upstreamMessageWeekly($from, $to)` 获取消息发送周数据, 最大时间跨度:**30**;
+ `array upstreamMessageMonthly($from, $to)` 获取消息发送月数据, 最大时间跨度:**30**;
+ `array upstreamMessageDistSummary($from, $to)` 获取消息发送分布数据, 最大时间跨度:**15**;
+ `array upstreamMessageDistWeekly($from, $to)` 获取消息发送分布周数据, 最大时间跨度:**30**;
+ `array upstreamMessageDistMonthly($from, $to)` 获取消息发送分布月数据, 最大时间跨度:**30**;
+ `array interfaceSummary($from, $to)` 获取接口分析数据, 最大时间跨度:**30**;
+ `array interfaceSummaryHourly($from, $to)` 获取接口分析分时数据, 最大时间跨度:**1**;

Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ EasyWeChat 的安装非常简单,因为它是一个标准的 [Composer](https:

- 具备 PHP 基础知识,不要连闭包是啥都不明白,可以参考我在知乎的回答: [想要开发自己的PHP框架需要那些知识储备?](http://www.zhihu.com/question/26635323/answer/33812516)
- 熟悉 PHP 常见的知识:自动加载、composer 的使用、JSON 处理、Curl 的使用等;
- **仔细阅读并看懂** (不是**看过**,是**看明白+看完** :exclamation:[微信官方文档](http://mp.weixin.qq.com/wiki/13/80a1a25adbc46faf2716774c423b3151.html)
- **仔细阅读并看懂** (不是**看过**,是**看明白+看完** :exclamation:[微信官方文档](http://mp.weixin.qq.com/wiki/13/80a1a25adbc46faf2716774c423b3151.html) [微信开放平台文档](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318292&token=&lang=zh_CN)
- 明白微信接口的组成,自有服务器、微信服务器、公众号(还有其它各种号)、测试号、以及通信原理(交互过程);
- 了解基本的 HTTP 协议,Header 头、请求方式(GET\POST\PUT\PATCH\DELETE)等;
- 基本的 Debug 技能,查看 php 日志,nginx 日志等。
Expand Down
98 changes: 98 additions & 0 deletions open_platform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
title: 微信开放平台
---

### 实例化

```php
<?php
use EasyWeChat\Foundation\Application;

$options = [
// ...
'open_platform' => [
'app_id' => 'component-app-id',
'secret' => 'component-app-secret',
'token' => 'component-token',
'aes_key' => 'component-aes-key'
],
// ..
];

$app = new Application($options);
$open_platform = $app->open_platform;
```

### 监听微信服务器推送事件

```php

$open_platform->server->listen(function ($event) {
switch ($event->InfoType) {
case 'authorized': // 授权成功
// logic code here...
case 'unauthorized': // 取消授权
// logic code here...
case 'updateauthorized': // 授权更新
// logic code here...
}
});
```


### 推送component_verify_ticket协议

在公众号第三方平台创建审核通过后,微信服务器会向其“授权事件接收URL”每隔10分钟定时推送component_verify_ticket。SDK内部已实现缓存component_veirfy_ticket,无需开发者另行缓存。

注:需要在URL路由中写上触发代码,并且注册路由后需要等待微信服务器推送verify_ticket,才能进行后续操作,否则报"Component verify ticket does not exists."

```php
// Example
public function serve(){
return $open_platform->server->listen();
}

```


### 获取预授权网址
```php
$open_platform->pre_auth
->setRedirectUri('http://domain.com/callback')
->getAuthLink();

```

用户授权后会带上code跳转到$redirect_uri

###### 使用授权码换取公众号的接口调用凭据和授权信息
```php
$authorizer = $open_platform->authorizer;

// 使用授权码换取公众号的接口调用凭据和授权信息
$authorizer->getAuthInfo($authorization_code);
```


##### 获取授权方的公众号帐号基本信息
```php
$authorizer = $open_platform->authorizer;

$authorizer->getAuthorizerInfo($authorizer_appid);

```

##### 获取授权方的选项设置信息
```php
$authorizer = $open_platform->authorizer;

$authorizer->getAuthorizerOption($authorizer_appid, $option_name);

```

##### 设置授权方的选项信息
```php
$authorizer = $open_platform->authorizer;

$authorizer->setAuthorizerOption($authorizer_appid, $option_name, $option_value);

```

0 comments on commit f946847

Please sign in to comment.