functions.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Here is your custom functions.
  4. */
  5. if (!function_exists('http_post')) {
  6. function http_post($url, $params)
  7. {
  8. $ch = curl_init();
  9. $this_header = array("content-type: application/x-www-form-urlencoded;charset=UTF-8");
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  13. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  14. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  15. curl_setopt($ch, CURLOPT_POST, 1);
  16. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//如果不加验证,就设false,商户自行处理
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  19. $output = curl_exec($ch);
  20. curl_close($ch);
  21. return $output;
  22. }
  23. }
  24. if (!function_exists('http_post_json')) {
  25. function http_post_json($url, $params)
  26. {
  27. $ch = curl_init();
  28. $this_header = array('Content-Type: application/json;charset=UTF-8');
  29. curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
  30. curl_setopt($ch, CURLOPT_URL, $url);
  31. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  32. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  33. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  34. curl_setopt($ch, CURLOPT_POST, 1);
  35. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
  36. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//如果不加验证,就设false,商户自行处理
  37. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  38. $output = curl_exec($ch);
  39. curl_close($ch);
  40. return $output;
  41. }
  42. }
  43. if (!function_exists('month_12')) {
  44. function month_12()
  45. {
  46. $months = [];
  47. for ($i = 0; $i < 12; $i++) {
  48. $months[$i] = date('Y/m', strtotime(date('Y-m-01') . "-" . $i . "month"));
  49. }
  50. return $months;
  51. }
  52. }
  53. /**
  54. * @Desc 管理员操作日志
  55. * @Author Gorden
  56. * @Date 2024/3/29 17:07
  57. *
  58. * adminId = 1001 充值
  59. *
  60. *
  61. * @param $name
  62. * @param $operation
  63. * @return void
  64. */
  65. if (!function_exists('_syslog')) {
  66. function _syslog($name, $operation, $operationData = false, $requestParams = false, $adminId = false)
  67. {
  68. $logAdminId = $adminId ? $adminId : \Tinywan\Jwt\JwtToken::getCurrentId();
  69. $model = new \app\model\SysLog();
  70. $model->log_admin_id = $logAdminId;
  71. $model->log_name = $name;
  72. $model->log_route = \request() && \request()->uri() ? \request()->uri() : (\request() && \request()->route && \request()->route->getPath() ? \request()->route->getPath() : '');
  73. $model->log_operation = $operation;
  74. $model->log_ip = \request() && \request()->getRealIp() ? \request()->getRealIp() : '0.0.0.0';
  75. $model->log_request_params = $requestParams ? json_encode($requestParams) : json_encode(\request()->all());
  76. $model->log_operation_data = $operationData ? json_encode($operationData) : null;
  77. $model->save();
  78. }
  79. }
  80. if (!function_exists('json_throw')) {
  81. function json_throw($code, $message, $data = '', $options = JSON_UNESCAPED_UNICODE)
  82. {
  83. $return = [
  84. 'code' => $code,
  85. 'message' => $message,
  86. 'data' => $data,
  87. ];
  88. return new \support\Response(200, ['Content-Type' => 'application/json'], json_encode($return, $options));
  89. }
  90. }