init: 项目初始代码
This commit is contained in:
151
app/library/KafkaClient.php
Normal file
151
app/library/KafkaClient.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\library;
|
||||
|
||||
/**
|
||||
* Kafka操作类
|
||||
*/
|
||||
trait KafkaClient
|
||||
{
|
||||
/**
|
||||
* 定义Kafka生产者初始化配置
|
||||
* 需要在服务端配置 kafka_server_jaas.conf 里面添加对应的用户名和密码
|
||||
* @var array
|
||||
*/
|
||||
private $kafkaProducerConfig = [];
|
||||
|
||||
/**
|
||||
* 定义Kafka生产者初始化配置
|
||||
* 需要在服务端配置 kafka_client_jaas.conf 里面添加对应的用户名和密码
|
||||
* @var array
|
||||
*/
|
||||
private $kafkaConsumerConfig = [];
|
||||
|
||||
|
||||
/**
|
||||
* 初始化kafka生产配置
|
||||
* @return string[]
|
||||
*/
|
||||
private function initKafkaProducerConfig() :array
|
||||
{
|
||||
return $this->kafkaProducerConfig = [
|
||||
'username' => 'orico',
|
||||
'password' => 'password',/**/
|
||||
'broker_list' => '127.0.0.1:9092',/*如果有多个,ip:port,ip2:port,ip3:port*/
|
||||
'topic' => 'topics'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化kafka消费配置
|
||||
* @return string[]
|
||||
*/
|
||||
private function initKafkaConsumerConfig() :array
|
||||
{
|
||||
return $this->kafkaConsumerConfig = [
|
||||
'username' => 'orico',
|
||||
'password' => 'password',/**/
|
||||
'brokerlist' => '127.0.0.1:9092',/*如果有多个,ip:port,ip2:port,ip3:port*/
|
||||
'topic' => 'topics'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* kafka 生产者核心方法
|
||||
* @param array $config kafka 配置参数
|
||||
* @param array $data 需要生产的数据
|
||||
*/
|
||||
public function kafkaProducer(array $config, array $data)
|
||||
{
|
||||
if (empty($this->kafkaProducerConfig)) {
|
||||
$this->initKafkaProducerConfig();
|
||||
}
|
||||
$conf = new \RdKafka\Conf();
|
||||
$conf->set('sasl.mechanisms', 'PLAIN');
|
||||
$conf->set('security.protocol', 'SASL_PLAINTEXT');
|
||||
$conf->set('sasl.username', $config['username']);
|
||||
$conf->set('sasl.password', $config['password']);
|
||||
$conf->set('socket.keepalive.enable', 'true'); // socket不操作保持长连
|
||||
$conf->set('log.connection.close', 'false'); // 静默所有自发断开连接日志
|
||||
$conf->set('metadata.broker.list', $config['broker_list']);
|
||||
|
||||
$producer = new \RdKafka\Producer($conf);
|
||||
|
||||
$topic = $producer->newTopic($this->topicProduce);
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$topic->produce(RD_KAFKA_PARTITION_UA, 0,$data);
|
||||
$producer->poll(0);
|
||||
}
|
||||
|
||||
for ($flushRetries = 0; $flushRetries < 10; $flushRetries++) {
|
||||
$result = $producer->flush(10000);
|
||||
if (RD_KAFKA_RESP_ERR_NO_ERROR === $result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
|
||||
throw new \RuntimeException('Was unable to flush, messages might be lost!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* kafka 消息者核心方法
|
||||
* @param array $config kafka 配置参数
|
||||
* @param array $data 需要生产的数据
|
||||
*/
|
||||
public function kafkaConsumer(array $config, array $data)
|
||||
{
|
||||
if (empty($this->kafkaConsumerConfig)) {
|
||||
$this->initKafkaConsumerConfig();
|
||||
}
|
||||
return ($this->kafkaConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* curl请求
|
||||
* @param $url string 请求的url链接
|
||||
* @param $data string|array|mixed 请求的数据
|
||||
* @param bool $is_post 是否是post请求,默认false
|
||||
* @param array $options 是否附带请求头
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function http(string $url, array $data, bool $is_post=false, array $options=[]):array
|
||||
{
|
||||
$data = json_encode($data);
|
||||
$headerArray = [
|
||||
'Content-type: application/json;charset=utf-8',
|
||||
'Accept: application/json'
|
||||
];
|
||||
$curl = curl_init();
|
||||
$arr = [];
|
||||
array_push($arr,$url);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
|
||||
if ($is_post) {
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
if (!empty($options['cookie'])) {
|
||||
curl_setopt($curl, CURLOPT_COOKIE, $options['cookie']);
|
||||
}
|
||||
$output = curl_exec($curl);
|
||||
$http_status = curl_errno($curl);
|
||||
$http_msg = curl_error($curl);
|
||||
curl_close($curl);
|
||||
if ($http_status == 0) {
|
||||
return json_decode($output, true);
|
||||
} else {
|
||||
return ['status' => $http_status, 'message' => $http_msg, 'data' => []];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
154
app/library/LogToKafka.php
Normal file
154
app/library/LogToKafka.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace app\library;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\facade\Env;
|
||||
|
||||
/**
|
||||
* 日志消息队列
|
||||
*/
|
||||
trait LogToKafka
|
||||
{
|
||||
/**
|
||||
* 日志放Kafka接口配置
|
||||
* @var array
|
||||
*/
|
||||
public static $sendLogToKafkaConfig = [];
|
||||
|
||||
/**
|
||||
* 日志类型
|
||||
* action_logs 行为日志内容(值为二维数组序列化)(不是本日志传空值)
|
||||
* api_logs 接口日志内容(值为二维数组序列化)(不是本日志传空值)
|
||||
* lg_logs_view 访客日志内容(值为二维数组序列化)(不是本日志传空值)
|
||||
* lg_task_queue队列日志内容(值为二维数组序列化)(不是本日志传空值)
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $logType = ['action_logs','api_logs','lg_logs_view','lg_task_queue'];
|
||||
|
||||
/**
|
||||
* 日志写入类型,add添加日志,api调用接口,queue队列
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $methodType = ['add','api','queue'];
|
||||
|
||||
/**
|
||||
* 初始化配置
|
||||
* @return array
|
||||
*/
|
||||
private static function initLogConfig():array
|
||||
{
|
||||
return self::$sendLogToKafkaConfig = [
|
||||
'LogsSSOUrl' => Env::get('SSO.UC_URL'),
|
||||
'apiRoute' => '/journal/v1/kafkaproducer/send',
|
||||
'signStr' => 'logsmonitor',
|
||||
'secretKey' => 'logsmonitorscretlist',
|
||||
'dbName' => 'users'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求,生成到api日志kafka
|
||||
* @param array $data 请求数据
|
||||
* @param string $logType 日志类型
|
||||
* @param string $database 操作数据库
|
||||
* @param string $dotype 调用接口方式
|
||||
* @return bool
|
||||
*/
|
||||
public static function sendLogsToKafkaProduce(array $data, string $logType, string $database, string $dotype):bool
|
||||
{
|
||||
if (empty(self::$sendLogToKafkaConfig)) {
|
||||
self::initLogConfig();
|
||||
}
|
||||
$newData = [
|
||||
'action_logs' => "",
|
||||
'api_logs' => "",
|
||||
'lg_logs_view' => "",
|
||||
'lg_task_queue' => ""
|
||||
];
|
||||
//先构建好数据
|
||||
if ($logType != '' && in_array($logType,self::$logType)) {
|
||||
$newData[$logType] = json_encode($data);
|
||||
}
|
||||
//构建数据库
|
||||
if ($database) {
|
||||
$newData['database'] = $database;
|
||||
}
|
||||
//构建写入kafka的类型,
|
||||
if ($dotype != '' && in_array($dotype,self::$methodType)) {
|
||||
$newData['dotype'] = $dotype;
|
||||
}
|
||||
//拿到数据,构建签名
|
||||
$newData['sign'] = self::getSign($newData);
|
||||
//构建请求接口
|
||||
$url = self::$sendLogToKafkaConfig['LogsSSOUrl'].self::$sendLogToKafkaConfig['apiRoute'];
|
||||
$result = self::http($url,$newData,true);
|
||||
Cache::set('$url',$url,300);
|
||||
Cache::set('result',$result,300);
|
||||
if(isset($result['errno']) && $result['errno'] == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名
|
||||
* @param array $param 用于验证数据完整性
|
||||
* @return string
|
||||
*/
|
||||
public static function getSign(array $param):string
|
||||
{
|
||||
ksort($param);
|
||||
$signStr = self::$sendLogToKafkaConfig['signStr'];
|
||||
$secretKey = self::$sendLogToKafkaConfig['secretKey'];
|
||||
foreach ( $param as $key => $value ) {
|
||||
$signStr = $signStr . $key . "=" . $value . "&";
|
||||
}
|
||||
$signStr = substr($signStr, 0, -1);
|
||||
return base64_encode(hash_hmac("sha1", $signStr, $secretKey, true));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* curl请求
|
||||
* @param $url string 请求的url链接
|
||||
* @param $data string|array|mixed 请求的数据
|
||||
* @param bool $is_post 是否是post请求,默认false
|
||||
* @param array $options 是否附带请求头
|
||||
* @return array|mixed
|
||||
*/
|
||||
private static function http(string $url, array $data, bool $is_post=false, array $options=[]):array
|
||||
{
|
||||
$data = json_encode($data);
|
||||
$headerArray = [
|
||||
'Content-type: application/json;charset=utf-8',
|
||||
'Accept: application/json'
|
||||
];
|
||||
$curl = curl_init();
|
||||
$arr = [];
|
||||
array_push($arr,$url);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
|
||||
if ($is_post) {
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
if (!empty($options['cookie'])) {
|
||||
curl_setopt($curl, CURLOPT_COOKIE, $options['cookie']);
|
||||
}
|
||||
$output = curl_exec($curl);
|
||||
$http_status = curl_errno($curl);
|
||||
$http_msg = curl_error($curl);
|
||||
curl_close($curl);
|
||||
if ($http_status == 0) {
|
||||
return json_decode($output, true);
|
||||
} else {
|
||||
return ['status' => $http_status, 'message' => $http_msg, 'data' => []];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
459
app/library/SSOApi.php
Normal file
459
app/library/SSOApi.php
Normal file
@@ -0,0 +1,459 @@
|
||||
<?php
|
||||
|
||||
namespace app\library;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\facade\Env;
|
||||
use think\facade\Session;
|
||||
|
||||
/**
|
||||
* 单点请求类
|
||||
*/
|
||||
trait SSOApi
|
||||
{
|
||||
/**
|
||||
* 应用请求token
|
||||
* @var array
|
||||
*/
|
||||
protected $appToken = [];
|
||||
|
||||
/**
|
||||
* 单点配置信息
|
||||
* @var array
|
||||
*/
|
||||
protected $ssoApiConfig = [];
|
||||
|
||||
/**
|
||||
* 接口列表
|
||||
*/
|
||||
protected $apis = [
|
||||
'getAuthorizeToken' => '/authorize/token',/*获取应用授权接口*/
|
||||
'getDeptList' => '/dept/list',/*部门分页数据*/
|
||||
'getDeptDetail' => '/dept/detail',/*根据ID部门详细*/
|
||||
'getDeptDetailDeptCode' => '/dept/detail/dept_code',/*根据编码部门详细*/
|
||||
'getDeptHead' => '/dept/head',/*根据编码获取部门主管*/
|
||||
'getDeptChainId' => '/dept/chain/id/{id}',/*根据部门ID获取部门上下级*/
|
||||
'getDeptChainCode' => '/dept/chain/code/{code}',/*根据部门编码获取部门上下级*/
|
||||
'getStaffList' => '/staff/list',/*员工分页数据*/
|
||||
'getStaffListDept' => '/staff/list/dept',/*根据部门编码获取员工数据*/
|
||||
'getUserDetailUid' => '/user/detail/uid',/*根据用户ID获取用户详细*/
|
||||
'getUserDetailStaffCode' => '/user/detail/staff_code',/*根据用户(员工)编码获取用户(员工)详情*/
|
||||
'getUserDepts' => '/user/depts',/*根据用户ID获取用户所属部门*/
|
||||
'getUserDeptsStaffCode' => '/user/depts/staff_code',/*根据用户编码获取用户所属部门*/
|
||||
'getUserDetailMobile' => '/user/detail/mobile',/*根据手机号获取用户详细*/
|
||||
'getRoleDetailId' => '/role/detail/id/{id}',/*根据ID获取角色详细*/
|
||||
'getRoleDetailCode' => '/role/detail/code/{code}',/*根据编码获取角色详细*/
|
||||
'getMenuListApp' => '/menu/list/app',/*获取应用的菜单*/
|
||||
'getMenuListUserCode' => '/menu/list/user/{code}',/*获取用户权限菜单*/
|
||||
];
|
||||
|
||||
/**
|
||||
* 初始化配置,需要手动去.env文件里面填写以下配置项
|
||||
*
|
||||
* [SSO]
|
||||
* UC_URL='https://uc.test'
|
||||
* UC_CACHE_KEY='crm_dev'
|
||||
* APPID='cfcd05b1f3576e90cf53dc8a3d221ff7'
|
||||
* APPSECRET='271491c88ef42303da0251034aee3e5c'
|
||||
* UC_API_VERSION=v1
|
||||
* PUB_KEY='-----BEGIN PUBLIC KEY-----
|
||||
* -----END PUBLIC KEY-----'
|
||||
* PRI_KEY='-----BEGIN PRIVATE KEY-----
|
||||
* -----END PRIVATE KEY-----'
|
||||
*
|
||||
* UC_URL: 单点域名
|
||||
* UC_CACHE_KEY:单点应用 token 缓存key值,用于标识是哪个应用的,比如crm系统,线上使用orico_crm,测试使用 dev_crm,
|
||||
* APPID : 应用ID
|
||||
* APPSECRET:应用密钥
|
||||
*/
|
||||
private function initSSOConfig(): array
|
||||
{
|
||||
if (Cache::has('app_get_auth') && Cache::get('app_get_auth') == 1) {
|
||||
return $this->ssoApiConfig = [
|
||||
'appId' => Cache::get('app')['app_id'],/*应用的APPID*/
|
||||
'appSecret' => Cache::get('app')['app_secret'],/*应用密钥*/
|
||||
'ssoApiUrl' => Env::get('SSO.UC_URL'),/*单点请求链接*/
|
||||
'cacheKey' => Cache::get('app')['uc_cache_key'].'_app_token',/*应用token缓存key*/
|
||||
'apiVersion' => '/api/'.Env::get('SSO.UC_API_VERSION')/*接口版本*/
|
||||
];
|
||||
} else {
|
||||
return $this->ssoApiConfig = [
|
||||
'appId' => Session::get('app')['app_id'],/*应用的APPID*/
|
||||
'appSecret' => Session::get('app')['app_secret'],/*应用密钥*/
|
||||
'ssoApiUrl' => Env::get('SSO.UC_URL'),/*单点请求链接*/
|
||||
'cacheKey' => Session::get('app')['uc_cache_key'].'_app_token',/*应用token缓存key*/
|
||||
'apiVersion' => '/api/'.Env::get('SSO.UC_API_VERSION')/*接口版本*/
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求接口
|
||||
* @param array $data 请求数据
|
||||
* @param string $funcName 请求方法名
|
||||
* @param bool $isPost 请求类型,true = post| false = get
|
||||
* @param array $options 请求头
|
||||
* @return array
|
||||
*/
|
||||
public function setRequestURI(array $data, string $funcName, bool $isPost = false,array $options = []):array
|
||||
{
|
||||
// if (empty($this->ssoApiConfig)) {
|
||||
$this->initSSOConfig();
|
||||
// }
|
||||
//设置接口token
|
||||
if (empty($this->appToken) && $funcName != 'getAuthorizeToken') {
|
||||
$this->getAuthorizeToken();
|
||||
}
|
||||
|
||||
$arrToken = [];
|
||||
if ($funcName != 'getAuthorizeToken') {
|
||||
$arrToken['access_token'] = $this->appToken['access_token'];
|
||||
$data['access_token'] = $this->appToken['access_token'];
|
||||
}
|
||||
$params = null;
|
||||
if (false === $isPost) {
|
||||
//get请求
|
||||
if ($funcName == 'getStaffListDept') {
|
||||
$params = '?' . http_build_query($data);
|
||||
} else {
|
||||
$params = '?' . http_build_query($arrToken);
|
||||
}
|
||||
}
|
||||
|
||||
//拼接请求链接
|
||||
$url = $this->ssoApiConfig['ssoApiUrl'].$this->ssoApiConfig['apiVersion'].$this->apis[$funcName];/*post 请求*/
|
||||
|
||||
if (!is_null($params)) {
|
||||
//get 请求
|
||||
if (false === strpos($this->apis[$funcName],'{')) {
|
||||
$url = $this->ssoApiConfig['ssoApiUrl'].$this->ssoApiConfig['apiVersion'].$this->apis[$funcName].$params;
|
||||
} else {
|
||||
//解析出参数,restful 接口。 id/{:id}
|
||||
$arr = explode('/{',$this->apis[$funcName]);
|
||||
if (2 === count($arr)) {
|
||||
$param = rtrim($arr[1],'}');
|
||||
$newUrl = $arr[0];
|
||||
$url = $this->ssoApiConfig['ssoApiUrl'].$this->ssoApiConfig['apiVersion'].$newUrl.DIRECTORY_SEPARATOR.$data[$param].$params;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//执行请求
|
||||
$result = $this->http($url,$data,$isPost,$options);
|
||||
// \think\facade\Log::record($url);
|
||||
// \think\facade\Log::record(json_encode($result));
|
||||
if (isset($result['status']) && $result['status'] == 200) {
|
||||
return $result['data'];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用token
|
||||
*/
|
||||
public function getAuthorizeToken():array
|
||||
{
|
||||
// if (empty($this->ssoApiConfig)) {
|
||||
$this->initSSOConfig();
|
||||
// }
|
||||
$data = [
|
||||
'appid' => $this->ssoApiConfig['appId'],
|
||||
'app_secret'=> $this->ssoApiConfig['appSecret']
|
||||
];
|
||||
$this->appToken = Cache::get($this->ssoApiConfig['cacheKey']);
|
||||
if (is_null($this->appToken) || $this->appToken['expires_time'] - time() <= 600) {
|
||||
$data = $this->setRequestURI($data,__FUNCTION__,true);
|
||||
if (!empty($data)) {
|
||||
$data['expires_time'] = time() + $data['expires_in'];
|
||||
Cache::set($this->ssoApiConfig['cacheKey'], $data, $data['expires_in']-1000);
|
||||
$this->appToken = $data;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
return $this->appToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门分页数据
|
||||
* @param int $page 页码
|
||||
* @param int $size 每页条数
|
||||
* @param array $filter 查询条件,{"keywords":"dept_name=欧洲团"}
|
||||
* @return array
|
||||
*/
|
||||
public function getDeptList(int $page = 0,int $size = 0,array $filter = []):array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
if ($page != 0) {
|
||||
$data['page'] = $page;
|
||||
}
|
||||
|
||||
if ($size != 0) {
|
||||
$data['size'] = $size;
|
||||
}
|
||||
|
||||
if (!empty($filter)) {
|
||||
$data['filter'] = $filter;
|
||||
}
|
||||
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID部门详细
|
||||
* @param int $deptId 部门ID
|
||||
* @return array
|
||||
*/
|
||||
public function getDeptDetail(int $deptId):array
|
||||
{
|
||||
$data = [
|
||||
'id' => $deptId
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID部门详细
|
||||
* @param string $deptCode 部门dept_code
|
||||
* @return array
|
||||
*/
|
||||
public function getDeptDetailDeptCode(string $deptCode):array
|
||||
{
|
||||
$data = [
|
||||
'dept_code' => $deptCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编码获取部门主管
|
||||
* @param string $deptCode 部门dept_codes
|
||||
* @return array
|
||||
*/
|
||||
public function getDeptHead(string $deptCode):array
|
||||
{
|
||||
$data = [
|
||||
'dept_code' => $deptCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门ID获取部门上下级
|
||||
* @param int $deptId 部门ID
|
||||
* @return array
|
||||
*/
|
||||
public function getDeptChainId(int $deptId):array
|
||||
{
|
||||
$data = [
|
||||
'id' => $deptId
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门code获取部门上下级
|
||||
* @param string $deptCode 部门dept_code
|
||||
* @return array
|
||||
*/
|
||||
public function getDeptChainCode(string $deptCode):array
|
||||
{
|
||||
$data = [
|
||||
'code' => $deptCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工分页数据
|
||||
* @param int $page 页码
|
||||
* @param int $size 每页条数
|
||||
* @return array
|
||||
*/
|
||||
public function getStaffList(int $page = 0,int $size = 0):array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
if ($page != 0) {
|
||||
$data['page'] = $page;
|
||||
}
|
||||
|
||||
if ($size != 0) {
|
||||
$data['size'] = $size;
|
||||
}
|
||||
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门编码获取员工数据
|
||||
* @param string $deptCode 部门dept_code
|
||||
* @return array
|
||||
*/
|
||||
public function getStaffListDept(string $deptCode):array
|
||||
{
|
||||
$data = [
|
||||
'dept_code' => $deptCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户详细
|
||||
* @param int $uid 部门ID
|
||||
* @return array
|
||||
*/
|
||||
public function getUserDetailUid(int $uid):array
|
||||
{
|
||||
$data = [
|
||||
'uid' => $uid
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户(员工)编码获取用户(员工)详情
|
||||
* @param string $staffCode 员工staff_code
|
||||
* @return array
|
||||
*/
|
||||
public function getUserDetailStaffCode(string $staffCode):array
|
||||
{
|
||||
$data = [
|
||||
'staff_code' => $staffCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户所属部门
|
||||
* @param int $uid 部门ID
|
||||
* @return array
|
||||
*/
|
||||
public function getUserDepts(int $uid):array
|
||||
{
|
||||
$data = [
|
||||
'uid' => $uid
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户编码获取用户所属部门
|
||||
* @param string $staffCode 员工staff_code
|
||||
* @return array
|
||||
*/
|
||||
public function getUserDeptsStaffCode(string $staffCode):array
|
||||
{
|
||||
$data = [
|
||||
'staff_code' => $staffCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号获取用户详细
|
||||
* @param string $mobile 手机号
|
||||
* @return array
|
||||
*/
|
||||
public function getUserDetailMobile(string $mobile):array
|
||||
{
|
||||
$data = [
|
||||
'mobile' => $mobile
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取角色详细
|
||||
* @param int $roleId 角色role_id
|
||||
* @return array
|
||||
*/
|
||||
public function getRoleDetailId(int $roleId):array
|
||||
{
|
||||
$data = [
|
||||
'id' => $roleId
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编码获取角色详细
|
||||
* @param string $roleCode 角色role_code
|
||||
* @return array
|
||||
*/
|
||||
public function getRoleDetailCode(string $roleCode):array
|
||||
{
|
||||
$data = [
|
||||
'code' => $roleCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用的菜单
|
||||
* @return array
|
||||
*/
|
||||
public function getMenuListApp():array
|
||||
{
|
||||
return $this->setRequestURI([],__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限菜单
|
||||
* @param string $staffCode 用户staff_code
|
||||
* @return array
|
||||
*/
|
||||
public function getMenuListUserCode(string $staffCode):array
|
||||
{
|
||||
// 是否是用于检测有没有权限
|
||||
$this->appToken = [];
|
||||
|
||||
$data = [
|
||||
'code' => $staffCode
|
||||
];
|
||||
return $this->setRequestURI($data,__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* curl请求
|
||||
* @param $url string 请求的url链接
|
||||
* @param $data string|array|mixed 请求的数据
|
||||
* @param bool $is_post 是否是post请求,默认false
|
||||
* @param array $options 是否附带请求头
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function http(string $url, array $data, bool $is_post=false, array $options=[]):array
|
||||
{
|
||||
$data = json_encode($data);
|
||||
$headerArray = [
|
||||
'Content-type: application/json;charset=utf-8',
|
||||
'Accept: application/json'
|
||||
];
|
||||
$curl = curl_init();
|
||||
$arr = [];
|
||||
array_push($arr,$url);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
|
||||
if ($is_post) {
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
if (!empty($options['cookie'])) {
|
||||
curl_setopt($curl, CURLOPT_COOKIE, $options['cookie']);
|
||||
}
|
||||
$output = curl_exec($curl);
|
||||
$http_status = curl_errno($curl);
|
||||
$http_msg = curl_error($curl);
|
||||
curl_close($curl);
|
||||
if ($http_status == 0) {
|
||||
return json_decode($output, true);
|
||||
} else {
|
||||
return ['status' => $http_status, 'message' => $http_msg, 'data' => []];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user