functions.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // 写日志
  41. \support\Log::info('模拟请求:',json_decode($output,true));
  42. return $output;
  43. }
  44. }
  45. if (!function_exists('month_12')) {
  46. function month_12()
  47. {
  48. $months = [];
  49. for ($i = 0; $i < 12; $i++) {
  50. $months[$i] = date('Y/m', strtotime(date('Y-m-01') . "-" . $i . "month"));
  51. }
  52. return $months;
  53. }
  54. }
  55. /**
  56. * @Desc 管理员操作日志
  57. * @Author Gorden
  58. * @Date 2024/3/29 17:07
  59. *
  60. * adminId = 1001 充值
  61. *
  62. *
  63. * @param $name
  64. * @param $operation
  65. * @return void
  66. */
  67. if (!function_exists('_syslog')) {
  68. function _syslog($name, $operation, $operationData = false, $requestParams = false, $adminId = false)
  69. {
  70. $logAdminId = $adminId ? $adminId : \Tinywan\Jwt\JwtToken::getCurrentId();
  71. $model = new \app\model\SysLog();
  72. $model->log_admin_id = $logAdminId;
  73. $model->log_name = $name;
  74. $model->log_route = \request() && \request()->uri() ? \request()->uri() : (\request() && \request()->route && \request()->route->getPath() ? \request()->route->getPath() : '');
  75. $model->log_operation = $operation;
  76. $model->log_ip = \request() && \request()->getRealIp() ? \request()->getRealIp() : '0.0.0.0';
  77. $model->log_request_params = $requestParams ? json_encode($requestParams) : json_encode(\request()->all());
  78. $model->log_operation_data = $operationData ? json_encode($operationData) : null;
  79. $model->save();
  80. }
  81. }
  82. if (!function_exists('json_throw')) {
  83. function json_throw($code, $message, $data = '', $options = JSON_UNESCAPED_UNICODE)
  84. {
  85. $return = [
  86. 'code' => $code,
  87. 'message' => $message,
  88. 'data' => $data,
  89. ];
  90. return new \support\Response(200, ['Content-Type' => 'application/json'], json_encode($return, $options));
  91. }
  92. }