| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 | <?php/** * Here is your custom functions. */if (!function_exists('http_post')) {    function http_post($url, $params)    {        $ch = curl_init();        $this_header = array("content-type: application/x-www-form-urlencoded;charset=UTF-8");        curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');        curl_setopt($ch, CURLOPT_TIMEOUT, 30);        curl_setopt($ch, CURLOPT_POST, 1);        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//如果不加验证,就设false,商户自行处理        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);        $output = curl_exec($ch);        curl_close($ch);        return $output;    }}if (!function_exists('http_post_json')) {    function http_post_json($url, $params)    {        try {            $ch = curl_init();            $this_header = array('Content-Type: application/json;charset=UTF-8');            curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);            curl_setopt($ch, CURLOPT_URL, $url);            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');            curl_setopt($ch, CURLOPT_TIMEOUT, 30);            curl_setopt($ch, CURLOPT_POST, 1);            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//如果不加验证,就设false,商户自行处理            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);            $output = curl_exec($ch);            curl_close($ch);            // 写日志            if (is_json($output)) {                \support\Log::info('模拟请求:', json_decode($output, true));            } else {                \support\Log::info('模拟请求,返回异常:', ['msg' => (string)$output]);            }            return $output;        } catch (\Exception $e) {            \support\Log::info('模拟请求失败:', ['msg' => $e->getMessage()]);        }    }}if (!function_exists('month_12')) {    function month_12()    {        $months = [];        for ($i = 0; $i < 12; $i++) {            $months[$i] = date('Y/m', strtotime(date('Y-m-01') . "-" . $i . "month"));        }        return $months;    }}/** * @Desc 管理员操作日志 * @Author Gorden * @Date 2024/3/29 17:07 * *  adminId = 1001 计划任务 * * * @param $name * @param $operation * @return void */if (!function_exists('_syslog')) {    function _syslog($name, $operation, $operationData = false, $requestParams = false, $adminId = false)    {        try {            $adminId = $adminId ? $adminId : \Tinywan\Jwt\JwtToken::getCurrentId();        } catch (\Exception $e) {            $adminId = 1001;        }        $logAdminId = $adminId;        $model = new \app\model\SysLog();        $model->log_admin_id = $logAdminId;        $model->log_name = $name;        $model->log_route = \request() && \request()->uri() ? \request()->uri() : (\request() && \request()->route && \request()->route->getPath() ? \request()->route->getPath() : '');        $model->log_operation = $operation;        $model->log_ip = \request() && \request()->getRealIp() ? \request()->getRealIp() : '0.0.0.0';        $model->log_request_params = $requestParams ? json_encode($requestParams) : ($adminId == 1001 ? '[]' : json_encode(\request()->all()));        $model->log_operation_data = $operationData ? json_encode($operationData) : null;        $model->save();    }}if (!function_exists('json_throw')) {    function json_throw($code, $message, $data = '', $options = JSON_UNESCAPED_UNICODE)    {        $return = [            'code' => $code,            'message' => $message,            'data' => $data,        ];        return new \support\Response(200, ['Content-Type' => 'application/json'], json_encode($return, $options));    }}
 |