User.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace app\admin\common;
  3. class User
  4. {
  5. private $appid = 'cx';
  6. private $appkey = 'cx123123';
  7. private $Sign;
  8. private $param = [];
  9. private $header = ["Content-Type" => "multipart/json;charset=utf-8"];
  10. private $host;
  11. private $api = [
  12. "login" => 'login',
  13. "verifyToken" => 'verifyToken',
  14. "register" => 'register',
  15. "userlist" => 'userlist',
  16. "usersave" => 'usersave',
  17. "userstatus" => 'userstatus',
  18. "userinfo" => 'userinfo',
  19. "setpasswd" => 'setpasswd',
  20. "setcompany" => 'setcompany',
  21. "companystatus" => 'companystatus',
  22. "userlistbycompany" => 'userlistbycompany',
  23. "useradd" => 'useradd',
  24. "userDelete" => 'userDelete',//删除
  25. "passSetByPassword" => 'passSetByPassword',//修改密码
  26. //【公司账号管理】
  27. 'userCompanyBasicList' => 'userCompanyBasicList',//【列表】
  28. 'userCompanyBasicAdd' => 'userCompanyBasicAdd',//【添加】
  29. 'userCompanyBasicDelete' => 'userCompanyBasicDelete',//【删除】
  30. 'userCompanyBasicUpdate' => 'userCompanyBasicUpdate',//【修改】
  31. 'userCompanyBasicStatus' => 'userCompanyBasicStatus',//【启禁用】
  32. 'userCompanyBasicInfo' => 'userCompanyBasicInfo',//【详情】
  33. //【公司账号查询】
  34. 'userCompanyList' => 'userCompanyList',//【列表】
  35. 'userCompanyStatus' => 'userCompanyStatus',//【启禁用】
  36. 'userCompanyInfo' => 'userCompanyInfo',//【详情】
  37. 'changeMain' => 'changeMain',//【切换默认公司】
  38. //【公司汇总】
  39. 'hqList' => 'hqList',
  40. 'hqAdd' => 'hqAdd',
  41. 'hqUpdate' => 'hqUpdate',
  42. 'hqInfo' => 'hqInfo',
  43. 'delete' => 'delete',
  44. 'status' => 'status',
  45. 'sGetList' => 'sGetList',
  46. 'sCreate' => 'sCreate',
  47. 'sInfo' => 'sInfo',
  48. 'sEdit' => 'sEdit',
  49. 'bGetList' => 'bGetList',
  50. 'bCreate' => 'bCreate',
  51. 'bInfo' => 'bInfo',
  52. 'bEdit' => 'bEdit',
  53. 'bTitle' => 'bTitle',
  54. 'cTitle' => 'cTitle',
  55. 'getCodeAndName' => 'getCodeAndName',
  56. 'upgrade' => 'supplerUpgrade',
  57. 'get_business_list_tmp' => 'get_business_list_tmp',
  58. //组织架构
  59. 'ulist'=>'ulist',
  60. 'add'=>'add',
  61. 'query'=>'query',
  62. 'refresh'=>'refresh',
  63. 'itemdel'=>'itemdel',
  64. 'stat'=>'stat',
  65. 'userp'=>'userp',
  66. 'get_part'=>'get_part',//获取部门名称
  67. 'get_company_name_by_uid'=>'get_company_name_by_uid',//获取某个用户所属部门名称
  68. 'get_company_item_user_by_name'=>'get_company_item_user_by_name',//获取某个用户所属部门名称
  69. 'ciinfo'=>'ciinfo',//获取部门详情
  70. ];
  71. public function __construct()
  72. {
  73. $this->Sign = new Sign($this->appid, $this->appkey);
  74. $this->host = env("user.hosturl", '');
  75. }
  76. /**
  77. * 生成请求header参数
  78. */
  79. private function makeHeader()
  80. {
  81. $headerArr = ["appid" => $this->appid, "noce" => randomkeys(16), "sign" => '', "timestamp" => time()];
  82. $value = array_merge($this->param, $headerArr);
  83. $headerArr['sign'] = $this->Sign->makeSign($value);
  84. foreach ($headerArr as $key => $value) {
  85. $this->header[] = $key . ":" . $value;
  86. }
  87. }
  88. /**模拟post 请求数据
  89. * @param $url
  90. * @param array $param
  91. */
  92. private function post($url, $param = [])
  93. {
  94. $this->param = $param;
  95. $this->makeHeader();
  96. if (is_array($param)) $post = http_build_query($param);
  97. $curl = curl_init();
  98. curl_setopt($curl, CURLOPT_URL, $url);
  99. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
  100. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  101. curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  102. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  103. if ($post) {
  104. curl_setopt($curl, CURLOPT_POST, 1);
  105. curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
  106. }
  107. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  108. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  109. curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);
  110. $data = curl_exec($curl);
  111. if (curl_errno($curl)) {
  112. return curl_error($curl);
  113. }
  114. curl_close($curl);
  115. return $data;
  116. }
  117. /** 登录接口
  118. * @param $param
  119. * @return bool|string
  120. */
  121. public function Login($param)
  122. {
  123. return $this->post($this->host . $this->api["login"], $param);
  124. }
  125. public function VerifyTokens($param)
  126. {
  127. return $this->post($this->host . $this->api["verifyToken"], $param);
  128. }
  129. public function GetUserInfo($param)
  130. {
  131. return $this->post($this->host . $this->api["userinfo"], $param);
  132. }
  133. public function GetUserlist($param)
  134. {
  135. return $this->post($this->host . $this->api["userlist"], $param);
  136. }
  137. public function GetList($param)
  138. {
  139. return $this->post($this->host . $this->api["userlistbycompany"], $param);
  140. }
  141. public function GetAccountall($param)
  142. {
  143. return $this->post($this->host . $this->api["userlist"], $param);
  144. }
  145. public function resetPasswd($param)
  146. {
  147. return $this->post($this->host . $this->api["setpasswd"], $param);
  148. }
  149. public function resetInfo($param)
  150. {
  151. return $this->post($this->host . $this->api["usersave"], $param);
  152. }
  153. public function resetState($param)
  154. {
  155. return $this->post($this->host . $this->api["userstatus"], $param);
  156. }
  157. //删除
  158. public function userDelete(array $param = [])
  159. {
  160. return $this->post($this->host . $this->api['userDelete'], $param);
  161. }
  162. //修改
  163. public function userSave(array $param = [])
  164. {
  165. return $this->post($this->host . $this->api['usersave'], $param);
  166. }
  167. //通用
  168. public function handle(string $key = '', array $param = [])
  169. {
  170. $rs = $this->post($this->host . $this->api[$key], $param);
  171. // echo $rs;exit;
  172. return json_decode($rs, true);
  173. }
  174. //方便调试
  175. public function debug(string $key = '', array $param = [])
  176. {
  177. $rs = $this->post($this->host . $this->api[$key], $param);
  178. echo $rs;exit;
  179. }
  180. }