作者 lyh

gx

... ... @@ -48,337 +48,7 @@ class Demo extends Command
*/
protected $description = 'demo';
/**
* Create a new command instance.
*
* @return void
*/
// public function __construct()
// {
// parent::__construct();
// }
public function curlRequest($url, $data, $method = 'POST', $header = [], $time_out = 60)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if ($data)
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
'Expect:',
'Content-type: application/json',
'Accept: application/json',
], $header)
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [$code, $response];
}
/**
* @return bool
*/
// public function handle()
// {
// return $this->domain();
// $result = app(SyncService::class)->projectAcceptAddress(1);
// dd($result);
// $data = [
// 'key' => 'productkey_keyword',
// 'keywords' => 'apple watch'
// ];
// $result = Common::send_openai_msg('v2/openai_chat', $data);
// dd();
// $string = 'demo.globalso.site/';
// $domain_array = parse_url($string);
// $domain = $domain_array['host'] ?? $domain_array['path'];
// dd($domain);
// $data = [];
// dd(isset($data['a']['b']));
// $url = 'https://demo.globalso.site/';
// $action = 'api/updateHtmlNotify/';
// $data = [
// 'project_id' => 1,
// 'type' => 1,
// 'route' => 1
// ];;
// $method = 'GET';
// $result = $this->curlRequest($url . $action, $data, $method);
// dd($result);
//
// $context = stream_context_create([
// 'ssl' => [
// 'capture_peer_cert' => true,
// 'capture_peer_cert_chain' => false,
// ],
// ]);
//
// $stream = stream_socket_client('ssl://oa.quanqiusou.cn:443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
//
// if(!$stream) {
// die("Failed to connect: $errno - $errstr");
// }
//
// $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
//
// if(!$remote_cert) {
// die("Failed to retrieve certificate");
// }
//
// $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
// $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
//
// fclose($stream);
//
// echo "Certificate Valid From: $valid_from<br>";
// echo "Certificate Valid To: $valid_to<br>";
//
// dd('end');
// $dept_array = [
// '品牌部',
// '综合部',
// '渠道部',
// '广告推广部',
// 'AICC运营部',
// '黑格运营部',
// '直营运营部',
// '直营销售部',
// '深圳跨境部',
// '外贸部',
// '研发部',
// '技术部',
// '售后部',
// ];
// foreach ($dept_array as $v) {
// $dept = Dept::where(['title' => $v])->first();
// if (FALSE == empty($dept))
// continue;
// $dept = new Dept();
// $dept->title = $v;
// $dept->save();
// }
//// dd('dept end');
// $dept_map = Dept::pluck('title', 'id')->toArray();
// $belonging_map = BelongingGroup::pluck('name', 'id')->toArray();
//// dd($belonging_map);
//
// $filename = storage_path('logs/oa_hr.txt');
// $string = file_get_contents($filename);
// $data = explode("\r\n", $string);
// $data = array_filter($data);
// $dept = '';
// foreach ($data as $k=>$v) {
//// var_dump($v) . PHP_EOL;
// if ($k == 1)
// continue;
// $tmp = explode("\t", $v);
// if (count($tmp) == 3) {
// $dept = $tmp[0] ? : $dept;
// $position = $tmp[1];
// $name = $tmp[2];
// } else if (count($tmp) == 2) {
// $position = $tmp[0];
// $name = $tmp[1];
// } else {
// Log::info($v . PHP_EOL);
// continue;
// }
//
//
//// Log::info($dept . '---' . $position . '---' . $name . PHP_EOL);
//// continue;
//
// $dept_id = array_search($dept, $dept_map);
// $belonging_id = 17;
// if (FALSE !== strpos($dept,'技术部')) {
// $belonging_string = str_replace('技术部', '', $dept);
// if ($belonging_string) {
// $belonging_string = $belonging_string . '组';
// $belonging_id = array_search($belonging_string, $belonging_map);
// }
//
// $dept_tmp = '技术部';
// $dept_id = array_search($dept_tmp, $dept_map);
// }
// if (FALSE !== strpos($dept,'售后')) {
// $belonging_string = str_replace('售后', '', $dept);
// if ($belonging_string)
// $belonging_id = array_search($belonging_string, $belonging_map);
// $dept_tmp = '售后部';
// $dept_id = array_search($dept_tmp, $dept_map);
// }
//
// $position_log = EntryPosition::where(['name' => $position])->first();
// if (empty($position_log)) {
// $position_log = new EntryPosition();
// $position_log->name = $position;
// $position_log->save();
// }
// $position_id = $position_log->id;
//
// $hr = ManageHr::where(['name' => $name])->first();
// if (empty($hr)) {
// Log::info($k . '-' . $name . '-' . $dept . '-' . $dept_id . '-' . $position . '-' . $position_id);
// continue;
// }
//
// $hr->belong_group = $belonging_id;
// $hr->dept_id = $dept_id;
// $hr->entry_position = $position_id;
// $hr->save();
// echo $k . '-' . $name . '-' . $dept . '-' . $dept_id . '-' . $position . '-' . $position_id . '-' . '组' . '-' . $belonging_id . PHP_EOL;
//
// }
// dd('end');
// exit;
//
// if (($handle = fopen($filename, 'r')) !== false) {
// while (($data = fgetcsv($handle, 1000, ',')) !== false) {
// // 处理每行数据
// Log::info(var_export($data, true));
// }
// fclose($handle);
// }
// exit;
//
// $group = BelongingGroup::get();
// dd($group->toArray());
// $domain = parse_url('https//:dev.golbalso.site/');
// dd($domain);
// echo time() . PHP_EOL;
// $blogModel = new Image();
// $list = $blogModel->list();
// echo time() . PHP_EOL;
// dd(count($list));
//
// return;
// preg_match_all("/\@include\(\"([a-z0-9_]+)\"\)/i",'
//@include("asdf")@include("")@include("asdtrw2erf")
// ',$include);
//
// print_r($include);
// }
public function handle(){
$fileModel = new File();
$lists = $fileModel->list(['created_at'=>['>=','2024-04-12 00:00:00']]);
foreach ($lists as $k=> $v){
$str = './coscli cp cos://globalso-v6-1309677403'.$v['path'].' /home/cos/'.$v['path'];
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($str, true) . PHP_EOL, FILE_APPEND);
}
return true;
}
/**
* @remark :处理子集排序
* @name :subSort
* @author :lyh
* @method :post
* @time :2024/2/29 15:30
*/
public function subSort($subList,&$sort,$pid = 0){
$navModel = new BNav();
foreach ($subList as $k => $v){
$v = (array)$v;
$sort = $sort+1;
$navModel->edit(['sort'=>$sort],['id'=>$v['id']]);
if(!empty($v['sub'])){
$this->subSort($v['sub'],$sort,$v['id']);
}
}
return true;
}
// public function handle(){
// $projectModel = new DeployOptimize();
// $list = $projectModel->list(['project_id'=>['<',187]]);
// foreach ($list as $v){
// echo date('Y-m-d H:i:s') . 'end'.json_encode($v) . PHP_EOL;
// $data = [];
// if(!empty($v['minor_languages']) && is_array($v['minor_languages'])){
// foreach ($v['minor_languages'] as $k1=> $v1){
// if(!empty($v1['tl']) && !empty($v1['type'])){
// $data[] = [
// 'language'=>$v1['tl'],
// 'type'=>$v1['type'],
// 'keywords'=>$v1['keywords'],
// 'service_day'=>$v1['service_day'],
// 'project_id'=>$v['project_id'],
// 'created_at'=>date('Y-m-d H:i:s'),
// 'updated_at'=>date('Y-m-d H:i:s')
// ];
// }
// }
// }
// $languageModel = new MinorLanguages();
// $languageModel->insert($data);
// }
//
// }
public function printMessage()
{
$client = new Client();
$headers = [
'Accept-Language' => 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Cache-Control' => 'no-cache',
'Content-Type' => 'application/json',
'DNT' => '1',
'Origin' => 'http://openai.waimaoq.com',
'Pragma' => 'no-cache',
'Proxy-Connection' => 'keep-alive',
'Referer' => 'http://openai.waimaoq.com/docs',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
'accept' => 'application/json',
'Access-Control-Allow-Origin' => '*'
];
$body = '{
"prompt": "Human: 我需要一篇100字的英文原创博客并包含标题,内容结合:“cnc machine”。AI:"
}';
$response = $client->post('http://openai.waimaoq.com/v1/openai_chat_stream', [
'stream' => true,
'headers' => $headers,
'body' => $body
]);
// 获取响应流对象
$stream = $response->getBody();
// 设置输出缓冲区
ob_start();
// 读取流中的数据并输出到页面
while (!$stream->eof()) {
echo $stream->read(4);
ob_flush();
flush();
}
dd(1);
}
/**
* @remark :获取域名
* @name :domain
* @author :lyh
* @method :post
* @time :2023/11/29 18:47
*/
public function domain(){
$domainModel = new DomainInfo();
$lists = $domainModel->list();
foreach ($lists as $k => $v){
if($v['project_id'] != 0){
echo date('Y-m-d H:i:s') . ' start: ' . $v['project_id'] . PHP_EOL;
$domain = 'https://'.$v['domain'].'/';
$url = $domain.'/api/update_robots/?project_id='.$v['project_id'];
http_get($url);
echo date('Y-m-d H:i:s') . ' end: ' . $v['project_id'] . PHP_EOL;
}
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :EditVideoMp4.php
* @author :lyh
* @method :post
* @time :2024/4/16 9:44
*/
namespace App\Console\Commands\Test;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class EditVideoMp4 extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'edit_video';
/**
* The console command description.
*
* @var string
*/
protected $description = 'edit_mp4';
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>1]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->copyTable();
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :获取video的src
* @name :getVideoSrc
* @author :lyh
* @method :post
* @time :2024/4/16 9:46
*/
public function getVideoSrc($html){
$videoArr = [];
$html = file_get_contents($html);
$pattern = '/<video.*?src=[\'"]([^\'"]+)[\'"].*?>/i';
preg_match_all($pattern, $html, $matches);
$srcLinks = $matches[1];
foreach ($srcLinks as $link) {
$videoArr[] = $link;
}
return $videoArr;
}
/**
* @remark :复制表
* @name :copyTable
* @author :lyh
* @method :post
* @time :2024/4/16 9:51
*/
public function copyTable(){
// 原始表名和新表名
$originalTableName = "gl_web_template";
$newTableName = "gl_web_template_copy";
// 检查原始表是否存在
$result = DB::connection('custom_mysql')->query("SHOW TABLES LIKE '{$originalTableName}'");
if ($result->num_rows == 1) {
// 复制原始表结构到新表
DB::connection('custom_mysql')->query("CREATE TABLE {$newTableName} LIKE {$originalTableName}");
// 复制原始表数据到新表
DB::connection('custom_mysql')->query("INSERT INTO {$newTableName} SELECT * FROM {$originalTableName}");
echo "表复制成功!";
} else {
echo "原始表不存在!";
}
DB::connection('custom_mysql')->close();
}
}
... ...
... ... @@ -40,12 +40,10 @@ class ProjectServer
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
config(['database.connections.custom_mysql.username' => $project->mysqlConfig->user]);
config(['database.connections.custom_mysql.password' => $project->mysqlConfig->password]);
//清除现有的数据库连接配置
DB::purge('custom_mysql');
//重连
DB::connection('custom_mysql')->reconnect();
// 设置 redis 配置
return $project;
}
... ...