Skip to content

Commit

Permalink
first blood
Browse files Browse the repository at this point in the history
  • Loading branch information
pithyone committed Jul 30, 2017
0 parents commit 3060d0e
Show file tree
Hide file tree
Showing 66 changed files with 4,315 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
/vendor/
/composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 王兵

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Work WeChat

📦 最最最简单易用的[企业微信](https://work.weixin.qq.com/)SDK

## 介绍

虽然企业微信**很坑**,但是大厂的东西还是要去适配,所以有了这么个东西。

> 暂不支持企业支付相关接口,已列入后续开发计划
## 要求

- PHP >= 5.5.26

## 安装

```shell
composer require pithyone/wechat
```

## 用法

> 可直接参考 [demo](examples)
- [概述](docs/01-overview.md)
- [AccessToken](docs/02-token.md)
- [成员管理](docs/02-user.md)
- [部门管理](docs/03-department.md)
- [标签管理](docs/04-tag.md)
- [应用管理](docs/05-agent.md)
- [发送消息](docs/06-message.md)
- [接收消息](docs/07-receive.md)
- [被动回复消息](docs/08-reply.md)
- [JS-API](docs/09-js-api.md)
- [网页授权](docs/10-oauth.md)
- [自定义菜单](docs/11-menu.md)
- [素材管理](docs/12-media.md)

## 自定义

- [缓存](docs/100001-custom-cache.md)
- [日志](docs/100002-custom-log.md)

## 致谢

- [overtrue/wechat](https://github.com/overtrue/wechat)

## License

MIT
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "pithyone/wechat",
"type": "library",
"description": "企业微信SDK",
"license": "MIT",
"authors": [
{
"name": "wangbing",
"email": "[email protected]"
}
],
"require": {
"guzzlehttp/guzzle": "^6.3",
"openlss/lib-array2xml": "^0.5.1",
"doctrine/cache": "~1.6.2",
"monolog/monolog": "^1.23",
"voku/arrayy": "^3.6"
},
"autoload": {
"psr-4": {
"pithyone\\wechat\\": "src/"
}
}
}
81 changes: 81 additions & 0 deletions docs/01-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 概述

> SDK统一调用入口,所有**配置**都需要在初始化时引用,下方会给出完整配置。
## 注意

1. 企业微信每个应用彼此独立,所以每个应用的配置也需要分开
2. API接口调用依赖于企业微信应用,所以初始化接口前需要指定应用

## 完整配置

```php
<?php

return [
/**
* Debug 模式,用于记录调试日志
*/
'debug' => true,

/**
* 日志配置
*
* file:日志文件位置(绝对路径!!!),要求可写权限
*/
'log' => [
'file' => __DIR__ . '/../tmp/work-wechat.log',
],

/**
* 企业唯一ID,可在管理后台“我的企业”-“企业信息”下查看(需要有管理员权限)
*/
'corp_id' => 'your-corp-id',

/**
* 通讯录同步助手配置,可以对部门和成员进行查询、添加、修改、删除操作(其他应用无操作权限)
*
* token: 可任意填写,用于生成签名
* aes_key: 用于消息体的加密
* secret: 访问密钥,通讯录接口的密钥在“管理工具”-“通讯录同步”里面查看
*/
'contacts' => [
'token' => 'your-contacts-agent-token',
'aes_key' => 'your-contacts-agent-aes-key',
'secret' => 'your-contacts-agent-secret'
],

/**
* 其他应用配置,注意:需要使用的配置都需要按照如下格式进行添加
*
* test: 应用标识,可随意指定(不重复)
* agent_id:应用ID
* token: 可任意填写,用于生成签名
* aes_key: 用于消息体的加密
* secret: 访问密钥,可以在企业应用的详情里面手动生成
*/
'test' => [
'agent_id' => 'your-test-agent-id',
'token' => 'your-test-agent-token',
'aes_key' => 'your-test-agent-aes-key',
'secret' => 'your-test-agent-secret'
],

// ...
];
```

## 初始化

```php
$work = new Work($config);

// 设置需要操作的应用,注意:此处填写的是应用标识,事先需要在配置中定义
$test = $work->setAgentId('test');

// 设置需要操作的接口
$agent = $test->agent;

// 接口操作...
```

31 changes: 31 additions & 0 deletions docs/02-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# AccessToken

## 目录

- [获取实例](#获取实例)
- API接口
- [获取AccessToken](#获取AccessToken)

> 可直接参考 [demo](../examples/token.php)
## 获取实例

```php
<?php

use pithyone\wechat\Work;

// ...

$work = new Work($config);

$test = $work->setAgentId('test');

$token = $test->token;
```

## 获取AccessToken

```php
$token->get();
```
97 changes: 97 additions & 0 deletions docs/02-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 成员管理

## 目录

- [获取实例](#获取实例)
- API接口
- [创建成员](#创建成员)
- [读取成员](#读取成员)
- [更新成员](#更新成员)
- [删除成员](#删除成员)
- [批量删除成员](#批量删除成员)
- [获取部门成员](#获取部门成员)
- [获取部门成员详情](#获取部门成员详情)
- [userid转换成openid](#userid转换成openid)
- [openid转换成userid](#openid转换成userid)
- [二次验证](#二次验证)

> 使用通讯录同步助手的secret进行开发
> 可直接参考 [demo](../examples/user.php)
## 获取实例

```php
<?php

use pithyone\wechat\Work;

// ...

$work = new Work($config);

$contacts = $work->setAgentId('contacts');

$user = $contacts->user;
```

## 创建成员

```php
$user->create($data);
```

## 读取成员

```php
$user->get($userid);
```

## 更新成员

```php
$user->update($data);
```

## 删除成员

```php
$user->delete($userid);
```

## 批量删除成员

```php
$user->batchDelete([$userid1, $userid2, $userid3]);
```

## 获取部门成员

```php
$user->simpleLists($department_id, $fetch_child);
```

## 获取部门成员详情

```php
$user->lists($department_id, $fetch_child);
```

## userid转换成openid

```php
$user->convertToOpenId($userid);
```

## openid转换成userid

```php
$user->convertToUserId($open_id);
```

## 二次验证

```php
$user->authSuccess($userid);
```

54 changes: 54 additions & 0 deletions docs/03-department.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 部门管理

## 目录

- [获取实例](#获取实例)
- API接口
- [创建部门](#创建部门)
- [更新部门](#更新部门)
- [删除部门](#删除部门)
- [获取部门列表](#获取部门列表)

> 使用通讯录同步助手的secret进行开发
> 可直接参考 [demo](../examples/department.php)
## 获取实例

```php
<?php

use pithyone\wechat\Work;

// ...

$work = new Work($config);

$contacts = $work->setAgentId('contacts');

$department = $contacts->department;
```

## 创建部门

```php
$department->create($data);
```

## 更新部门

```php
$department->update($data);
```

## 删除部门

```php
$department->delete($id);
```

## 获取部门列表

```php
$department->lists($id);
```
Loading

0 comments on commit 3060d0e

Please sign in to comment.