User.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. namespace app\admin\common;
  3. class User
  4. {
  5. private $appid = '123';
  6. private $appkey = '12345';
  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. "userall" => 'userall',//所有账号
  27. //【公司账号管理】
  28. 'userCompanyBasicList' => 'userCompanyBasicList',//【列表】
  29. 'userCompanyBasicAdd' => 'userCompanyBasicAdd',//【添加】
  30. 'userCompanyBasicDelete' => 'userCompanyBasicDelete',//【删除】
  31. 'userCompanyBasicUpdate' => 'userCompanyBasicUpdate',//【修改】
  32. 'userCompanyBasicStatus' => 'userCompanyBasicStatus',//【启禁用】
  33. 'userCompanyBasicInfo' => 'userCompanyBasicInfo',//【详情】
  34. //【公司账号查询】
  35. 'userCompanyList' => 'userCompanyList',//【列表】
  36. 'userCompanyStatus' => 'userCompanyStatus',//【启禁用】
  37. 'userCompanyInfo' => 'userCompanyInfo',//【详情】
  38. 'changeMain' => 'changeMain',//【切换默认公司】
  39. //【公司汇总】
  40. 'hqList' => 'hqList',
  41. 'hqAdd' => 'hqAdd',
  42. 'hqUpdate' => 'hqUpdate',
  43. 'hqInfo' => 'hqInfo',
  44. 'delete' => 'delete',
  45. 'status' => 'status',
  46. 'sGetList' => 'sGetList',
  47. 'sCreate' => 'sCreate',
  48. 'sInfo' => 'sInfo',
  49. 'sEdit' => 'sEdit',
  50. 'bGetList' => 'bGetList',
  51. 'bCreate' => 'bCreate',
  52. 'bInfo' => 'bInfo',
  53. 'bEdit' => 'bEdit',
  54. 'bTitle' => 'bTitle',
  55. 'cInfo' => 'cInfo',
  56. 'cTitle' => 'cTitle',
  57. 'cCreate' => 'cCreate',
  58. 'cList' => 'cList',
  59. 'cEdit' => 'cEdit',
  60. 'customer_org_create' => 'customer_org_create',
  61. 'customer_org_list' => 'customer_org_list',
  62. 'customer_org_update' => 'customer_org_update',
  63. 'customer_org_info' => 'customer_org_info',
  64. 'customer_org_delete' => 'customer_org_delete',
  65. 'customer_org_status' => 'customer_org_status',
  66. 'get_top_customer_org' => 'get_top_customer_org',
  67. 'getCodeAndName' => 'getCodeAndName',
  68. 'upgrade' => 'supplerUpgrade',
  69. 'get_business_list_tmp' => 'get_business_list_tmp',
  70. //组织架构
  71. 'ulist' => 'ulist',
  72. 'add' => 'add',
  73. 'query' => 'query',
  74. 'refresh' => 'refresh',
  75. 'itemdel' => 'itemdel',
  76. 'stat' => 'stat',
  77. 'userp' => 'userp',
  78. 'get_part' => 'get_part',//获取部门名称
  79. 'get_company_name_by_uid' => 'get_company_name_by_uid',//获取某个用户所属部门名称
  80. 'get_company_item_user_by_name' => 'get_company_item_user_by_name',//获取某个用户所属部门名称
  81. 'ciinfo' => 'ciinfo',//获取部门详情
  82. 'check_has_account_by_supplierNos' => 'check_has_account_by_supplierNos',//检查供应商是否有开通账号
  83. ];
  84. private static $obj = null;
  85. public static function getIns()
  86. {
  87. if (is_null(self::$obj)) self::$obj = new self;
  88. return self::$obj;
  89. }
  90. //禁止new
  91. private function __construct()
  92. {
  93. $this->Sign = new Sign($this->appid, $this->appkey);
  94. $this->host = env("user.hosturl", '');
  95. }
  96. /**
  97. * 生成请求header参数
  98. */
  99. private function makeHeader()
  100. {
  101. $headerArr = ["appid" => $this->appid, "noce" => randomkeys(16), "sign" => '', "timestamp" => time()];
  102. $value = array_merge($this->param, $headerArr);
  103. $headerArr['sign'] = $this->Sign->makeSign($value);
  104. foreach ($headerArr as $key => $value) {
  105. $this->header[] = $key . ":" . $value;
  106. }
  107. }
  108. /**模拟post 请求数据
  109. * @param $url
  110. * @param array $param
  111. */
  112. private function post($url, $param = [])
  113. {
  114. $this->param = $param;
  115. $this->makeHeader();
  116. if (is_array($param)) $post = http_build_query($param);
  117. $curl = curl_init();
  118. curl_setopt($curl, CURLOPT_URL, $url);
  119. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
  120. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  121. curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  122. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  123. if ($post) {
  124. curl_setopt($curl, CURLOPT_POST, 1);
  125. curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
  126. }
  127. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  128. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  129. curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);
  130. $data = curl_exec($curl);
  131. if (curl_errno($curl)) {
  132. return curl_error($curl);
  133. }
  134. curl_close($curl);
  135. return $data;
  136. }
  137. /** 登录接口
  138. * @param $param
  139. * @return bool|string
  140. */
  141. public function Login($param)
  142. {
  143. return $this->post($this->host . $this->api["login"], $param);
  144. }
  145. public function VerifyTokens($param)
  146. {
  147. return $this->post($this->host . $this->api["verifyToken"], $param);
  148. }
  149. public function GetUserInfo($param)
  150. {
  151. return $this->post($this->host . $this->api["userinfo"], $param);
  152. }
  153. public function GetUserlist($param)
  154. {
  155. return $this->post($this->host . $this->api["userlist"], $param);
  156. }
  157. public function GetList($param)
  158. {
  159. return $this->post($this->host . $this->api["userlistbycompany"], $param);
  160. }
  161. public function GetAccountall($param)
  162. {
  163. return $this->post($this->host . $this->api["userlist"], $param);
  164. }
  165. public function resetPasswd($param)
  166. {
  167. return $this->post($this->host . $this->api["setpasswd"], $param);
  168. }
  169. public function resetInfo($param)
  170. {
  171. return $this->post($this->host . $this->api["usersave"], $param);
  172. }
  173. public function resetState($param)
  174. {
  175. return $this->post($this->host . $this->api["userstatus"], $param);
  176. }
  177. //删除
  178. public function userDelete(array $param = [])
  179. {
  180. return $this->post($this->host . $this->api['userDelete'], $param);
  181. }
  182. //修改
  183. public function userSave(array $param = [])
  184. {
  185. return $this->post($this->host . $this->api['usersave'], $param);
  186. }
  187. //通用
  188. public function handle(string $key = '', array $param = [])
  189. {
  190. $rs = $this->post($this->host . $this->api[$key], $param);
  191. // echo $rs;exit;
  192. return json_decode($rs, true);
  193. }
  194. //方便调试
  195. public function debug(string $key = '', array $param = [])
  196. {
  197. $rs = $this->post($this->host . $this->api[$key], $param);
  198. echo $rs;
  199. exit;
  200. }
  201. //禁止外部克隆
  202. private function __clone()
  203. {
  204. }
  205. //禁止实例化
  206. private function __wakeup()
  207. {
  208. }
  209. }