"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',//删除 "passSetByPassword" => 'passSetByPassword',//修改密码 "userall" => 'userall',//所有账号 //【公司账号管理】 'userCompanyBasicList' => 'userCompanyBasicList',//【列表】 'userCompanyBasicAdd' => 'userCompanyBasicAdd',//【添加】 'userCompanyBasicDelete' => 'userCompanyBasicDelete',//【删除】 'userCompanyBasicUpdate' => 'userCompanyBasicUpdate',//【修改】 'userCompanyBasicStatus' => 'userCompanyBasicStatus',//【启禁用】 'userCompanyBasicInfo' => 'userCompanyBasicInfo',//【详情】 //【公司账号查询】 'userCompanyList' => 'userCompanyList',//【列表】 'userCompanyStatus' => 'userCompanyStatus',//【启禁用】 'userCompanyInfo' => 'userCompanyInfo',//【详情】 'changeMain' => 'changeMain',//【切换默认公司】 //【公司汇总】 'hqList' => 'hqList', 'hqAdd' => 'hqAdd', 'hqUpdate' => 'hqUpdate', 'hqInfo' => 'hqInfo', 'delete' => 'delete', 'status' => 'status', 'sGetList' => 'sGetList', 'sCreate' => 'sCreate', 'sInfo' => 'sInfo', 'sEdit' => 'sEdit', 'bGetList' => 'bGetList', 'bCreate' => 'bCreate', 'bInfo' => 'bInfo', 'bEdit' => 'bEdit', 'bTitle' => 'bTitle', 'cInfo' => 'cInfo', 'cTitle' => 'cTitle', 'cCreate' => 'cCreate', 'cList' => 'cList', 'cEdit' => 'cEdit', 'customer_org_create' => 'customer_org_create', 'customer_org_list' => 'customer_org_list', 'customer_org_update' => 'customer_org_update', 'customer_org_info' => 'customer_org_info', 'customer_org_delete' => 'customer_org_delete', 'customer_org_status' => 'customer_org_status', 'get_top_customer_org' => 'get_top_customer_org', 'getCodeAndName' => 'getCodeAndName', 'upgrade' => 'supplerUpgrade', 'get_business_list_tmp' => 'get_business_list_tmp', //组织架构 'ulist' => 'ulist', 'add' => 'add', 'query' => 'query', 'refresh' => 'refresh', 'itemdel' => 'itemdel', 'stat' => 'stat', 'userp' => 'userp', 'get_part' => 'get_part',//获取部门名称 'get_company_name_by_uid' => 'get_company_name_by_uid',//获取某个用户所属部门名称 'get_company_item_user_by_name' => 'get_company_item_user_by_name',//获取某个用户所属部门名称 'ciinfo' => 'ciinfo',//获取部门详情 'check_has_account_by_supplierNos' => 'check_has_account_by_supplierNos',//检查供应商是否有开通账号 ]; private static $obj = null; public static function getIns() { if (is_null(self::$obj)) self::$obj = new self; return self::$obj; } //禁止new private 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 = []) { $rs = $this->post($this->host . $this->api[$key], $param); // echo $rs;exit; return json_decode($rs, true); } //方便调试 public function debug(string $key = '', array $param = []) { $rs = $this->post($this->host . $this->api[$key], $param); echo $rs; exit; } //禁止外部克隆 private function __clone() { } //禁止实例化 private function __wakeup() { } }