一、概述
企业微信是腾讯推出结合微信社交的企业客户关系管理平台,同时提供开放接口供调用。但是直接调用接口实现业务功能涉及的软件栈比较复杂,需要一套更加简洁可用的框架供软件服务使用。为此,研发了一套PHP实现的前后端分离企业微信开源接口框架:奇辰Open-API。
二、开源框架架构
基于开源奇辰Open-API框架,SCRM后端服务已经对接了企业微信基础API,业务研发只需要调用开箱即用的SCRM后端服务API实现后端客户管理业务;前端基于开源框架的前端基础框架开发SCRM应用和SCRM后台,即可快速实现SCRM系统。
三、开源实现
1、企业微信同步
开发企业微信的首要工作是实现本地存储的部门、成员信息和企业微信第三方平台管理的部门、成员信息同步。为此,奇辰Open-API开源框架已经封装好了此项功能。如下图所示:
同步的企业微信第三方平台通讯录信息如下图所示:
- 部门同步接口
调用方式:HTTP、HTTPS
api: department/qiwei/sync
HTTP请求方法:POST
部门同步实现:
public function sync()
{
$http = new GuzzleHttp\Client;
$params = [
'access_token' => Common::getAccesstoken()
];
$response = $http->get('https://qyapi.weixin.qq.com/cgi-bin/department/simplelist', [
'query' => $params
]);
$result = json_decode($response->getBody(), true);
if (array_key_exists('errcode', $result) && $result['errcode'] != 0) {
$res = ResultTool::fail();
$res['errorCode'] = $result['errcode'];
$res['errorMsg'] = $result['errmsg'];
return $res;
} else {
$department_ids = $result['department_id'];
$qw_ids = [];
foreach ($department_ids as $qw_id) {
array_push($qw_ids, $qw_id['id']);
}
$departments_list = DepartmentModel::get();
$exists_qw_ids = [];
foreach ($departments_list as $department) {
if (!in_array($department->qw_id, $qw_ids)) {
DepartmentModel::where('id', '=', $department->id)->delete();
} else {
array_push($exists_qw_ids, $department->qw_id);
}
}
foreach ($department_ids as $qw_id) {
if (!in_array($qw_id['id'], $exists_qw_ids)) {
$department = new DepartmentModel();
$department->qw_id = $qw_id['id'];
$department->parentid = $qw_id['parentid'];
$department->order = $qw_id['order'];
$department->save();
}
}
}
return ResultTool::success();
}
- 成员同步接口
调用方式:HTTP、HTTPS
api: clerk/qiwei/sync
HTTP请求方法:POST
成员同步实现
public function sync()
{
$http = new GuzzleHttp\Client;
$params = [
'access_token' => Common::getAccesstoken()
];
$response = $http->get('https://qyapi.weixin.qq.com/cgi-bin/user/list_id', [
'query' => $params
]);
$result = json_decode($response->getBody(), true);
if (array_key_exists('errcode', $result) && $result['errcode'] != 0) {
$res = ResultTool::fail();
$res['errorCode'] = $result['errcode'];
$res['errorMsg'] = $result['errmsg'];
return $res;
} else {
$dept_user = $result['dept_user'];
foreach ($dept_user as $qw_user) {
$clerk = ClerkModel::where('qw_userid', '=', $qw_user['userid'])->where('qw_department_id', '=', $qw_user['department'])->first();
if(is_null($clerk)) {
$clerk = new ClerkModel();
$clerk->qw_userid = $qw_user['userid'];
$clerk->qw_department_id = $qw_user['department'];
$department = DepartmentModel::where('qw_id', '=', $qw_user['department'])->first();
if(!is_null($department)) {
$clerk->department_id = $department->id;
}
$clerk->save();
}
}
}
return ResultTool::success();
}
2、部门管理
编辑部门接口
调用方式:HTTP、HTTPS
api: department/update
HTTP请求方法:POST
接口已封装企业微信部门管理接口,所以调用该接口会自动修改企业微信平台对应部门信息,然后修改本地业务管理的部门信息。
3、成员管理
编辑成员接口
调用方式:HTTP、HTTPS
api: clerk/update
HTTP请求方法:POST
接口已封装企业微信成员管理接口,所以调用该接口会自动修改企业微信平台对应成员信息,然后修改本地业务管理的成员信息。
四、更多
开源项目:Open-Api
更多信息:www.lokei.cn
原文地址:https://www.jb51.cc/wenti/3280725.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。