123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-9-23
- * Time: 上午10:56
- */
- use Illuminate\Support\Facades\Log;
- use App\Exceptions\ExitOutException;
- //统一输出格式话的json数据
- if (!function_exists('out')) {
- function out($data = null, $code = 200, $message = 'success', $exceptionData = false)
- {
- $out = ['code' => $code, 'message' => $message, 'data' => $data];
- if ($exceptionData !== false) {
- trace([$message => $exceptionData], 'error');
- }
- return response()->json($out);
- }
- }
- //统一异常输出格式话的json数据
- if (!function_exists('exit_out')) {
- function exit_out($data = null, $code = 200, $message = 'success', $exceptionData = false)
- {
- $out = ['code' => $code, 'message' => $message, 'data' => $data];
- if ($exceptionData !== false) {
- trace([$message => $exceptionData], 'error');
- }
- $json = json_encode($out, JSON_UNESCAPED_UNICODE);
- throw new ExitOutException($json);
- }
- }
- //日志记录
- if (!function_exists('trace')) {
- function trace($log = '', $level = 'info')
- {
- Log::log($level, $log);
- }
- }
- //AES加密
- if (!function_exists('aes_encrypt')) {
- function aes_encrypt($data)
- {
- if (is_array($data)) {
- $data = json_encode($data, JSON_UNESCAPED_UNICODE);
- }
- $key = config('config.aes_key');
- $iv = config('config.aes_iv');
- $cipher_text = openssl_encrypt($data, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
- $cipher_text = base64_encode($cipher_text);
- return urlencode($cipher_text);
- }
- }
- //AES解密
- if (!function_exists('aes_decrypt')) {
- function aes_decrypt($encryptData)
- {
- $encryptData = urldecode($encryptData);
- $encryptData = base64_decode($encryptData);
- $key = config('config.aes_key');
- $iv = config('config.aes_iv');
- $original_plaintext = openssl_decrypt($encryptData, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
- return json_decode($original_plaintext, true);
- }
- }
|