· 5 years ago · Dec 08, 2020, 05:50 PM
1<?php
2
3class rc4crypt
4{
5 const KEY = '$KEY.IT$DflqgxTrwn8E7e8Ctcvw.YMmb1';
6 public $data;
7
8 /
9 * rc4crypt constructor.
10 * @param $data
11 */
12 public function __construct($data)
13 {
14 $this->data = $data;
15
16 }
17
18 /
19 * @return false|string
20 */
21 private function preEncrypt()
22 {
23 if (is_string($this->data)) {
24
25 $this->data = pack("H*", $this->data);
26 }
27 return $this->data;
28 }
29
30 /
31 * @return array|mixed
32 */
33 public function result()
34 {
35 $this->preEncrypt();
36 if (!is_array($this->data))
37 return $this->encrypt();
38 return $this->data;
39 }
40
41 /
42 * @return mixed
43 */
44 private function encrypt()
45 {
46 $key[] = '';
47 $box[] = '';
48 $pwd_length = strlen(self::KEY);
49 $data_length = strlen($this->data);
50 for ($i = 0; $i < 256; $i++) {
51 $key[$i] = ord(self::KEY[$i % $pwd_length]);
52 $box[$i] = $i;
53 }
54 for ($j = $i = 0; $i < 256; $i++) {
55 $j = ($j + $box[$i] + $key[$i]) % 256;
56 $tmp = $box[$i];
57 $box[$i] = $box[$j];
58 $box[$j] = $tmp;
59 }
60 $cipher = '';
61 for ($a = $j = $i = 0; $i < $data_length; $i++) {
62 $a = ($a + 1) % 256;
63 $j = ($j + $box[$a]) % 256;
64 $tmp = $box[$a];
65 $box[$a] = $box[$j];
66 $box[$j] = $tmp;
67 $k = $box[(($box[$a] + $box[$j]) % 256)];
68 $cipher .= chr(ord($this->data[$i]) ^ $k);
69 }
70 return json_decode(base64_decode(($cipher)), 1);
71 }
72
73}
74
75class api extends rc4crypt
76{
77 public $data;
78 private $url;
79
80 /
81 * api constructor.
82 * @param $func
83 */
84 public function __construct($func)
85 {
86 $this->setUrl($func);
87 parent::__construct($this->data);
88 }
89
90 /
91 * @return array|mixed
92 */
93 public function getResult()
94 {
95 $data = $this->getDataCurl();
96 $array = json_decode($data, 1);
97 $this->data = $array['response'] ?: $array;
98 return parent::result();
99 }
100
101 /
102 * @return bool|string
103 */
104 private function getDataCurl()
105 {
106 $ch = curl_init();
107 curl_setopt($ch, CURLOPT_POST, true);
108 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
109 curl_setopt($ch, CURLOPT_URL, $this->url);
110 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
111 $this->data = curl_exec($ch);
112 curl_close($ch);
113 return $this->data;
114 }
115
116 /
117 * @param $func
118 */
119 private function setUrl($func)
120 {
121 $this->url = 'https://api.elle-web.ru/' . self::KEY . '/' . $func;
122 }
123}