12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?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')
- {
- $out = ['code' => $code, 'message' => $message, 'data' => $data];
- return response()->json($out);
- }
- }
- //统一异常输出格式话的json数据
- if (!function_exists('exit_out')) {
- function exit_out($data = null, $code = 500, $message = 'fail')
- {
- $out = ['code' => $code, 'message' => $message, 'data' => $data];
- $message = json_encode($out, JSON_UNESCAPED_UNICODE);
- throw new ExitOutException($message);
- }
- }
- //日志记录
- 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);
- }
- }
|