1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
public function handle() { try {
$webHook = 'http://127.0.0.1:6701';
$client = new Client([ 'base_uri' => $webHook, 'timeout' => 10.0, 'http_errors' => false, ]); $response = $client->request('get', '/get_friend_list', [ 'query' => [ 'access_token' => 'hzjmytoken', ] ]);
$data = json_decode($response->getBody(), true);
$friendList = array_map(function ($item) { return [ 'nickname' => $item['nickname'] ?? '', 'remark' => $item['remark'] ?? '', 'user_id' => $item['user_id'] ?? ''
]; }, $data['data'] ?? []);
foreach($friendList as $item){ echo $item['user_id'].PHP_EOL; }
$num = 0; foreach ($friendList as $friend) { $nickname = $friend['nickname']; $remark = $friend['remark']; $user_id = $friend['user_id']; $name = str_replace(['信科', '一·', '一中', '软件', '能动', '统计', ' ', '美术', '是长得像RE的RE', '20-', '~继国', '1502', '自动', '~'], '', $remark); if (in_array($user_id, ['563724681', '176104400', '289883273', '1750686113', '1870786623'])) { dump('## 跳过 :' . $name); continue; }
$userInfo = ($this->getUserInfo($user_id));
$userInfo = json_decode($userInfo, true);
$sex = $userInfo['data']['sex'] ?? '';
if (strlen($name) % 3 !== 0) { dump('## 跳过(格式问题) :' . $name); continue; }
$result = $this->senderMessage($user_id, $name, $sex);
if ($user_id == '31792690') { echo 1;
} $num += 1; dump("############## $num ################"); } } catch (\Exception $e) { dump($e->getMessage()); } return null;
}
public function sender($userId, $message): string { $webHook = 'http://127.0.0.1:6701';
$client = new Client([ 'base_uri' => $webHook, 'timeout' => 10.0, 'http_errors' => false, ]); $query = [ 'access_token' => 'hzjmytoken', 'message' => $message, 'user_id' => $userId, ];
dump($query);
return '##heihei'; }
public function senderMessage($userId, $name, $sex): string { $flag = true; $message = "";
$firstName = str_split($name, 3)[0] ?? $name; $firstName = str_replace('rrr', '闫', $firstName); $newYearName = '老' . $firstName . '同学'; if (strpos($name, '老师') !== false) { $message .= $name . '新年快乐,鼠年吉祥, 🐀你健康,🐀你顺利,🐀你快乐'; } else { switch ($sex) { case 'female': $message .= '祝老' . $firstName . '同学' . '.🐀年健康,🐀年顺利,🐀年快乐,鼠年吉祥'; break; case 'male': $t = mt_rand(0, 2); if ($t == 0) { $message .= '老' . $firstName . '新年快乐ha`,'; } else if ($t == 1) { $message .= $firstName . '老板新年快乐ha`,'; } else { $message .= $firstName . '大大新年快乐ha`,'; } $message .= "祝{$newYearName},新的一年🐀你快乐,🐀你健康,神清气爽,吃嘛嘛香,财源滚滚"; break; default: $message .= $name . "同学新年快乐,鼠年大吉" . PHP_EOL; $message .= "🐀你快乐,🐀你健康,红包多抢,记得分我"; break; } }
dump('## 执行:' . $firstName. '**** | message:' . $message); if ($flag) { $result = $this->sender($userId, '🐀😁😁😁😁😁😁😁😁😁😁😁😁😁'); dump('## run1'); $result = $this->sender($userId, $message); dump('## run2'); if (strpos($name, '老师') !== false) { switch ($sex) { case 'female': if (mt_rand(0, 1)) { $result = $this->sender($userId, '🍬🍬🍬'); } else { $result = $this->sender($userId, '🍭🍭🍭🍭🍭🍭'); } break; default: $result = $this->sender($userId, '🐀🤞🐀'); break; } } else { $result = $this->sender($userId, '🐀🤞🐀'); } dump('## run3'); } else { $result = '未发送'; dump('## 未发送'); }
return $result; }
public function getUserInfo($userId): string { $webHook = 'http://127.0.0.1:6701';
$client = new Client([ 'base_uri' => $webHook, 'timeout' => 10.0, 'http_errors' => false, ]); $response = $client->request('get', '/get_stranger_info', [ // 'from_params' => [ // 'bookOrderId' => 'qwe', // 'remark' => '', // ], // 'headers' => [ // 'Content-type' => 'application/json', // ], 'query' => [ 'access_token' => 'hzjmytoken', 'user_id' => $userId, 'no_cache' => false, ] ]); return $response->getBody(); }
|