common.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. use think\Db;
  3. use cmf\lib\Storage;
  4. use think\Config;
  5. function getErrCode($key = 0)
  6. {
  7. $info = array(
  8. 0 => '请求失败',
  9. 1 => '请求成功',
  10. 10001 => '未登录'
  11. );
  12. return $info[$key];
  13. }
  14. /**
  15. * 判断前台用户是否登录
  16. * @return boolean
  17. */
  18. function battery_is_user_login()
  19. {
  20. $sessionUser = session('battery_user');
  21. return !empty($sessionUser);
  22. }
  23. /**
  24. * 更新当前登录前台用户的信息
  25. * @param array $user 前台用户的信息
  26. */
  27. function battery_update_current_user($user){
  28. session('battery_user', $user);
  29. }
  30. /**
  31. * 获取当前登录的前台用户的信息,未登录时,返回false
  32. * @return array|boolean
  33. */
  34. function battery_get_current_user()
  35. {
  36. $sessionUser = session('battery_user');
  37. if (!empty($sessionUser)) {
  38. unset($sessionUser['battery_user_pass']); // 销毁敏感数据
  39. return $sessionUser;
  40. } else {
  41. return false;
  42. }
  43. }
  44. function curl_get_contents($url){
  45. $ch=curl_init();
  46. curl_setopt($ch, CURLOPT_URL, $url); //设置访问的url地址
  47. // curl_setopt($ch,CURLOPT_HEADER,1); //是否显示头部信息
  48. curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置超时
  49. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  50. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  51. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //用户访问代理 User-Agent
  52. curl_setopt($ch, CURLOPT_REFERER,$_SERVER['HTTP_HOST']); //设置 referer
  53. curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); //跟踪301
  54. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回结果
  55. $r=curl_exec($ch);
  56. curl_close($ch);
  57. return $r;
  58. }
  59. function hcw_get_md5($str='')
  60. {
  61. return md5('xlC0TSdijC2ESHQD'.$str);
  62. }