common.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. // 应用公共文件
  3. use think\facade\Config;
  4. use think\facade\Db;
  5. use think\facade\Filesystem;
  6. // 应用公共文件
  7. function app_show($code=0,$message="",$data=[]){
  8. $result = ['code'=>$code,"message"=>$message,"data"=>$data];
  9. echo json_encode($result,JSON_UNESCAPED_UNICODE);
  10. die();
  11. }
  12. // 应用公共文件
  13. function error_show($code=0,$message=""){
  14. $result = ['code'=>$code,"message"=>$message];
  15. echo json_encode($result,JSON_UNESCAPED_UNICODE);
  16. die();
  17. }
  18. function GetUserInfo($token){
  19. $host = Config::get("app");
  20. $url = $host["api_host"]."/Api/userinfo";
  21. $data=[
  22. "token"=>$token
  23. ];
  24. $response=curl_request($url,$data);
  25. return json_decode($response,true);
  26. }
  27. /**手机号验证
  28. * @param $mobile
  29. * @return bool
  30. */
  31. function checkMobile($mobile){
  32. if (!is_numeric($mobile)) {
  33. return false;
  34. }
  35. return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false;
  36. }
  37. function checkTel($tel){
  38. if (!$tel) {
  39. return false;
  40. }
  41. return preg_match('/^(0[0-9]{2,3}\-)([0-9]{7,8})+(\-[0-9]{1,4})?$/', $tel) ? true : false;
  42. }
  43. /**邮箱验证
  44. * @param $email
  45. * @return bool
  46. */
  47. function checkEmail($email){
  48. if (!$email) {
  49. return false;
  50. }
  51. return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false;
  52. }
  53. /**
  54. * @param
  55. * @return int
  56. */
  57. function makeSalt(){
  58. $salt = rand(10000000,99999999);
  59. return $salt;
  60. }
  61. /**
  62. * @param $token
  63. * @return array
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @throws \think\exception\DbException
  68. */
  69. function VerifyTokens($token){
  70. $host = Config::get("app");
  71. $url = $host["api_host"]."/Api/verify_token";
  72. $data=[
  73. "token"=>$token
  74. ];
  75. $response=curl_request($url,$data);
  76. return json_decode($response,true);
  77. }
  78. /**
  79. * @param $token
  80. * @param $condition
  81. * @return mixed
  82. */
  83. function GetUserlist($token,$condition){
  84. $host = Config::get("app");
  85. $url = $host["api_host"]."/Api/getuserlist";
  86. $condition['token']=$token;
  87. $response=curl_request($url,$condition);
  88. return json_decode($response,true);
  89. }
  90. /**
  91. * @param $token
  92. * @param $condition
  93. * @return mixed
  94. */
  95. function GetAccountall($token, $condition){
  96. $host = Config::get("app");
  97. $url = $host["api_host"]."/Api/userall";
  98. $condition['token']=$token;
  99. $response=curl_request($url,$condition);
  100. return json_decode($response,true);
  101. }
  102. function GetList($token,$condition){
  103. $host = Config::get("app");
  104. $url = $host["api_host"]."/Api/userlist";
  105. $condition['token']=$token;
  106. $response=curl_request($url,$condition);
  107. return json_decode($response,true);
  108. }
  109. /**
  110. * @param $token
  111. * @param $condition ['id'=>1]
  112. * @return mixed
  113. */
  114. function GetInfoById($token,$condition){
  115. $host = Config::get("app");
  116. $url = $host["api_host"]."/Api/userinfobyid";
  117. $condition['token']=$token;
  118. $response=curl_request($url,$condition);
  119. return json_decode($response,true);
  120. }
  121. /**
  122. * @param $str
  123. * @return string
  124. */
  125. function makeNo($str){
  126. $date=date("mdHis");
  127. $year = date("Y")-2000;
  128. $msec=rand(1000,9999);
  129. return $str.$year.$date.$msec;
  130. }
  131. /**
  132. * @param $token
  133. * @param $condition
  134. * @return mixed
  135. */
  136. function resetpwd($token,$condition){
  137. $host = Config::get("app");
  138. $url = $host["api_host"]."/Api/passset";
  139. $condition['token']=$token;
  140. $response=curl_request($url,$condition);
  141. return json_decode($response,true);
  142. }
  143. function resetpasswd($token,$condition){
  144. $host = Config::get("app");
  145. $url = $host["api_host"]."/Api/passsave";
  146. $condition['token']=$token;
  147. $response=curl_request($url,$condition);
  148. return json_decode($response,true);
  149. }
  150. /**
  151. * @param $token
  152. * @param $condition
  153. * @return mixed
  154. */
  155. function resetinfo($token,$condition){
  156. $host = Config::get("app");
  157. $url = $host["api_host"]."/Api/usersave";
  158. $condition['token']=$token;
  159. $response=curl_request($url,$condition);
  160. return json_decode($response,true);
  161. }
  162. //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
  163. function curl_request($url,$post=''){
  164. $curl = curl_init();
  165. curl_setopt($curl, CURLOPT_URL, $url);
  166. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
  167. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  168. curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  169. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  170. if($post) {
  171. curl_setopt($curl, CURLOPT_POST, 1);
  172. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
  173. }
  174. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  175. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  176. $data = curl_exec($curl);
  177. if (curl_errno($curl)) {
  178. return curl_error($curl);
  179. }
  180. curl_close($curl);
  181. return $data;
  182. }
  183. function checkRole($roleid,$menu){
  184. $roleinfo = \think\facade\Db::name("role_action")->where([['role_id',"=",$roleid],["status","=",1]])->find();
  185. if($roleinfo['private_data']!=""){
  186. $private = explode(",",$roleinfo['private_data']);
  187. if(in_array($menu,$private)){
  188. return true;
  189. }
  190. }
  191. return false;
  192. }