common.php 699 B

12345678910111213141516171819202122232425
  1. <?php
  2. // 应用公共文件
  3. function ajax_return($code = 0, $msg = '', $data = [])
  4. {
  5. $res = ['code' => $code, 'msg' => $msg, 'data' => $data];
  6. $response = \think\Response::create($res, 'json');
  7. throw new \think\exception\HttpResponseException($response);
  8. }
  9. function url(string $url = '', array $vars = [], $suffix = true, $domain = true)
  10. {
  11. return \think\facade\Route::buildUrl($url, $vars)->suffix($suffix)->domain($domain);
  12. }
  13. function rand_str($len = 6)
  14. {
  15. $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  16. $res = '';
  17. for ($i = 0; $i < $len; $i++) {
  18. $key = rand(0, strlen($str));
  19. $res .= $str[$key];
  20. }
  21. return $res;
  22. }