Zhouzhendong 4 жил өмнө
parent
commit
84c3d9255c

+ 90 - 3
app/Http/Controllers/TestController.php

@@ -100,6 +100,7 @@ use Laravel\Horizon\Events\JobFailed;
 use Monolog\Handler\IFTTTHandler;
 use phpDocumentor\Reflection\Types\Resource_;
 use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
+use Ramsey\Uuid\Uuid;
 use Symfony\Component\ErrorHandler\Error\FatalError;
 
 class TestController extends Controller
@@ -222,9 +223,25 @@ class TestController extends Controller
     }
     public function test()
     {
-        $package = OrderPackage::query()->find(17535630);
-        $line = 4;
-        dd($this->checkingAndProcess($package,$line));
+        $post = [
+            [
+                "taskMode"      => 2,
+                "bins"=>[
+                ],
+                "groupCode"     => 'g'.microtime(true),
+                "priority"      => 20,
+                "sequenceFlag"  => 1,
+            ]
+        ];
+        $post[0]['bins'][]=[
+            "taskCode"  =>Uuid::uuid4().'|'.microtime(true),
+            "binCode"   => "IDE0003571",
+            "fromLocCode" => "",
+            "toLocCode" => "BIN-OUT1",
+        ];
+        $response = Http::post(config('api.haiq.storage.moveBin'),$post);
+        $responseBody = $response->body();
+        dd($responseBody);
 
         $a = memory_get_usage();
         $tmp = str_repeat('http://blog.huachen.me/', 4000);
@@ -533,4 +550,74 @@ sql;
     {
         $this->dispatch(new SettlementBillReportJob('2021-08-01',[]));
     }
+    public function test2(){
+        $source_file ="E:\OneDrive\桌面\工作目录\文件库\\5.jpg";
+
+        $img = ImageCreateFromJpeg($source_file);
+        imagecolortransparent($img);//将某个颜色设置成透明色
+        imagecolorstotal($img);
+        header('Content-type:image/jpeg');
+        imagejpeg($img);
+        //dd($this->run('E:\OneDrive\桌面\工作目录\文件库\5.jpg', 'E:\OneDrive\桌面\工作目录\文件库\6.jpg'));
+    }
+
+
+    const FILE_NOT_FOUND = '-1';
+    const FILE_EXTNAME_ILLEGAL = '-2';
+
+    public function run($src1, $src2) {
+        if(!is_file($src1) || !is_file($src2)) exit(self::FILE_NOT_FOUND);
+        $hash1 = $this->getHashValue($src1);
+        $hash2 = $this->getHashValue($src2);
+        if(strlen($hash1) !== strlen($hash2)) return false;
+        $count = 0;
+        $len = strlen($hash1);
+        for($i = 0; $i < $len; $i++) if($hash1[$i] !== $hash2[$i]){
+            $count++;
+        }
+        dd($count);
+        return $count <= 10 ? true : false;
+    }
+
+    public function getImage($file) {
+        $extname = pathinfo($file, PATHINFO_EXTENSION);
+        if(!in_array($extname, ['jpg','jpeg','png','gif'])) exit(self::FILE_EXTNAME_ILLEGAL);
+        $img = call_user_func('imagecreatefrom'. ( $extname == 'jpg' ? 'jpeg' : $extname ) , $file);
+        return $img;
+    }
+    public function getHashValue($file) {
+        $w = 32;
+        $h = 32;
+        $img = imagecreatetruecolor($w, $h);
+        list($src_w, $src_h) = getimagesize($file);
+        $src = $this->getImage($file);
+        imagecopyresampled($img, $src, 0, 0, 0, 0, $w, $h, $src_w, $src_h);
+        imagedestroy($src);
+        $total = 0;
+        $array = array();
+        for( $y = 0; $y < $h; $y++) {
+            for ($x = 0; $x < $w; $x++) {
+                $rgb = imagecolorat($img, $x, $y);
+                $gray = $rgb & 0xFF;
+                /*dump([
+                    ($rgb >> 8) & 0xFF,
+                    ($rgb >> 16) & 0xFF,
+                    $rgb & 0xFF,
+                ]);*/
+                if(!isset($array[$y])) $array[$y] = array();
+                $array[$y][$x] = $gray;
+                $total += $gray;
+            }
+        }
+        imagedestroy($img);
+        $average = intval($total / ($w * $h * 2));
+        $hash = '';
+        for($y = 0; $y < $h; $y++) {
+            for($x = 0; $x < $w; $x++) {
+                $hash .= ($array[$y][$x] >= $average) ? '1' : '0';
+            }
+        }
+        dump($hash);
+        return $hash;
+    }
 }