This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from finecho/patch-2
[docs]update open-work/server.md
- Loading branch information
Showing
1 changed file
with
26 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,40 @@ | ||
# 服务端 | ||
|
||
## 企业微信第三方回调协议 | ||
企业微信第三方服务端推送和公众号一样,请参考:[公众号:服务端](/docs/{{version}}/official-account/server.md) | ||
|
||
## 第三方平台推送事件 | ||
|
||
SDK 默认会处理事件 `suite_ticket` ,并会缓存 `suite_ticket` | ||
企业微信第三方数据推送的有以下事件: | ||
|
||
- suite_ticket 推送 `suite_ticket` | ||
- 授权成功 `create_auth` | ||
- 授权变更 `change_auth` | ||
- 授权取消 `cancel_auth` | ||
- 通讯录变更 `change_contact` | ||
- 共享应用事件回调 `share_agent_change` | ||
|
||
> {info} 需要注意的是:授权成功、变更授权、取消授权通知时间的响应必须在1000ms内完成,以保证用户安装应用的体验。建议在接收到此事件时 立即回应企业微信,之后再做相关业务的处理。 | ||
## 自定义消息处理器 | ||
|
||
> *消息处理器详细说明见:公众号开发 - 服务端一节* | ||
```php | ||
$server = $app->server; | ||
// 授权成功事件 | ||
$server->handleAuthCreated(callable | string $handler); | ||
|
||
$server->push(function ($message) { | ||
//指令回调 | ||
if (isset($message['InfoType'])) { | ||
switch ($message['InfoType']) { | ||
//推送suite_ticket | ||
case 'suite_ticket': | ||
break; | ||
//授权成功通知 | ||
case 'create_auth': | ||
break; | ||
//变更授权通知 | ||
case 'cancel_auth': | ||
break; | ||
//通讯录事件通知 | ||
case 'change_contact': | ||
switch ($message['ChangeType']) { | ||
case 'create_user': | ||
return '新增成员事件'; | ||
break; | ||
case 'update_user': | ||
return '更新成员事件'; | ||
break; | ||
case 'delete_user': | ||
return '删除成员事件'; | ||
break; | ||
case 'create_party': | ||
return '新增部门事件'; | ||
break; | ||
case 'update_party': | ||
return '更新部门事件'; | ||
break; | ||
case 'delete_party': | ||
return '删除部门事件'; | ||
break; | ||
case 'update_tag': | ||
return '标签成员变更事件'; | ||
break; | ||
} | ||
break; | ||
default: | ||
return 'fail'; | ||
break; | ||
} | ||
} | ||
// 授权变更事件 | ||
$server->handleAuthChanged(callable | string $handler); | ||
|
||
//数据回调 | ||
if(isset($message['MsgType'])){ | ||
switch ($message['MsgType']) { | ||
case 'event': | ||
return '事件消息';//详情 https://work.weixin.qq.com/api/doc/90001/90143/90376#%E5%88%A0%E9%99%A4%E6%88%90%E5%91%98%E4%BA%8B%E4%BB%B6 | ||
break; | ||
case 'text': | ||
return '文本消息';//详情 https://work.weixin.qq.com/api/doc/90001/90143/90375#%E5%9B%BE%E7%89%87%E6%B6%88%E6%81%AF | ||
break; | ||
case 'image': | ||
return '图片消息'; | ||
break; | ||
//等等...不再一一举例 | ||
default: | ||
return '其他消息'; | ||
break; | ||
} | ||
} | ||
// 授权取消事件 | ||
$server->handleAuthCancelled(callable | string $handler); | ||
|
||
}); | ||
$response = $server->serve(); | ||
$response->send(); | ||
// 通讯录变更事件 | ||
$server->handleContactChanged(callable | string $handler); | ||
|
||
// 共享应用事件 | ||
$server->handleShareAgentChanged(callable | string $handler); | ||
|
||
// suite_ticket 推送事件 | ||
$server->handleSuiteTicketRefreshed(callable | string $handler); | ||
``` | ||
|
||
> {warning} 注意:如果你自行处理了 SuiteTicket 推送,你必须同时设置 ProviderAccessToken 类,因为 ProviderAccessToken 依赖它。 |