Commit aa36e2e4 authored by jiangyipeng's avatar jiangyipeng

Merge branch 'master' of gitlab.linanquan.com:jiangyipeng/doc_phone

parents 128931cb 84dcbc37
......@@ -11,9 +11,7 @@ class Index extends Controller
{
public function index()
{
$model = new Folder();
$b = $model->index();
var_dump();
}
......@@ -23,11 +21,7 @@ class Index extends Controller
$model = new Folder();
$parentid = $request->param('parentid');
$res = $model->folderList($parentid);
if ($res) {
return json(code([$res], 0, 'ok'));
} else {
return json(code([], 10002, '请求失败'));
}
}
......@@ -35,6 +29,7 @@ class Index extends Controller
public function folderAdd()
{
$name = input('post.name');
// var_dump($name);
$parentid = input('post.parentid');
$model = new Folder();
......@@ -43,11 +38,11 @@ class Index extends Controller
} else {
$res = $model->addFolder($name, $parentid);
if ($res) {
if ($res['code']>=0) {
return json(code([$res], 0, '添加成功'));
} else {
return json(code([$res], 10002, '添加失败'));
return json(code([], 10002, '添加失败'));
}
}
}
......@@ -57,8 +52,9 @@ class Index extends Controller
$name = input('post.name');
$parentid = input('post.parentid');
$folderid = input('post.folderid');
$model = new Folder();
if (empty($parentid) || empty($folderid)) {
if (empty($folderid)) {
return json(code([], 10001, '参数不足'));
}
if (empty($name)) {
......@@ -98,47 +94,120 @@ class Index extends Controller
public function articleList()
{
$folderid = input('post.folderid');
//
// $model = new Doclist();
// if(empty($folderid)){
// return json(code([],10001,'没有folderid'));
// }else{
// $res = $model->ArticleList($folderid);
//
// }
$model = new Doclist();
$folderid = input('post.folderid');
$post['origin'] = input('request.origin');
$post['pagenum'] = input('request.pagenum');
$post['current'] = input('request.current');
if ( !isset($post['origin']) || empty($post['origin']) ) {
$post['origin'] = 0 ;
if (!isset($folderid) || empty($folderid)) {
return json(code([], 10001, 'folderid为空'));
}
if (!isset($post['origin']) || empty($post['origin'])) {
$post['origin'] = 0;
}
//每页显示多少条数据
if ( !isset($post['pagenum']) || empty($post['pagenum']) ) {
$post['pagenum'] = 20 ;
if (!isset($post['pagenum']) || empty($post['pagenum'])) {
$post['pagenum'] = 20;
}
//当前页
if ( isset($post['current']) && !empty($post['current']) && $post['current']>=1 ) {
if (isset($post['current']) && !empty($post['current']) && $post['current'] >= 1) {
$data['current'] = ceil($post['current']);
if (($data['current']-1)>=1){
$post['origin'] = ($post['current']-1) * $post['lenght'];
if (($data['current'] - 1) >= 1) {
$post['origin'] = ($post['current'] - 1) * $post['pagenum'];
}
}else{
} else {
$data['current'] = $post['origin'] / $post['pagenum'];
}
$data['pagenum'] = $post['pagenum'];
if ($data['current']<=1) {
if ($data['current'] <= 1) {
$data['current'] = 1;
}
$data['admin'] = AdminModel::admin_lst($post['origin'],$post['pagenum']);
//数据总条数
$data['count'] = StudyModel::rules_count();
//总页数
$data['page'] = ceil($data['count'] / $data['lenght']);
$result = $model->articleList($folderid, $post['origin'], $post['pagenum']);
//var_dump($result);
if ($result) {
return json(code([$result], 0, '请求成功'));
} else {
return json(code([$result], 0, 'ok'));
}
}
public function articleDetail()
{
$docid = input('post.docid');
$model = new Doclist();
$detail = $model->articleDetail($docid);
if ($detail) {
return json(code([$detail], 0, '请求成功'));
} else {
return json(code([], 10002, '请求失败'));
}
}
public function articleAdd()
{
$title = input('post.title');
$folderid = input('post.folderid');
$type = (int)input('post.type');
$doc = input('post.doc');
$model = new Doclist();
if (empty($type)) {
return json(code([], 10001, '类型不能为空'));
}
if (empty($title)) {
return json(code([], 10001, '标题不能为空'));
} else {
$res = $model->addArticle($title, $folderid, $type, $doc);
if ($res) {
return json(code([$res], 0, '添加成功'));
} else {
return json(code([$res], 10002, '添加失败'));
}
}
}
public function articleEdit()
{
$title = input('post.title');
$folderid = input('post.folderid');
$doc = input('post.doc');
$docid = input('post.docid');
$model = new Doclist();
if ( empty($title) || empty($doc) || empty($docid)) {
return json(code([], 10001, '参数不足'));
}
$res = $model->editArticle($title, $folderid, $doc, $docid);
if ($res) {
return json(code([], 0, '修改成功'));
} else {
return json(code([], 10002, '修改失败'));
}
}
public function articleDel()
{
$docid = input('post.docid');
$model = new Doclist();
if (empty($docid)) {
return json(code([], 10001, '没有docid'));
} else {
$res = $model->delArticle($docid);
if ($res) {
return json(code([], 0, '删除成功'));
} else {
return json(code([], 10002, '删除失败'));
}
}
}
}
......@@ -9,79 +9,92 @@ class Doclist extends Model
{
public function index()
{
$user = Db::name('folder')->where('state', '=', -1)->find();
return $user;
// $user = Db::name('folder')->where('state', '=', -1)->find();
// return $user;
// $sql = Db::name('folder')->getLastSql();
//// var_dump($sql);
}
//获取文件夹名称
public function ArticleList($folderid,$origin,$pagenum)
public function articleList($folderid,$origin,$pagenum)
{
var_dump($origin);
var_dump($pagenum);die();
$where = ['folderid' => $folderid];
$articlelist = Db::name('doclist')->where($where)->order('')->select();
$sql = Db::name('doclist')->getLastSql();
var_dump($sql);
// var_dump($folderid);
if($folderid){
$where['folderid'] = array('=',$folderid);
$where['state'] = array('=',0);
$articlelist = Db::name('doclist')->field('docid,title,type,updatetime')->where($where)->order('createtime')->limit($origin,$pagenum)->select();
// $sql = Db::name('doclist')->getLastSql();
// var_dump($sql);
}else{
$articlelist=[];
}
return $articlelist;
}
public function addFolder($name, $parentid)
public function articleDetail($docid)
{
if($docid){
$where = ['docid' => $docid];
$articldetail = Db::name('doclist')->field('docid,title,type,updatetime,doc')->where($where)->find();
return $articldetail;
}
}
public function addArticle($title, $folderid,$type,$doc)
{
$folderid = randomkeys(18);
$docid = randomkeys(18);
// $where = ['folderid' => $folderid];
$docname = Db::name('doclist')->where(['docid' => $docid])->count();
$foldername = Db::name('folder')->where(['folderid' => $folderid])->count();
$rs = new Doclist();
if ($foldername == 0) {
if ($docname == 0) {
$data = [
'docid' =>$docid,
'title' => $title ,
'type' => $type,
'doc' => $doc,
'folderid' => $folderid,
'name' => $name,
'updatetime' => date("Y-m-d H:i:s", time()),
'parentid' => $parentid,
'state' => 0
'createtime' => date("Y-m-d H:i:s", time())
];
$rs->isUpdate(false)->save($data);
$return = $rs->folderid;
// $sql = Db::name('doclist')->getLastSql();
// var_dump($sql);
$return = $rs->docid;
return $return;
}
}
public function editFolder($name, $parentid, $folderid)
public function editArticle($title, $folderid,$doc,$docid)
{
$rs = new Folder();
$rs = new Doclist();
$where = '';
$where = [];
$data = [
'name' => $name,
'title' => $title,
'doc' =>$doc,
'updatetime' => date("Y-m-d H:i:s", time()),
];
if ($folderid) {
$where = ['folderid' => $folderid];
if ($docid) {
$where['docid'] = array('=',$docid);
}
if ($parentid) {
$where = ['parentid' => $parentid];
}
$oldname = Db::name('folder')->where($where)->value('name');
if ($name != $oldname) {
$rs = $this->where($where)->update($data);
if ($rs === false) {
return false;
} else {
return true;
}
} else {
return false;
}
// var_dump($rs);die();
......@@ -90,12 +103,13 @@ class Doclist extends Model
}
public function delFolder($folderid)
public function delArticle($docid)
{
$rs = new Folder();
$where = ['folderid' => $folderid];
$rs = new Doclist();
$where = ['docid' => $docid];
$data = [
'state' => -1,
'updatetime' => date("Y-m-d H:i:s", time())
];
$rs = $this->where($where)->update($data);
......
......@@ -26,7 +26,8 @@ class Folder extends Model
}
$folderlist = Db::name('folder')->where($where)->order('')->select();
// $sql = Db::name('folder')->getLastSql();
// var_dump($sql);
return $folderlist;
}
......@@ -35,53 +36,95 @@ class Folder extends Model
{
$folderid = randomkeys(18);
// $folderid='bpy0p4617b7fun9lxqa1';
if (!$parentid) {
$parentid = '';
}
$foldername = Db::name('folder')->where(['folderid' => $folderid])->count();
$rs = new Folder();
if ($foldername == 0) {
// $data = [
// 'folderid' => $folderid,
// 'name' => $name,
// 'updatetime' => date("Y-m-d H:i:s", time()),
// 'parentid' => $parentid,
// 'state' => 0
// ];
// $childfolder_nums = Db::name('folder')->where(['parentid' => $parentid])->count();
//
// $rs->isUpdate(false)->save($data);
// if ($rs) {
// $items = $this->where(['folderid' => $parentid])->setField('items', $childfolder_nums + 1);
// }
// $return = $rs->folderid;
// return $return;
// 启动事务
Db::startTrans();
try {
$data = [
'folderid' => $folderid,
'name' => $name,
'updatetime' => date("Y-m-d H:i:s", time()),
'parentid' => $parentid,
'state' => 0
];
$rs->isUpdate(false)->save($data);
$childfolder_nums = Db::name('folder')->where(['parentid' => $parentid])->count();
$res = $rs->isUpdate(false)->save($data);
if ($res !== false) {
if ($parentid) {
$items = $this->where(['folderid' => $parentid])->setField('items', $childfolder_nums + 1);
if ($items) {
$return = $rs->folderid;
return $return;
} else {
throw new \Exception('添加失败');
}
} else {
$return = $rs->folderid;
}
}
// 提交事务
Db::commit();
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
$return = ['code' => -200, 'msg' => $e->getMessage()];
}
} else {
$return = ['code' => -10002, 'msg' => '文件名重复'];
}
return $return;
}
public function editFolder($name, $parentid,$folderid)
public function editFolder($name, $parentid, $folderid)
{
$rs = new Folder();
$where ='';
$where = '';
$data = [
'name' => $name,
'updatetime' => date("Y-m-d H:i:s", time()),
];
if($folderid){
if ($folderid) {
$where = ['folderid' => $folderid];
}
if($parentid){
if ($parentid) {
$where = ['parentid' => $parentid];
}
$oldname = Db::name('folder')->where($where)->value('name');
if($name!=$oldname){
if ($name != $oldname) {
$rs = $this->where($where)->update($data);
if($rs===false){
if ($rs === false) {
return false;
} else{
} else {
return true;
}
}else{
} else {
return false;
}
......@@ -91,23 +134,23 @@ class Folder extends Model
// var_dump($sql);
}
public function delFolder($folderid)
{
$rs = new Folder();
$where = ['folderid' => $folderid];
$data = [
'state' =>-1,
'state' => -1,
];
$rs = $this->where($where)->update($data);
if($rs===false){
if ($rs === false) {
return false;
} else{
} else {
return true;
}
// var_dump($rs);die();
// $sql = Db::name('folder')->getLastSql();
// var_dump($sql);
......
......@@ -26,6 +26,9 @@
*/
function code($sendData = [], $errCode = 0, $errMsg = '')
{
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
$_errCode = $errCode;
$_errMsg = $errMsg;
......
<?php
namespace app\login\controller;
use cjango\Dingtalk\User;
use src\Dingtalk\Utils;
use think\Controller;
use think\Db;
use src\Dingtalk;
use think\Session;
class Index extends Controller
{
// public function index(){
//
// return $this->fetch();
//
//
// }
public function config(){
$Ding = new Dingtalk();
$Token =new Dingtalk\Token();
$token =$Token->get();
$access_token=$Ding->config('access_token',$token);
Session::set('access_token',$token);
$ticket = $Token->jsapi();
Session::set('jsapi_ticket',$ticket);
$jsapi_ticket= $Ding->config('jsapi_ticket',$ticket);
$config=$Ding->ddconfig();
// if($config){
// $data['config']=$config;
// $data['status']=200;
// }
return json(code([$config], 0, 'ok'));
//return json($data);
}
public function getSsoToken(){
$code = input('post.code');
//var_dump($code);
//$access_token= Session::get('access_token');
$User =new Dingtalk\User();
$userid =$User->code($code);
if($userid===false){
$data['status']=-10001;
$data['errmsg']='登录失败';
}else{
$data['status']=0;
$data['errmsg']='登录成功';
$data['userid']=$userid;
}
// return json($data);
return json(code([$data], 0, 'ok'));
// var_dump($_SESSION);
}
}
*
!.gitignore
\ No newline at end of file
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src;
/**
* 钉钉SDK
*/
class Dingtalk
{
/**
* 钉钉实例
* @var object
*/
protected static $instance = null;
/**
* 接口调用地址
* @var string
*/
protected static $baseUrl = 'https://oapi.dingtalk.com/';
/**
* 请求头信息
* @var array
*/
protected static $headers = [
'Content-Type' => 'application/json',
];
/**
* 错误信息
* @var null
*/
protected static $error = null;
/**
* 钉钉的配置信息
* @var array
*/
protected static $config = [
'agentid' => 781256835,
'appkey' =>'ding205fbymmwea4mtln',
'appsecret' =>'S_E2VRls4GZLU11K-mlEyFAslu2I0T1jbtAKrAZBJea_A32fLP1FV9QQ5D7_mYdW',
'corpid' => 'dingeb18cb3ded3f0424',
'corpsecret' => 'ding205fbymmwea4mtln',
'ssosecret' => 'S_E2VRls4GZLU11K-mlEyFAslu2I0T1jbtAKrAZBJea_A32fLP1FV9QQ5D7_mYdW',
'access_token' => '',
'jsapi_ticket'=>'',
];
/**
* 实例化钉钉SDK
* @param array $config 配置信息
*/
public function __construct($config = [])
{
if (!empty($config) && is_array($config)) {
self::$config = array_merge(self::$config, $config);
}
}
/**
* 实例化的静态方法
* @param array $config 配置信息
* @param boolean $force 强制重新实例化
* @return \tools\DDing
*/
public static function instance($config = [], $force = false)
{
if (is_null(self::$instance) || $force == true) {
self::$instance = new static($config);
}
return self::$instance;
}
/**
* 设置/获取 配置变量
* @param string $key
* @param string $value
* @return string
*/
public static function config($key, $value = null)
{
if (is_null($value)) {
return self::$config[$key];
} else {
self::$config[$key] = $value;
}
}
/**
* JS-API权限验证参数生成
* @return array
*/
public static function ddConfig()
{
$nonceStr = uniqid();
$timestamp = time();
$config = [
'agentId' => self::$config['agentid'],
'corpId' => self::$config['corpid'],
'timeStamp' => $timestamp,
'nonceStr' => $nonceStr,
];
$config['signature'] = self::sign($nonceStr, $timestamp);
return $config;
}
/**
* 钉钉签名算法
* @param string $noncestr
* @param string $timestamp
* @return string
*/
private static function sign($noncestr, $timestamp)
{
$signArr = [
'jsapi_ticket' => self::$config['jsapi_ticket'],
'noncestr' => $noncestr,
'timestamp' => $timestamp,
'url' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // 获取当前页面地址 有待优化
];
ksort($signArr);
//var_dump($signArr);
$signStr = urldecode(http_build_query($signArr));
return sha1($signStr);
}
/**
* 设置/获取 错误信息
* @param string $msg
* @return string
*/
public static function error($msg = null)
{
if (!is_null($msg)) {
self::$error = $msg;
} else {
return self::$error;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
*
*/
class AppClient extends Dingtalk
{
/**
* 初始化APP端钉钉配置
* @param string $agentId agentId
* @param array $jsApiList 需要使用的jsapi列表
* @return array
*/
public static function init($agentId, $jsApiList = [])
{
$return = '<script src="https://g.alicdn.com/dingding/open-develop/0.7.0/dingtalk.js" type="text/javascript" charset="utf-8"></script>';
$return .= '<script type="text/javascript" charset="utf-8">';
$return .= 'dd.config(';
$return .= self::ddConfig($agentId, $jsApiList);
$return .= ');';
$return .= '</script>' . "\r\n";
return [
'init' => $return,
'corpid' => parent::$config['corpid'],
];
}
/**
* JS-API权限验证参数生成
* @return array
*/
private static function ddConfig($agentId, $jsApiList)
{
$nonceStr = uniqid();
$timestamp = time();
$config = [
'agentId' => $agentId,
'corpId' => parent::$config['corpid'],
'timeStamp' => $timestamp,
'nonceStr' => $nonceStr,
];
$config['signature'] = self::sign($nonceStr, $timestamp);
$config['jsApiList'] = $jsApiList;
return json_encode($config);
}
/**
* 钉钉签名算法
* @param string $noncestr
* @param string $timestamp
* @return string
*/
private static function sign($noncestr, $timestamp)
{
$jsapi_ticket = parent::$config['jsapi_ticket'];
if (empty($jsapi_ticket)) {
$jsapi_ticket = Token::jsapi();
}
$signArr = [
'jsapi_ticket' => $jsapi_ticket,
'noncestr' => $noncestr,
'timestamp' => $timestamp,
'url' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // 获取当前页面地址 有待优化
];
ksort($signArr);
$signStr = urldecode(http_build_query($signArr));
return sha1($signStr);
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* 考勤打卡
*/
class Attendance extends Dingtalk
{
/**
* 获取考勤打卡数据
* @param dateTime $from 考勤开始时间
* @param dateTime $to 考勤结束时间 跨度不能超过7天
* @param string $userId 用户userid
* @return array|boolean
*/
public static function get($from, $to, $userId = null)
{
$params = [
'workDateFrom' => $from,
'workDateTo' => $to,
];
if (!is_null($userId)) {
$params['userId'] = $userId;
}
$result = Utils::post('attendance/list', $params);
if (false !== $result) {
return $result['recordresult'];
} else {
return false;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* Department 通讯录管理
*/
class Department extends Dingtalk
{
/**
* 获取部门列表
* @return array|boolean
*/
public static function lists()
{
$result = Utils::get('department/list');
if (false !== $result) {
return $result['department'];
} else {
return false;
}
}
/**
* 获取部门详情
* @param integer $id 部门ID
* @return array|boolean
*/
public static function info($id)
{
$params = [
'id' => $id,
];
$result = Utils::get('department/get', $params);
if (false !== $result) {
return $result;
} else {
return false;
}
}
/**
* 创建部门
* @param string|array $name
* @param integer $parentid
* @return integer|boolean
*/
public static function create($name, $parentid = 1)
{
if (is_array($name)) {
$params = $name;
} else {
$params = [
'name' => $name,
'parentid' => $parentid,
];
}
$result = Utils::post('department/create', $params);
if (false !== $result) {
return $result['id'];
} else {
return false;
}
}
/**
* 更新部门
* @param string|array $name
* @param integer $id
* @return boolean
*/
public static function update($name, $id)
{
if (is_array($name)) {
$params = $name;
} else {
$params = [
'id' => $id,
'name' => $name,
];
}
$result = Utils::post('department/update', $params);
if (false !== $result) {
return true;
} else {
return false;
}
}
/**
* 删除部门
* @param integer $id
* @return boolean
*/
public static function delete($id)
{
$params = [
'id' => $id,
];
$result = Utils::get('department/delete', $params);
if (false !== $result) {
return true;
} else {
return false;
}
}
/**
* 获取部门用户USERID列表
* @param integer $departmentId
* @return array|boolean
*/
public static function users($departmentId)
{
$params = [
'department_id' => $departmentId,
];
$result = Utils::get('user/simplelist', $params);
if (false !== $result) {
return $result['userlist'];
} else {
return false;
}
}
/**
* 获取部门用户详情列表
* @param [type] $departmentId [description]
* @return [type] [description]
*/
public static function usersDetail($departmentId)
{
$params = [
'department_id' => $departmentId,
];
$result = Utils::get('user/list', $params);
if (false !== $result) {
return $result['userlist'];
} else {
return false;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* 管理多媒体文件
*/
class Media extends Dingtalk
{
/**
* 上传多媒体文件/ 接口未完成
* @return [type] [description]
*/
public static function upload()
{
$params = [
'type' => $type,
'media' => $media,
];
$result = Utils::post('media/upload', $params);
if (false !== $result) {
return $result['media_id'];
} else {
return false;
}
}
/**
* 获取媒体文件
* @param string $mediaId 媒体文件的唯一标示
* @return [type]
*/
public static function get($mediaId)
{
$params = [
'media_id ' => $mediaId,
];
$result = Utils::get('media/get', $params);
if (false !== $result) {
return $result;
} else {
return false;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* 会话消息
*/
class Message extends Dingtalk
{
/**
* 发送企业会话消息
* @param [type] $touser [description]
* @param [type] $agentid [description]
* @param [type] $msgtype [description]
* @param [type] $msgbody [description]
* @return [type] [description]
*/
public static function send($touser, $agentid, $msgtype, $msgbody)
{
$params = [
'touser' => $touser,
'agentid' => $agentid,
'msgtype' => $msgtype,
$msgbody,
];
$result = Utils::post('message/send', $params);
if (false !== $result) {
unset($result['errcode']);
unset($result['errmsg']);
return $result;
} else {
return false;
}
}
/**
* 获取企业会话消息已读未读状态
* @param string $messageId 消息id
* @return array|boolean
*/
public static function status($messageId)
{
$params = [
'messageId' => $messageId,
];
$result = Utils::post('message/list_message_status', $params);
if (false !== $result) {
unset($result['errcode']);
unset($result['errmsg']);
return $result;
} else {
return false;
}
}
/**
* 发送普通会话消息
* @param [type] $sender [description]
* @param [type] $cid [description]
* @param [type] $msgtype [description]
* @param [type] $msgbody [description]
* @return [type] [description]
*/
public static function common($sender, $cid, $msgtype, $msgbody)
{
$params = [
'sender' => $sender,
'cid' => $cid,
'msgtype' => $msgtype,
$msgbody,
];
$result = Utils::post('message/send_to_conversation', $params);
if (false !== $result) {
return $result['receiver'];
} else {
return false;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* 管理微应用
*/
class Microapp extends Dingtalk
{
/**
* 创建微应用
* @return [type] [description]
*/
public static function create()
{
// "appIcon": "@HIdsabikkhjsdsas",
// "appName": "测试微应用",
// "appDesc": "测试使用的微应用",
// "homepageUrl": "http://oa.dingtalk.com/?h5",
// "pcHomepageUrl": "http://oa.dingtalk.com/?pc",
// "ompLink": ""
$params = [
];
$result = Utils::post('microapp/create', $params);
if (false !== $result) {
return $result['id'];
} else {
return false;
}
}
/**
* 获取企业设置的微应用可见范围
* @param [type] $agentId [description]
*/
public static function scopes($agentId)
{
$params = [
'agentId' => $agentId,
];
$result = Utils::post('microapp/visible_scopes', $params);
if (false !== $result) {
unset($result['errcode']);
unset($result['errmsg']);
return $result;
} else {
return false;
}
}
/**
* 设置微应用的可见范围
* @param [type] $agentId [description]
* @param [type] $params [description]
*/
public static function setScopes($agentId, $params)
{
$params['agentId'] = $agentId;
$result = Utils::post('microapp/set_visible_scopes', $params);
if (false !== $result) {
return true;
} else {
return false;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
*
*/
class PcClient extends Dingtalk
{
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* Token 获取
*/
class Token extends Dingtalk
{
/**
* 获取ACCESS_TOKEN
* @return string|boolean
*/
public static function get()
{
$params = [
'appkey' => parent::$config['appkey'],
'appsecret' => parent::$config['appsecret'],
];
$result = Utils::get('gettoken', $params, false);
if (false !== $result) {
return $result['access_token'];
} else {
return false;
}
}
/**
* 获取 免登SsoToken
* @return string|boolean
*/
public static function sso()
{
$params = [
'corpid' => parent::$config['corpid'],
'corpsecret' => parent::$config['ssosecret'],
];
$result = Utils::get('sso/gettoken', $params, false);
if (false !== $result) {
return $result['access_token'];
} else {
return false;
}
}
/**
* 获取jsapi_ticket
* @return string|boolean
*/
public static function jsapi()
{
$result = Utils::get('get_jsapi_ticket');
if (false !== $result) {
return $result['ticket'];
} else {
return false;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* 用户管理
*/
class User extends Dingtalk
{
/**
* 获取企业员工人数
* @param integer $active 0:总数,1:已激活
* @return array|boolean
*/
public static function count($active = 0)
{
$params = [
'onlyActive' => $active,
];
$result = Utils::get('user/get_org_user_count', $params);
if (false !== $result) {
return $result['count'];
} else {
return false;
}
}
/**
* 获取用户详情
* @param string $userid 员工在企业内的UserID
* @return array|boolean
*/
public static function get($userid)
{
$params = [
'userid' => $userid,
];
$result = Utils::get('user/get', $params);
if (false !== $result) {
return $result;
} else {
return false;
}
}
/**
* 创建成员
* @param [type] $name [description]
* @param string $mobile [description]
* @param array $department [description]
* @return [type] [description]
*/
public static function create($name, $mobile, $department = [])
{
$params = [
'name' => $name,
'mobile' => $mobile,
'department' => $department,
];
$result = Utils::post('user/create', $params);
if (false !== $result) {
return $result['userid'];
} else {
return false;
}
}
/**
* 更新成员
* @param [type] $userid [description]
* @param [type] $name [description]
* @param array $data [description]
* @return [type] [description]
*/
public static function update($userid, $name, $data = [])
{
#Todo..
}
/**
* 删除成员
* @param [type] $userid [description]
* @return [type] [description]
*/
public static function delete($userid)
{
$params = [
'userid' => $userid,
];
$result = Utils::get('user/delete', $params);
if (false !== $result) {
return true;
} else {
return false;
}
}
/**
* 批量删除用户
* @param array $useridlist
* @return boolean
*/
public static function batchDelete($useridlist = [])
{
$params = [
'useridlist' => $useridlist,
];
$result = Utils::post('user/batchdelete', $params);
if (false !== $result) {
return true;
} else {
return false;
}
}
/**
* 获取管理员列表
* @return array|boolean
*/
public static function admin()
{
$result = Utils::get('user/get_admin');
if (false !== $result) {
return $result['adminList'];
} else {
return false;
}
}
/**
* 通过CODE换取用户身份
* @param string $code requestAuthCode接口中获取的CODE
* @return string|boolean
*/
public static function code($code)
{
$params = [
'code' => $code,
];
$result = Utils::get('user/getuserinfo', $params);
if (false !== $result) {
return $result['userid'];
} else {
return false;
}
}
}
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace src\Dingtalk;
use src\Dingtalk;
/**
* 基础工具类
*/
class Utils extends Dingtalk
{
/**
* GET 方式请求接口
* @param string $api
* @param array $params
* @param boolean $token
* @return array|boolean
*/
public static function get($api, $params = [], $token = true)
{
$url = Dingtalk::$baseUrl . $api;
//var_dump($url);
if ($token === true) {
$access_token = Dingtalk::config('access_token');
//var_dump($access_token);
if (empty($access_token)) {
$access_token = Token::get();
}
$params['access_token'] = $access_token;
}
$url .= '?' . http_build_query($params);
//var_dump($url);
$result = self::http($url, 'GET', $params, Dingtalk::$headers);
//var_dump($result);
if ($result !== false) {
$result = json_decode($result, true);
if ($result['errcode'] == 0) {
return $result;
} else {
Dingtalk::error($result['errmsg']);
return false;
}
} else {
return false;
}
}
/**
* POST 方式请求接口
* @param string $api
* @param array $params
* @return array|boolean
*/
public static function post($api, $params)
{
$access_token = Dingtalk::config('access_token');
if (empty($access_token)) {
$access_token = Token::get();
}
$url = Dingtalk::$baseUrl . $api . '?access_token=' . $access_token;
$result = self::http($url, 'POST', json_encode($params, JSON_UNESCAPED_UNICODE), Dingtalk::$headers);
if ($result !== false) {
$result = json_decode($result, true);
if ($result['errcode'] == 0) {
return $result;
} else {
Dingtalk::error($result['errmsg']);
return false;
}
} else {
return false;
}
}
/**
* curl操作函数
* @param string $url 请求地址
* @param string $method 提交方式
* @param array $postFields 提交内容
* @param array $header 请求头
* @return mixed 返回数据
*/
public static function http($url, $method = 'GET', $postFields = null, $headers = null)
{
$method = strtoupper($method);
if (!in_array($method, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'])) {
return false;
}
$opts = [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_URL => $url,
CURLOPT_FAILONERROR => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 30,
];
if ($method == 'POST' && !is_null($postFields)) {
$opts[CURLOPT_POSTFIELDS] = $postFields;
}
if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == 'https') {
$opts[CURLOPT_SSL_VERIFYPEER] = false;
$opts[CURLOPT_SSL_VERIFYHOST] = false;
}
if (!empty($headers) && is_array($headers)) {
$httpHeaders = [];
foreach ($headers as $key => $value) {
array_push($httpHeaders, $key . ':' . $value);
}
$opts[CURLOPT_HTTPHEADER] = $httpHeaders;
}
$ch = curl_init();
curl_setopt_array($ch, $opts);
$data = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err > 0) {
Dingtalk::error(curl_error($ch));
return false;
} else {
return $data;
}
}
}
......@@ -8,13 +8,10 @@
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 应用入口文件 ]
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment