正在显示
10 个修改的文件
包含
258 行增加
和
121 行删除
app/Helper/common.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | -use Illuminate\Support\Facades\Log; | ||
| 3 | - | ||
| 4 | -define('HTTP_OPENAI_URL','http://openai.waimaoq.com'); | ||
| 5 | - | ||
| 6 | -//ai自动生成文本 | ||
| 7 | -function send_openai_msg($url , $command , $param){ | ||
| 8 | - $url = HTTP_OPENAI_URL.$url; | ||
| 9 | - $data = [ | ||
| 10 | - 'messages'=>[ | ||
| 11 | - ['role'=>$command['key'],'content'=>$command['scene']], | ||
| 12 | - ['role'=>$param['key'],'content'=>$param['scene']], | ||
| 13 | - ] | ||
| 14 | - ]; | ||
| 15 | - return http_post($url,json_encode($data)); | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -if(!function_exists('http_post')){ | ||
| 19 | - /** | ||
| 20 | - * 发送http post请求 | ||
| 21 | - * @param type $url | ||
| 22 | - * @param type $post_data | ||
| 23 | - */ | ||
| 24 | - function http_post($url, $post_data) | ||
| 25 | - { | ||
| 26 | - $header[] = "charset = UTF-8"; | ||
| 27 | - $ch = curl_init(); | ||
| 28 | - curl_setopt($ch, CURLOPT_URL, $url); | ||
| 29 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | ||
| 30 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
| 31 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | ||
| 32 | - curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | ||
| 33 | - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); | ||
| 34 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | ||
| 35 | - curl_setopt($ch, CURLOPT_AUTOREFERER, 1); | ||
| 36 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); | ||
| 37 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| 38 | - $res = curl_exec($ch); | ||
| 39 | - if (curl_errno($ch)) { | ||
| 40 | - Log::write(print_r(curl_errno($ch),1),'debug---1'); | ||
| 41 | - } | ||
| 42 | - curl_close($ch); | ||
| 43 | - return json_decode($res, true); | ||
| 44 | - } | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | -if(!function_exists('http_get')){ | ||
| 48 | - /** | ||
| 49 | - * 发送http get请求 | ||
| 50 | - * @param type $url | ||
| 51 | - * @return type | ||
| 52 | - */ | ||
| 53 | - function http_get($url) | ||
| 54 | - { | ||
| 55 | - $header[] = "content-type: application/x-www-form-urlencoded; | ||
| 56 | - charset = UTF-8"; | ||
| 57 | - $ch1 = curl_init(); | ||
| 58 | - $timeout = 5; | ||
| 59 | - curl_setopt($ch1, CURLOPT_URL, $url); | ||
| 60 | - curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); | ||
| 61 | - curl_setopt($ch1, CURLOPT_HTTPHEADER, $header); | ||
| 62 | - curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout); | ||
| 63 | - curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false); | ||
| 64 | - curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false); | ||
| 65 | - $access_txt = curl_exec($ch1); | ||
| 66 | - curl_close($ch1); | ||
| 67 | - return json_decode($access_txt, true); | ||
| 68 | - } | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | - | ||
| 72 | -if(!function_exists('_get_child')){ | ||
| 73 | - /** | ||
| 74 | - * 菜单权限->得到子级数组 | ||
| 75 | - * @param int | ||
| 76 | - * @return array | ||
| 77 | - */ | ||
| 78 | - function _get_child($my_id, $arr) | ||
| 79 | - { | ||
| 80 | - $new_arr = array(); | ||
| 81 | - foreach ($arr as $k => $v) { | ||
| 82 | - $v = (array)$v; | ||
| 83 | - if ($v['pid'] == $my_id) { | ||
| 84 | - $v['sub'] = _get_child($v['id'],$arr); | ||
| 85 | - $new_arr[] = $v; | ||
| 86 | - } | ||
| 87 | - } | ||
| 88 | - return $new_arr ? $new_arr : false; | ||
| 89 | - } | ||
| 90 | -} | ||
| 91 | - |
| 1 | <?php | 1 | <?php |
| 2 | - | 2 | +define('HTTP_OPENAI_URL','http://openai.waimaoq.com/'); |
| 3 | /** | 3 | /** |
| 4 | * 生成路由标识 | 4 | * 生成路由标识 |
| 5 | * @param $string | 5 | * @param $string |
| @@ -10,3 +10,81 @@ | @@ -10,3 +10,81 @@ | ||
| 10 | function generateRoute($string){ | 10 | function generateRoute($string){ |
| 11 | return trim(strtolower(preg_replace( '/[\W]+/', '-', trim($string))), '-'); | 11 | return trim(strtolower(preg_replace( '/[\W]+/', '-', trim($string))), '-'); |
| 12 | } | 12 | } |
| 13 | + | ||
| 14 | + | ||
| 15 | +if(!function_exists('http_post')){ | ||
| 16 | + /** | ||
| 17 | + * 发送http post请求 | ||
| 18 | + * @param type $url | ||
| 19 | + * @param type $post_data | ||
| 20 | + */ | ||
| 21 | + function http_post($url, $post_data) | ||
| 22 | + { | ||
| 23 | + $header = array( | ||
| 24 | + "Accept: application/json", | ||
| 25 | + "Content-Type:application/json;charset=utf-8", | ||
| 26 | + ); | ||
| 27 | + $ch = curl_init(); | ||
| 28 | + curl_setopt($ch, CURLOPT_URL, $url); | ||
| 29 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | ||
| 30 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
| 31 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | ||
| 32 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | ||
| 33 | + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); | ||
| 34 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | ||
| 35 | + curl_setopt($ch, CURLOPT_AUTOREFERER, 1); | ||
| 36 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); | ||
| 37 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| 38 | + $res = curl_exec($ch); | ||
| 39 | + if (curl_errno($ch)) { | ||
| 40 | + Log::write(print_r(curl_errno($ch),1),'debug---1'); | ||
| 41 | + } | ||
| 42 | + curl_close($ch); | ||
| 43 | + return json_decode($res, true); | ||
| 44 | + } | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +if(!function_exists('http_get')){ | ||
| 48 | + /** | ||
| 49 | + * 发送http get请求 | ||
| 50 | + * @param type $url | ||
| 51 | + * @return type | ||
| 52 | + */ | ||
| 53 | + function http_get($url) | ||
| 54 | + { | ||
| 55 | + $header[] = "content-type: application/x-www-form-urlencoded; | ||
| 56 | + charset = UTF-8"; | ||
| 57 | + $ch1 = curl_init(); | ||
| 58 | + $timeout = 5; | ||
| 59 | + curl_setopt($ch1, CURLOPT_URL, $url); | ||
| 60 | + curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); | ||
| 61 | + curl_setopt($ch1, CURLOPT_HTTPHEADER, $header); | ||
| 62 | + curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout); | ||
| 63 | + curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false); | ||
| 64 | + curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false); | ||
| 65 | + $access_txt = curl_exec($ch1); | ||
| 66 | + curl_close($ch1); | ||
| 67 | + return json_decode($access_txt, true); | ||
| 68 | + } | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | + | ||
| 72 | +if(!function_exists('_get_child')){ | ||
| 73 | + /** | ||
| 74 | + * 菜单权限->得到子级数组 | ||
| 75 | + * @param int | ||
| 76 | + * @return array | ||
| 77 | + */ | ||
| 78 | + function _get_child($my_id, $arr) | ||
| 79 | + { | ||
| 80 | + $new_arr = array(); | ||
| 81 | + foreach ($arr as $k => $v) { | ||
| 82 | + $v = (array)$v; | ||
| 83 | + if ($v['pid'] == $my_id) { | ||
| 84 | + $v['sub'] = _get_child($v['id'],$arr); | ||
| 85 | + $new_arr[] = $v; | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + return $new_arr ? $new_arr : false; | ||
| 89 | + } | ||
| 90 | +} |
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | -namespace App\Http\Controllers\Bside; | 3 | +namespace App\Http\Controllers\Aside; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | +use App\Http\Controllers\Aside\BaseController; | ||
| 7 | +use App\Models\AiCommand as AiCommandModel; | ||
| 8 | +use function App\Helper\send_openai_msg; | ||
| 6 | 9 | ||
| 7 | class AiCommandController extends BaseController | 10 | class AiCommandController extends BaseController |
| 8 | { | 11 | { |
| @@ -12,12 +15,9 @@ class AiCommandController extends BaseController | @@ -12,12 +15,9 @@ class AiCommandController extends BaseController | ||
| 12 | * @author :liyuhang | 15 | * @author :liyuhang |
| 13 | * @method | 16 | * @method |
| 14 | */ | 17 | */ |
| 15 | - public function lists(){ | ||
| 16 | - $url = 'v2/openai_chat'; | ||
| 17 | - $command = ['key'=>'user','scene'=>'system']; | ||
| 18 | - $param = ['key'=>'user','scene'=>'请问你是谁?']; | ||
| 19 | - $data = send_openai_msg($url,$command,$param); | ||
| 20 | - $this->response('success',Code::SUCCESS,$data); | 18 | + public function lists(AiCommandModel $aiCommandModel){ |
| 19 | + $lists = $aiCommandModel->lists($this->map,); | ||
| 20 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; | @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; | ||
| 7 | use Illuminate\Http\JsonResponse; | 7 | use Illuminate\Http\JsonResponse; |
| 8 | use Illuminate\Http\Request; | 8 | use Illuminate\Http\Request; |
| 9 | use Illuminate\Http\Exceptions\HttpResponseException; | 9 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 10 | +use Illuminate\Support\Facades\Cache; | ||
| 10 | use Illuminate\Support\Facades\Session; | 11 | use Illuminate\Support\Facades\Session; |
| 11 | 12 | ||
| 12 | class BaseController extends Controller | 13 | class BaseController extends Controller |
| @@ -14,7 +15,6 @@ class BaseController extends Controller | @@ -14,7 +15,6 @@ class BaseController extends Controller | ||
| 14 | protected $param = [];//所有请求参数 | 15 | protected $param = [];//所有请求参数 |
| 15 | protected $token = ''; //token | 16 | protected $token = ''; //token |
| 16 | protected $request = [];//助手函数 | 17 | protected $request = [];//助手函数 |
| 17 | - protected $allCount = 0;//总条数 | ||
| 18 | protected $page = 1;//当前页 | 18 | protected $page = 1;//当前页 |
| 19 | protected $row = 20;//每页条数 | 19 | protected $row = 20;//每页条数 |
| 20 | protected $header = [];//设置请求头参数 | 20 | protected $header = [];//设置请求头参数 |
| @@ -22,7 +22,6 @@ class BaseController extends Controller | @@ -22,7 +22,6 @@ class BaseController extends Controller | ||
| 22 | protected $map = [];//处理后的参数 | 22 | protected $map = [];//处理后的参数 |
| 23 | protected $uid = 0; | 23 | protected $uid = 0; |
| 24 | protected $user = [];//当前登录用户详情 | 24 | protected $user = [];//当前登录用户详情 |
| 25 | - | ||
| 26 | /** | 25 | /** |
| 27 | * 获取所有参数 | 26 | * 获取所有参数 |
| 28 | */ | 27 | */ |
| @@ -30,24 +29,24 @@ class BaseController extends Controller | @@ -30,24 +29,24 @@ class BaseController extends Controller | ||
| 30 | { | 29 | { |
| 31 | $this->request = $request; | 30 | $this->request = $request; |
| 32 | $this->param = $this->request->all(); | 31 | $this->param = $this->request->all(); |
| 32 | + $this->token = $this->request->header('token'); | ||
| 33 | + if(!empty($this->token) && !empty(Cache::get($this->token))){ | ||
| 34 | + $info = Cache::get($this->token); | ||
| 35 | + $this->user = $info; | ||
| 36 | + $this->uid = $info['id']; | ||
| 37 | + }else{ | ||
| 38 | + return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); | ||
| 39 | + } | ||
| 33 | $this->get_param(); | 40 | $this->get_param(); |
| 34 | } | 41 | } |
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * @return mixed | ||
| 38 | - * @author zbj | ||
| 39 | - * @date 2023/4/19 | ||
| 40 | - */ | ||
| 41 | - public function manage(){ | ||
| 42 | - return Session::get('manage'); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | /** | 42 | /** |
| 46 | * 成功返回 | 43 | * 成功返回 |
| 47 | * @param array $data | 44 | * @param array $data |
| 48 | * @param string $code | 45 | * @param string $code |
| 49 | * @param bool $objectData | 46 | * @param bool $objectData |
| 50 | * @return JsonResponse | 47 | * @return JsonResponse |
| 48 | + * @throws \Psr\Container\ContainerExceptionInterface | ||
| 49 | + * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 51 | */ | 50 | */ |
| 52 | function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse | 51 | function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse |
| 53 | { | 52 | { |
| @@ -60,6 +59,7 @@ class BaseController extends Controller | @@ -60,6 +59,7 @@ class BaseController extends Controller | ||
| 60 | 'data' => $data, | 59 | 'data' => $data, |
| 61 | 'msg' => $code->description, | 60 | 'msg' => $code->description, |
| 62 | ]; | 61 | ]; |
| 62 | + $this->header['token'] = $this->token; | ||
| 63 | return response()->json($response,200,$this->header); | 63 | return response()->json($response,200,$this->header); |
| 64 | } | 64 | } |
| 65 | /** | 65 | /** |
| @@ -116,11 +116,53 @@ class BaseController extends Controller | @@ -116,11 +116,53 @@ class BaseController extends Controller | ||
| 116 | $result = [ | 116 | $result = [ |
| 117 | 'msg' => $msg == ' ' ? $code->description : $msg, | 117 | 'msg' => $msg == ' ' ? $code->description : $msg, |
| 118 | 'code' => $code->value, | 118 | 'code' => $code->value, |
| 119 | - 'data' => $data, | 119 | + 'data' => $this->_extents($data), |
| 120 | ]; | 120 | ]; |
| 121 | $this->header['Content-Type'] = $type; | 121 | $this->header['Content-Type'] = $type; |
| 122 | $this->header['token'] = $this->token; | 122 | $this->header['token'] = $this->token; |
| 123 | $response = response($result,$result_code,$this->header);; | 123 | $response = response($result,$result_code,$this->header);; |
| 124 | throw new HttpResponseException($response); | 124 | throw new HttpResponseException($response); |
| 125 | } | 125 | } |
| 126 | + | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * 菜单权限->得到子级数组 | ||
| 130 | + * @param int | ||
| 131 | + * @return array | ||
| 132 | + */ | ||
| 133 | + public function _get_child($my_id, $arr) | ||
| 134 | + { | ||
| 135 | + $new_arr = array(); | ||
| 136 | + foreach ($arr as $k => $v) { | ||
| 137 | + $v = (array)$v; | ||
| 138 | + if ($v['pid'] == $my_id) { | ||
| 139 | + $v['sub'] = $this->_get_child($v['id'],$arr); | ||
| 140 | + $new_arr[] = $v; | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + return $new_arr ? $new_arr : false; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + protected function _extents($data) { | ||
| 147 | + | ||
| 148 | + if (empty($data) || !is_array($data)) { | ||
| 149 | + return empty($data) ? is_array($data) ? [] : '' : $data; | ||
| 150 | + } | ||
| 151 | + foreach ($data as $k => $v) { | ||
| 152 | + if (is_array($v)) { | ||
| 153 | + $data[$k] = $this->_extents($v); | ||
| 154 | + } else { | ||
| 155 | + if (is_null($v)) { | ||
| 156 | + $data[$k] = ''; | ||
| 157 | + continue; | ||
| 158 | + } | ||
| 159 | + switch ((string) $k) { | ||
| 160 | + case 'image': | ||
| 161 | + $v['image_link'] = file_get_contents($v); | ||
| 162 | + break; | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | + return $data; | ||
| 167 | + } | ||
| 126 | } | 168 | } |
| @@ -4,12 +4,11 @@ namespace App\Http\Controllers\Bside; | @@ -4,12 +4,11 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Controller; | 6 | use App\Http\Controllers\Controller; |
| 7 | -use App\Utils\EncryptUtils; | 7 | +use App\Models\AiCommand as AiCommandModel; |
| 8 | use Illuminate\Http\JsonResponse; | 8 | use Illuminate\Http\JsonResponse; |
| 9 | use Illuminate\Http\Request; | 9 | use Illuminate\Http\Request; |
| 10 | use Illuminate\Http\Exceptions\HttpResponseException; | 10 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 11 | use Illuminate\Support\Facades\Cache; | 11 | use Illuminate\Support\Facades\Cache; |
| 12 | -use Illuminate\Support\Facades\Log; | ||
| 13 | 12 | ||
| 14 | class BaseController extends Controller | 13 | class BaseController extends Controller |
| 15 | { | 14 | { |
| @@ -166,4 +165,29 @@ class BaseController extends Controller | @@ -166,4 +165,29 @@ class BaseController extends Controller | ||
| 166 | } | 165 | } |
| 167 | return $data; | 166 | return $data; |
| 168 | } | 167 | } |
| 168 | + | ||
| 169 | + /** | ||
| 170 | + * @name :ai自动生成 | ||
| 171 | + * @return mixed | ||
| 172 | + * @author :liyuhang | ||
| 173 | + * @method | ||
| 174 | + */ | ||
| 175 | + public function send_openai_msg($url , $key){ | ||
| 176 | + $url = HTTP_OPENAI_URL.$url; | ||
| 177 | + $aiCommandModel = New AiCommandModel(); | ||
| 178 | + //指定库获取指令 | ||
| 179 | + $info = $aiCommandModel->read(['key'=>$key]); | ||
| 180 | + if($info === false){ | ||
| 181 | + $this->response('error',Code::USER_ERROR); | ||
| 182 | + } | ||
| 183 | + //替换关键字 | ||
| 184 | + $content = str_replace('$keyword$', $this->param['keywords'], $info['ai']); | ||
| 185 | + $data = [ | ||
| 186 | + 'messages'=>[ | ||
| 187 | + ['role'=>'system','content'=>$info['scene']], | ||
| 188 | + ['role'=>'assistant','content'=>$content], | ||
| 189 | + ] | ||
| 190 | + ]; | ||
| 191 | + return http_post($url,json_encode($data)); | ||
| 192 | + } | ||
| 169 | } | 193 | } |
| @@ -112,4 +112,43 @@ class BlogController extends BaseController | @@ -112,4 +112,43 @@ class BlogController extends BaseController | ||
| 112 | $blogLogic->blog_del(); | 112 | $blogLogic->blog_del(); |
| 113 | $this->response('success'); | 113 | $this->response('success'); |
| 114 | } | 114 | } |
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * @name :ai生成名称 | ||
| 118 | + * @return void | ||
| 119 | + * @author :liyuhang | ||
| 120 | + * @method | ||
| 121 | + */ | ||
| 122 | + public function ai_blog_name(Request $request){ | ||
| 123 | + # id, key, scene, ai | ||
| 124 | + $request->validate([ | ||
| 125 | + 'keywords'=>['required'], | ||
| 126 | + ],[ | ||
| 127 | + 'keywords.required' => '关键字不能为空', | ||
| 128 | + ]); | ||
| 129 | + $key = 'blog_title'; | ||
| 130 | + #TODO 通过key获取到ai指令对象 | ||
| 131 | + $url = 'v2/openai_chat'; | ||
| 132 | + $data = $this->send_openai_msg($url,$key); | ||
| 133 | + $this->response('success',Code::SUCCESS,$data); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + /** | ||
| 137 | + * @name :ai生成内容 | ||
| 138 | + * @return void | ||
| 139 | + * @author :liyuhang | ||
| 140 | + * @method | ||
| 141 | + */ | ||
| 142 | + public function ai_blog_content(Request $request){ | ||
| 143 | + $request->validate([ | ||
| 144 | + 'keywords'=>['required'], | ||
| 145 | + ],[ | ||
| 146 | + 'keywords.required' => '关键字不能为空', | ||
| 147 | + ]); | ||
| 148 | + $key = 'blog_content'; | ||
| 149 | + #TODO 通过key获取到ai指令对象 | ||
| 150 | + $url = 'v2/openai_chat'; | ||
| 151 | + $data = $this->send_openai_msg($url,$key); | ||
| 152 | + $this->response('success',Code::SUCCESS,$data); | ||
| 153 | + } | ||
| 115 | } | 154 | } |
| @@ -5,12 +5,9 @@ namespace App\Http\Controllers\Bside\News; | @@ -5,12 +5,9 @@ namespace App\Http\Controllers\Bside\News; | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Bside\BaseController; | 6 | use App\Http\Controllers\Bside\BaseController; |
| 7 | use App\Http\Logic\Bside\News\NewsCategoryLogic; | 7 | use App\Http\Logic\Bside\News\NewsCategoryLogic; |
| 8 | -use App\Http\Logic\Bside\News\NewsLogic; | ||
| 9 | use App\Http\Requests\Bside\News\NewsCategoryRequest; | 8 | use App\Http\Requests\Bside\News\NewsCategoryRequest; |
| 10 | -use App\Models\News\News as NewsModel; | ||
| 11 | use App\Models\News\NewsCategory as NewsCategoryModel; | 9 | use App\Models\News\NewsCategory as NewsCategoryModel; |
| 12 | use Illuminate\Http\Request; | 10 | use Illuminate\Http\Request; |
| 13 | -use Illuminate\Support\Facades\DB; | ||
| 14 | 11 | ||
| 15 | class NewsCategoryController extends BaseController | 12 | class NewsCategoryController extends BaseController |
| 16 | { | 13 | { |
| @@ -103,4 +100,5 @@ class NewsCategoryController extends BaseController | @@ -103,4 +100,5 @@ class NewsCategoryController extends BaseController | ||
| 103 | $newsCategoryLogic->del_news_category(); | 100 | $newsCategoryLogic->del_news_category(); |
| 104 | $this->response('success'); | 101 | $this->response('success'); |
| 105 | } | 102 | } |
| 103 | + | ||
| 106 | } | 104 | } |
| @@ -7,7 +7,6 @@ use App\Http\Controllers\Bside\BaseController; | @@ -7,7 +7,6 @@ use App\Http\Controllers\Bside\BaseController; | ||
| 7 | use App\Http\Logic\Bside\News\NewsLogic; | 7 | use App\Http\Logic\Bside\News\NewsLogic; |
| 8 | use App\Http\Requests\Bside\News\NewsRequest; | 8 | use App\Http\Requests\Bside\News\NewsRequest; |
| 9 | use App\Models\News\News as NewsModel; | 9 | use App\Models\News\News as NewsModel; |
| 10 | -use App\Models\News\NewsCategory as NewsCategoryModel; | ||
| 11 | use Illuminate\Http\Request; | 10 | use Illuminate\Http\Request; |
| 12 | 11 | ||
| 13 | /** | 12 | /** |
| @@ -115,4 +114,43 @@ class NewsController extends BaseController | @@ -115,4 +114,43 @@ class NewsController extends BaseController | ||
| 115 | //TODO::清空相关资源/写入日志 | 114 | //TODO::清空相关资源/写入日志 |
| 116 | $this->response('success'); | 115 | $this->response('success'); |
| 117 | } | 116 | } |
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * @name :ai生成名称 | ||
| 120 | + * @return void | ||
| 121 | + * @author :liyuhang | ||
| 122 | + * @method | ||
| 123 | + */ | ||
| 124 | + public function ai_news_name(Request $request){ | ||
| 125 | + # id, key, scene, ai | ||
| 126 | + $request->validate([ | ||
| 127 | + 'keywords'=>['required'], | ||
| 128 | + ],[ | ||
| 129 | + 'keywords.required' => '关键字不能为空', | ||
| 130 | + ]); | ||
| 131 | + $key = 'new_title'; | ||
| 132 | + #TODO 通过key获取到ai指令对象 | ||
| 133 | + $url = 'v2/openai_chat'; | ||
| 134 | + $data = $this->send_openai_msg($url,$key); | ||
| 135 | + $this->response('success',Code::SUCCESS,$data); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * @name :ai生成内容 | ||
| 140 | + * @return void | ||
| 141 | + * @author :liyuhang | ||
| 142 | + * @method | ||
| 143 | + */ | ||
| 144 | + public function ai_news_content(Request $request){ | ||
| 145 | + $request->validate([ | ||
| 146 | + 'keywords'=>['required'], | ||
| 147 | + ],[ | ||
| 148 | + 'keywords.required' => '关键字不能为空', | ||
| 149 | + ]); | ||
| 150 | + $key = 'new_content'; | ||
| 151 | + #TODO 通过key获取到ai指令对象 | ||
| 152 | + $url = 'v2/openai_chat'; | ||
| 153 | + $data = $this->send_openai_msg($url,$key); | ||
| 154 | + $this->response('success',Code::SUCCESS,$data); | ||
| 155 | + } | ||
| 118 | } | 156 | } |
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | -namespace App\Http\Logic\Bside; | 3 | +namespace App\Http\Logic\Aside; |
| 4 | + | ||
| 5 | +use App\Http\Logic\Aside\BaseLogic; | ||
| 6 | +use App\Models\AiCommand as AiCommandModel; | ||
| 4 | 7 | ||
| 5 | class AiCommandLogic extends BaseLogic | 8 | class AiCommandLogic extends BaseLogic |
| 6 | { | 9 | { |
| @@ -8,6 +11,7 @@ class AiCommandLogic extends BaseLogic | @@ -8,6 +11,7 @@ class AiCommandLogic extends BaseLogic | ||
| 8 | { | 11 | { |
| 9 | parent::__construct(); | 12 | parent::__construct(); |
| 10 | 13 | ||
| 11 | - $this->model = new Department(); | 14 | + $this->model = new AiCommandModel(); |
| 12 | } | 15 | } |
| 16 | + | ||
| 13 | } | 17 | } |
| @@ -85,7 +85,12 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -85,7 +85,12 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 85 | }); | 85 | }); |
| 86 | //ai指令 | 86 | //ai指令 |
| 87 | Route::prefix('command')->group(function () { | 87 | Route::prefix('command')->group(function () { |
| 88 | - Route::any('/', [\App\Http\Controllers\Bside\AiCommandController::class, 'lists'])->name('command_lists'); | 88 | + //新闻自动生成 |
| 89 | + Route::any('/ai_news_name', [\App\Http\Controllers\Bside\News\NewsController::class, 'ai_news_name'])->name('ai_news_name'); | ||
| 90 | + Route::any('/ai_news_content', [\App\Http\Controllers\Bside\News\NewsController::class, 'ai_news_content'])->name('ai_news_content'); | ||
| 91 | + //博客自动生成 | ||
| 92 | + Route::any('/ai_blog_name', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'ai_blog_name'])->name('ai_blog_name'); | ||
| 93 | + Route::any('/ai_blog_content', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'ai_blog_content'])->name('ai_blog_content'); | ||
| 89 | }); | 94 | }); |
| 90 | 95 | ||
| 91 | //产品 | 96 | //产品 |
-
请 注册 或 登录 后发表评论