package com.windowphone.text;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;

public class HttpPost {

private String xml;
 private String url;

public HttpPost(String url, String xml) {
  this.xml = xml;
  this.url = url;
 }

private void Send() {
  
  HttpURLConnection con = null;
  URL url = null;
  try {
   url = new URL(this.url);
   con = (HttpURLConnection) url.openConnection();
   con.setRequestMethod("POST");
   con.setDoOutput(true);
   con.setDoInput(true);
   con.setUseCaches(false);
   
   //全球唯一的ID,类型:eb84a429-1ac6-46e2-b3f3-51929fd17648
   String guid = UUID.randomUUID().toString();  
   con.setRequestProperty("X-MessageID",guid);
   con.setRequestProperty("Content-Type","text/xml;charset=utf-8");
   
   //①Raw Notification模式
   //3:立刻发送 13:等待450秒发送 23:等待900秒发送
   con.setRequestProperty("X-NotificationClass", "3");
   
   
   //②Toast Notification模式
   //2:立刻发送 12:等待450秒发送 22:等待900秒发送
//   con.setRequestProperty("X-WindowsPhone-Target", "toast");
//   con.setRequestProperty("X-NotificationClass", "2");
   
   //③Tile Notification模式
   //1:立刻发送 11:等待450秒发送 21:等待900秒发送
//            con.setRequestProperty("X-WindowsPhone-Target", "token");
//            con.setRequestProperty("X-NotificationClass", "1");
            
   OutputStream out = con.getOutputStream();
   //在此要特别的小心,发送比特流,要把获取字节码改为utf-8,不然中文会乱码
   out.write(this.xml.getBytes("utf-8"));
   out.flush();
   
   //输出微软服务器response的情况,正常输出OK
   System.out.println("response:   "+con.getResponseMessage());
   
   out.close();
   con.disconnect();
  } catch (ConnectException ce) {
  } catch (IOException ie) {
  } catch (Exception e) {
  }
 }

public static void main(String[] args) {
  
  //这里直接复制window phone 应用注册微软的Uri
  String uri = "http://db3.notify.live.net/throttledthirdparty/01.00/AAGKzo1xh_AfR4Ia6ePTklzoAgAAAAADAQAAAAQUZm52OjIzOEQ2NDJDRkI5MEVFMEQ";
  
  ///①Raw Notification模式
  String rawMessage = "hitler 林楚金!";
  
  //②Toast Notification模式,固定模式,Text1和Text2两个参数
  String toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"wpNotification\">" +
        "<wp:Toast>" +
        "<wp:Text1>123</wp:Text1>" +
        "<wp:Text2>林楚金</wp:Text2>" +
        "</wp:Toast>" +
        "</wp:Notification>";
  
  //③Tile Notification模式,固定模式,BackgroundImage背景图片,count数量,Title小标题
  String tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"wpNotification\">" +
        "<wp:Tile>" +
        "<wp:BackgroundImage>/Images/天晴.jpg</wp:BackgroundImage>" +
        "<wp:Count>2</wp:Count>" +
        "<wp:Title>fuck 林楚金</wp:Title>" +
        "</wp:Tile>" +
        "</wp:Notification>";
    
  HttpPost post = new HttpPost(uri,rawMessage);
  
  post.Send();
 }

}

java实现window phone推送通知的更多相关文章

  1. 网络推送通知:及时,相关和准确 (navigator.serviceWorker.register(), window.PushManager, new Notification)

    google网络推送通知 https://developers.google.cn/web/fundamentals/push-notifications/ 服务工作线程:简介server worle ...

  2. JavaScript是如何工作的: Web推送通知的机制

    摘要: 如何在Web端推送消息? 这是专门探索 JavaScript 及其所构建的组件的系列文章的第9篇. 如果你错过了前面的章节,可以在这里找到它们: JavaScript是如何工作的:引擎,运行时 ...

  3. iOS 本地推送通知

    1.什么是本地推送通知 不需要联网的情况下,应用程序经由系统发出的通知 2.本地推送的使用场景 定时提醒,如玩游戏.记账.闹钟.备忘录等 3.实现本地推送通知的步骤 创建本地推送通知的对象UILoca ...

  4. WP7推送通知服务

    原文地址http://www.cnblogs.com/Joetao/articles/2214482.html (一)为什么使用推送通知服务(1)Windows Phone执行模型决定只有一个第三方的 ...

  5. Windows Azure Service Bus Notification Hub推送通知

    前言 随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利.在上一篇文章中, 我们介绍了如何利用Windows Azure中的Servi ...

  6. iOS 远程推送通知

    1.什么是推送通知 在某些特殊情况下,应用程序被动收到的以不同种界面形式出现的提醒信息 推送通知的作用:可以让不在前台运行的app通知app发生了改变 iOS中得推送通知种类 远程推送通知(Remot ...

  7. Windows 8.1——将网站固定到开始菜单,自定义图标、颜色和Windows推送通知

    记得在IE 9和Windows 7刚出来那会儿我写过一篇文章来介绍如何自定义网站将其固定到Windows的任务栏上,同时自定义图标及任务内容.那个功能在IE 9中被称之为JumpList.http:/ ...

  8. iOS推送通知的实现步骤

    一.关于推送通知 来源:http://blog.csdn.net/enuola/article/details/8627283 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序 ...

  9. Swift 本地推送通知UILocalNotification

    Notification是智能手机应用开发中常用的信息传递机制,它不用消耗更多资源去不停的检查信息状态,可以非常好的节省资源. 在iOS中分为两种通知:本地.远程.本地的UILocalNotifica ...

随机推荐

  1. JQuery实现点击div以外的位置隐藏该div窗口

    简单示例代码: <body> <script type="text/javascript" src="http://ajax.googleapis.co ...

  2. Android 内核初识(3)init进程

    init是一个进程,确切地说,它是Linux系统中用户空间的第一个进程.由于Android是基于Linux内核的,所以init也是Android系统中用户空间的第一个进程,它的进程号是1.作为天字第一 ...

  3. wcf service library

    创建wcf服务库的时候,系统自动生成的代码 // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”. [ServiceContract] publ ...

  4. Receving Transactions > No data found IQC无法接收PO采购物料

    Receving Transactions > No data found IQC无法接收PO采购物料 APP-PO-14094: No records meet your search cri ...

  5. C#如何获取真实IP地址

    大家获取用户IP地址常用的方法是   C# 代码   复制 string IpAddress = ""; if((HttpContext.Current.Request.Serve ...

  6. mybatis 应用参考

    1.例子中包含了 mybatis 的常用sql的写法2.动态sql 的应用3.存储过程的使用 http://takeme.iteye.com/blog/1732801

  7. 可视化zookeeper的事务日志(转)

    前面提到,在zookeeper server的配置文件zoo.cfg中可以通过dataLogDir来配置zookeeper的事务日志的输出目录,这个事务日志类似于下面这样的文件: 这个文件是一个二进制 ...

  8. java反编译工具

    由于JAVA语言安全性高.代码优化.跨平台等特性,从1995年5月由SUN公司发布后,迅速取代了很多传统高级语言,占据了企业级网络应用开发等诸多领域的霸主地位. 不过,JAVA最突出的跨平台优势使得它 ...

  9. Tdxtreelist 行变色

    ACanvas.Font.Color := clRed;   //如果有加印的  变颜色

  10. selenium2.0 处理各种窗口问题解决方法

    selenium2.0处理muti-Windows . Frames .Popup Dialogs selenium2.0处理多窗口,弹窗等,只需要调用WebDriver 嵌套类:TargetLoca ...