// PopupMenu popup = new PopupMenu(); // MenuItem exitItem = new MenuItem(""); // exitItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.exit(0); } }); // popup.add(exitItem); SystemTray systemTray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit().getImage("vk_icon.png"); TrayIcon trayIcon = new TrayIcon(image,"VKNotifer",popup); trayIcon.setImageAutoSize(true); // systemTray.add(trayIcon); // trayIcon.displayMessage("VKNotifer", "",TrayIcon.MessageType.INFO);
HttpClient httpClient = new DefaultHttpClient(); // HttpPost post = new HttpPost("http://oauth.vk.com/authorize?" + "client_id="+client_id+ "&scope="+scope+ "&redirect_uri="+redirect_uri+ "&display="+display+ "&response_type="+response_type); HttpResponse response; response = httpClient.execute(post); post.abort(); // String HeaderLocation = response.getFirstHeader("location").getValue(); URI RedirectUri = new URI(HeaderLocation); // //ip_h to_h String ip_h= RedirectUri.getQuery().split("&")[2].split("=")[1]; String to_h=RedirectUri.getQuery().split("&")[4].split("=")[1]; // post = new HttpPost("https://login.vk.com/?act=login&soft=1"+ "&q=1"+ "&ip_h="+ip_h+ "&from_host=oauth.vk.com"+ "&to="+to_h+ "&expire=0"+ "&email="+email+ "&pass="+pass); response = httpClient.execute(post); post.abort(); // HeaderLocation = response.getFirstHeader("location").getValue(); post = new HttpPost(HeaderLocation); // response = httpClient.execute(post); post.abort(); // HeaderLocation = response.getFirstHeader("location").getValue(); // post = new HttpPost(HeaderLocation); response = httpClient.execute(post); post.abort(); // HeaderLocation = response.getFirstHeader("location").getValue(); // access_token = HeaderLocation.split("#")[1].split("&")[0].split("=")[1];
// String url = "https://api.vk.com/method/"+ "messages.get"+ "?out=0"+ "&access_token="+access_token ; String line = ""; try { URL url2 = new URL(url); BufferedReader reader = new BufferedReader(new InputStreamReader(url2.openStream())); line = reader.readLine(); reader.close(); } catch (MalformedURLException e) { // ... } catch (IOException e) { // ... } return line;
public class VKapi { private String client_id = "2971510"; private String scope = "messages"; private String redirect_uri = "http://oauth.vk.com/blank.html"; private String display = "popup"; private String response_type = "token"; private String access_token; private String email = "******";// email private String pass = "******";// public void setConnection() throws IOException, URISyntaxException { // token'a } public String getNewMessage() throws ClientProtocolException, IOException, NoSuchAlgorithmException, URISyntaxException { // } }
public static void main(String[] args) throws IOException, URISyntaxException, AWTException, InterruptedException, NoSuchAlgorithmException { // PopupMenu popup = new PopupMenu(); // MenuItem exitItem = new MenuItem(""); // exitItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.exit(0); } }); // popup.add(exitItem); SystemTray systemTray = SystemTray.getSystemTray(); // Image image = Toolkit.getDefaultToolkit().getImage("vk_icon.png"); TrayIcon trayIcon = new TrayIcon(image,"VKNotifer",popup); trayIcon.setImageAutoSize(true); // systemTray.add(trayIcon); trayIcon.displayMessage("VKNotifer", " ",TrayIcon.MessageType.INFO); // VKapi vkAPI = new VKapi(); // vkAPI.setConnection(); trayIcon.displayMessage("VKNotifer", " ",TrayIcon.MessageType.INFO); // String oldMessage = vkAPI.getNewMessage(); String newMessage; int i = 0; for (;;){ // 3 Thread.sleep(3000); // if (i == 15000){ // 45 000 ( , ) vkAPI.setConnection(); // Thread.sleep(3000); // i = 0; } // newMessage = vkAPI.getNewMessage(); if (!newMessage.equals(oldMessage)) { oldMessage = newMessage; trayIcon.displayMessage("VKNotifer", " ",TrayIcon.MessageType.INFO); Tools.playDrum(Drum.d53_Ride_Bell, 127,0); } i++; } }
Tools.playDrum(Drum.d53_Ride_Bell, 127,0);
Source: https://habr.com/ru/post/144813/
All Articles