Code Duplication    Length = 24-24 lines in 2 locations

src/Api.php 1 location

@@ 618-641 (lines=24) @@
615
     *
616
     * @return string
617
     */
618
    public static function encrypt($data, $key, $expire = 0)
619
    {
620
        $data = base64_encode($data);
621
        $x    = 0;
622
        $len  = strlen($data);
623
        $l    = strlen($key);
624
        $char = '';
625
626
        for ($i = 0; $i < $len; $i++) {
627
            if ($x == $l) {
628
                $x = 0;
629
            }
630
            $char .= substr($key, $x, 1);
631
            $x++;
632
        }
633
634
        $str = sprintf('%010d', $expire ? $expire + time() : 0);
635
636
        for ($i = 0; $i < $len; $i++) {
637
            $str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256);
638
        }
639
640
        return rawurlencode(str_replace('=', '', base64_encode($str)));
641
    }
642
643
    /**
644
     * 解析头信息

src/ComponentApi.php 1 location

@@ 504-527 (lines=24) @@
501
     *
502
     * @return string
503
     */
504
    public static function encrypt($data, $key, $expire = 0)
505
    {
506
        $data = base64_encode($data);
507
        $x    = 0;
508
        $len  = strlen($data);
509
        $l    = strlen($key);
510
        $char = '';
511
512
        for ($i = 0; $i < $len; $i++) {
513
            if ($x == $l) {
514
                $x = 0;
515
            }
516
            $char .= substr($key, $x, 1);
517
            $x++;
518
        }
519
520
        $str = sprintf('%010d', $expire ? $expire + time() : 0);
521
522
        for ($i = 0; $i < $len; $i++) {
523
            $str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256);
524
        }
525
526
        return rawurlencode(str_replace('=', '', base64_encode($str)));
527
    }
528
529
    /**
530
     * 解析头信息