|
@@ -0,0 +1,111 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace app\admin\common;
|
|
|
+
|
|
|
+
|
|
|
+class User {
|
|
|
+ private $appid='';
|
|
|
+ private $appkey='';
|
|
|
+ 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',
|
|
|
+ ];
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|