date("Y-m-d H:i:s", time() - 86400 * 2)], "add_time<:add_time"); for ($i = 1; $i <= 4; $i++) { $dataoke->getProducts($i); } file_put_contents($key, 1); } //商品采集结束,开始进行消息推送 if ($hour >= 7 && $hour <= 24) { //收集待推送的群组列表 $configs = $task_config = WechatTask::select([], ['status' => 1], "", null, 0, ['id' => false]); $result = $dataoke->send(0); while (!$result) { $result = $dataoke->send(0); } foreach ($configs as $item) { if ($item['id'] != 1) { $result = $dataoke->send(0, $item['user'], $result['data']); } if (!$result) { continue; } echo date("Y-m-d H:i:s") . "\t正在发送" . $item['user'] . "的宝贝:\t" . $result['data']['dtitle'] . PHP_EOL; if ($item['id'] == 1) { $wechat[$item['robot_wxid']]->sendImageMsg($result['pic'], $item['robot_wxid'], $item['group_id']); sleep(1); $wechat[$item['robot_wxid']]->sendTextMsg($result['msg'], $item['robot_wxid'], $item['group_id']); sleep(1); $_key = "/tmp/cache_" . $item['robot_wxid']; $date = intval(file_get_contents($_key)); if (time() - $date > 3600 * 4 && $hour < 20) { $wechat[$item['robot_wxid']]->sendImageMsg("https://www.phplife.net/ele.jpg", $item['robot_wxid'], '6657767651@chatroom'); file_put_contents($_key, time()); } } else { $wechat[$item['robot_wxid']]->sendTextMsg($result['msg'], $item['robot_wxid'], $item['group_id']); sleep(1); $wechat[$item['robot_wxid']]->sendImageMsg($result['pic'], $item['robot_wxid'], $item['group_id']); sleep(1); } } $sleep = rand(500, 800); echo "休息" . $sleep . "秒" . PHP_EOL; sleep($sleep); } else { echo "当前时段不支持发送消息!"; sleep(1801); } } catch (\Exception $exception) { print_r($exception); } } } }