123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace app\admin\common;
- class User
- {
- private $appid = 'cx';
- private $appkey = 'cx123123';
- private $Sign;
- private $param = [];
- private $header = ["Content-Type" => "multipart/json;charset=utf-8"];
- private $host;
- private $api = [
- "login" => 'login',
- "verifyToken" => 'verifyToken',
- "register" => 'register',
- "userlist" => 'userlist',
- "usersave" => 'usersave',
- "userstatus" => 'userstatus',
- "userinfo" => 'userinfo',
- "setpasswd" => 'setpasswd',
- "setcompany" => 'setcompany',
- "companystatus" => 'companystatus',
- "userlistbycompany" => 'userlistbycompany',
- "useradd" => 'useradd',
- "userDelete" => 'userDelete',//删除
- //【公司账号管理】
- 'userCompanyBasicList' => 'userCompanyBasicList',//【列表】
- 'userCompanyBasicAdd' => 'userCompanyBasicAdd',//【添加】
- 'userCompanyBasicDelete' => 'userCompanyBasicDelete',//【删除】
- 'userCompanyBasicUpdate' => 'userCompanyBasicUpdate',//【修改】
- 'userCompanyBasicStatus' => 'userCompanyBasicStatus',//【启禁用】
- 'userCompanyBasicInfo' => 'userCompanyBasicInfo',//【详情】
- //【公司账号查询】
- 'userCompanyList' => 'userCompanyList',//【列表】
- 'userCompanyStatus' => 'userCompanyStatus',//【启禁用】
- 'userCompanyInfo' => 'userCompanyInfo',//【详情】
- ];
- public function __construct()
- {
- $this->Sign = new Sign($this->appid, $this->appkey);
- $this->host = env("user.hosturl", '');
- }
- /**
- * 生成请求header参数
- */
- private function makeHeader()
- {
- $headerArr = ["appid" => $this->appid, "noce" => randomkeys(16), "sign" => '', "timestamp" => time()];
- $value = array_merge($this->param, $headerArr);
- $headerArr['sign'] = $this->Sign->makeSign($value);
- foreach ($headerArr as $key => $value) {
- $this->header[] = $key . ":" . $value;
- }
- }
- /**模拟post 请求数据
- * @param $url
- * @param array $param
- */
- private function post($url, $param = [])
- {
- $this->param = $param;
- $this->makeHeader();
- if (is_array($param)) $post = http_build_query($param);
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- if ($post) {
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
- }
- curl_setopt($curl, CURLOPT_TIMEOUT, 10);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);
- $data = curl_exec($curl);
- if (curl_errno($curl)) {
- return curl_error($curl);
- }
- curl_close($curl);
- return $data;
- }
- /** 登录接口
- * @param $param
- * @return bool|string
- */
- public function Login($param)
- {
- return $this->post($this->host . $this->api["login"], $param);
- }
- public function VerifyTokens($param)
- {
- return $this->post($this->host . $this->api["verifyToken"], $param);
- }
- public function GetUserInfo($param)
- {
- return $this->post($this->host . $this->api["userinfo"], $param);
- }
- public function GetUserlist($param)
- {
- return $this->post($this->host . $this->api["userlist"], $param);
- }
- public function GetList($param)
- {
- return $this->post($this->host . $this->api["userlistbycompany"], $param);
- }
- public function GetAccountall($param)
- {
- return $this->post($this->host . $this->api["userlist"], $param);
- }
- public function resetPasswd($param)
- {
- return $this->post($this->host . $this->api["setpasswd"], $param);
- }
- public function resetInfo($param)
- {
- return $this->post($this->host . $this->api["usersave"], $param);
- }
- public function resetState($param)
- {
- return $this->post($this->host . $this->api["userstatus"], $param);
- }
- //删除
- public function userDelete(array $param = [])
- {
- return $this->post($this->host . $this->api['userDelete'], $param);
- }
- //修改
- public function userSave(array $param = [])
- {
- return $this->post($this->host . $this->api['usersave'], $param);
- }
- //通用
- public function handle(string $key = '', array $param = [])
- {
- return $this->post($this->host . $this->api[$key], $param);
- }
- }
|