function.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. function appExec($module, $class, $action)
  3. {
  4. S('MODULE', $module);
  5. S("CONTROLLER", $class);
  6. S("ACTION", $action);
  7. S('URL_PATH', "/{$module}/{$class}/{$action}");
  8. $ctrl = \App::make("\\App\\Http\\Controllers\\" . ucfirst($module) . "\\" . ucfirst($class) . "Controller");
  9. return \App::call([$ctrl, $action]);
  10. }
  11. function toJson($status, $msg = '', $data = '')
  12. {
  13. $return = array(); //返回数组
  14. //组装状态码和返回数据
  15. if ($status < 0) {
  16. $return['status'] = $status;
  17. $return['data'] = $data;
  18. } else {
  19. if (!is_numeric($status)) {
  20. $return['data'] = $status;
  21. $return['status'] = 1;
  22. } else {
  23. $return['status'] = $status;
  24. $return['data'] = $data;
  25. }
  26. }
  27. if(empty($return['data'])){
  28. $return['data']=[];
  29. }
  30. //组装返回信息
  31. if (empty($msg)) {
  32. $return['msg'] = trans('error.' . $return['status']);
  33. } else {
  34. $return['msg'] = $msg;
  35. }
  36. //返回json数据
  37. return response()->json($return);
  38. }
  39. function getOrderId($prefix = '')
  40. {
  41. $num = mt_rand(100, 999);
  42. list($s, $m) = explode(' ', microtime());
  43. $order = date("YmdHis") . ($s * 1000000) . $num;
  44. return $prefix . $order;
  45. }
  46. //identity生产
  47. function getUUID()
  48. {
  49. $prefix = '';
  50. $uuid = '';
  51. $str = md5(uniqid(mt_rand(), true));
  52. $uuid = substr($str, 0, 8) . '-';
  53. $uuid .= substr($str, 8, 4) . '-';
  54. $uuid .= substr($str, 12, 4) . '-';
  55. $uuid .= substr($str, 16, 4) . '-';
  56. $uuid .= substr($str, 20, 12);
  57. return $prefix . $uuid;
  58. }
  59. function S($key, $value = '')
  60. {
  61. if (!isset($GLOBALS[$key]) && empty($value)) {
  62. return -1;
  63. }
  64. if (isset($GLOBALS[$key]) && empty($value)) {
  65. return $GLOBALS[$key];
  66. }
  67. return $GLOBALS[$key] = $value;
  68. }
  69. /**
  70. *密码加密码
  71. */
  72. function randcode($num=6)
  73. {
  74. srand((double) microtime() * 1000000); //create a random number feed.
  75. $ychar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
  76. $list = explode(",", $ychar);
  77. $authnum = "";
  78. for ($i = 0; $i < $num; $i++) {
  79. $randnum = rand(0, 61); // 10+26;
  80. $authnum .= $list[$randnum];
  81. }
  82. return $authnum;
  83. }
  84. function createPasswd($passwd,$solt){
  85. return md5(md5($solt.$passwd));
  86. }