用asp如何开发wap push(转)
生活随笔
收集整理的這篇文章主要介紹了
用asp如何开发wap push(转)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對于WAP PUSH服務,CP/SP需要向中國聯通申請該類服務,并且CP/SP所提供的WAP PUSH內容所在的服務器能夠與中國聯通的 Openwave PUSH Server連通,連接方式分為內網連接和公網連接兩種方式,由CP/SP根據自身實際情況選擇連接方式。Openwave PUSH Server分別位于北京、上海兩地,CP/SP根據就近原則選擇需要連接的Openwave PUSH Server。CP/SP需要向中國聯通提交內容應用服務器的主域名或IP地址。
北京Openwave PUSH SERVER的地址為:
http://211.94.69.231:9001/pap(公網)
http://10.2.17.66:9001/pap(內網)
上海Openwave PUSH SERVER的地址為:
http://211.95.66.70:9001/pap(公網)
http://10.95.17.66:9001/pap(內網)。
下面以向北京Openwave PUSH SERVER發送請求為例說明如何提供WAP PUSH服務:
/*
* Title: WAP Push Library Service Indication Payload Example
* Description: A basic Push Submission example using a
* Service Indication payload
*/
import java.io.IOException;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import com.openwave.wappush.*;
public class ServiceInd {
//Constants used in this example.
static final String address = "手機標識" +
"/TYPE=USER@gatewaybj.uni-info.com.cn";
static final String ppgAddress =
"http://211.94.69.231:9001/pap";
static final String SvcIndURI =
"http://devgate2.openwave.com/cgi-bin/mailbox.cgi";
static URL ppgURL = null;
static URL siURI = null;
public void SubmitMsg() throws WapPushException, IOException,
MalformedURLException {
//Instantiate and initialize the Pusher object.
Pusher ppg = new Pusher(ppgURL);
ppg.initialize();
//Instantiate the Service Indication object.
//This is the text string to send to the client device.
String alertText = "Mobile Mail: New message!";
ServiceIndication serviceIndication =
new ServiceIndication(alertText);
//Set the URI for this SI.
serviceIndication.setHref(siURI);
//Add some optional information to the SI.
ServiceIndicationInfo info =
new ServiceIndicationInfo("Mailbox", "Full");
info.AddInfoBlock("ReadMessages", "All");
serviceIndication.setInfo(info);
//Set the Service Indication action to signal-high.
serviceIndication.setAction(ServiceIndicationAction.signalHigh);
//Add some optional time information.
serviceIndication.setExpires(
new DateTime(2004, 6, 15, 12, 0, 1));
serviceIndication.setCreated(
new DateTime("2002-06-15T12:00:00Z"));
//Instantiate the push message object and set some
//optional information.
PushMessage pushMessage = new PushMessage(pushID, address);
pushMessage.setDeliverBeforeTimestamp(new
DateTime("2004-06-15T12:00:01Z"));
//Instantiate a MimeEntity and add the PushMessage
//and ServiceIndication objects.
MimeEntity me = new MimeEntity();
me.addEntity(pushMessage);
me.addEntity(serviceIndication);
//Send the push message
PushResponse pushResponse = (PushResponse) ppg.send(me);
//Read some information from the response.
System.out.println("reply-Time = " +
pushResponse.getReplyTime());
System.out.println("response-result-code = " +
pushResponse.getResultCode());
System.out.println("response-result-desc = " +
pushResponse.getResultDesc());
}//SubmitMsg()
public static void main(String[] args) throws WapPushException,
IOException {
try {
ppgURL = new URL(ppgAddress);
siURI = new URL(SvcIndURI);
ServiceInd si = new ServiceInd();
si.SubmitMsg();
}
//Handle possible exceptions.
catch (BadMessageException exception) {
System.out.println("*** ERROR - bad message exception");
BadMessageResponse response = exception.getResponse();
System.out.println("*** ERROR = " +
response.getBadMessageFragment());
}
catch (WapPushException exception) {
System.out.println("*** ERROR - WapPushException (" +
exception.getMessage() + ")");
}
catch (FileNotFoundException exception) {
System.out.println("*** ERROR - input file not found");
}
catch (MalformedURLException exception) {
System.out.println("*** ERROR - malformed PPG URL");
}
catch (IOException exception) {
System.out.println( "*** ERROR - I/O exception");
}
catch (Exception exception) {
System.out.println("*** ERROR - exception(" +
exception.getMessage() + ")");
}
}//main()
}//class ServiceInd
北京Openwave PUSH SERVER的地址為:
http://211.94.69.231:9001/pap(公網)
http://10.2.17.66:9001/pap(內網)
上海Openwave PUSH SERVER的地址為:
http://211.95.66.70:9001/pap(公網)
http://10.95.17.66:9001/pap(內網)。
下面以向北京Openwave PUSH SERVER發送請求為例說明如何提供WAP PUSH服務:
/*
* Title: WAP Push Library Service Indication Payload Example
* Description: A basic Push Submission example using a
* Service Indication payload
*/
import java.io.IOException;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import com.openwave.wappush.*;
public class ServiceInd {
//Constants used in this example.
static final String address = "手機標識" +
"/TYPE=USER@gatewaybj.uni-info.com.cn";
static final String ppgAddress =
"http://211.94.69.231:9001/pap";
static final String SvcIndURI =
"http://devgate2.openwave.com/cgi-bin/mailbox.cgi";
static URL ppgURL = null;
static URL siURI = null;
public void SubmitMsg() throws WapPushException, IOException,
MalformedURLException {
//Instantiate and initialize the Pusher object.
Pusher ppg = new Pusher(ppgURL);
ppg.initialize();
//Instantiate the Service Indication object.
//This is the text string to send to the client device.
String alertText = "Mobile Mail: New message!";
ServiceIndication serviceIndication =
new ServiceIndication(alertText);
//Set the URI for this SI.
serviceIndication.setHref(siURI);
//Add some optional information to the SI.
ServiceIndicationInfo info =
new ServiceIndicationInfo("Mailbox", "Full");
info.AddInfoBlock("ReadMessages", "All");
serviceIndication.setInfo(info);
//Set the Service Indication action to signal-high.
serviceIndication.setAction(ServiceIndicationAction.signalHigh);
//Add some optional time information.
serviceIndication.setExpires(
new DateTime(2004, 6, 15, 12, 0, 1));
serviceIndication.setCreated(
new DateTime("2002-06-15T12:00:00Z"));
//Instantiate the push message object and set some
//optional information.
PushMessage pushMessage = new PushMessage(pushID, address);
pushMessage.setDeliverBeforeTimestamp(new
DateTime("2004-06-15T12:00:01Z"));
//Instantiate a MimeEntity and add the PushMessage
//and ServiceIndication objects.
MimeEntity me = new MimeEntity();
me.addEntity(pushMessage);
me.addEntity(serviceIndication);
//Send the push message
PushResponse pushResponse = (PushResponse) ppg.send(me);
//Read some information from the response.
System.out.println("reply-Time = " +
pushResponse.getReplyTime());
System.out.println("response-result-code = " +
pushResponse.getResultCode());
System.out.println("response-result-desc = " +
pushResponse.getResultDesc());
}//SubmitMsg()
public static void main(String[] args) throws WapPushException,
IOException {
try {
ppgURL = new URL(ppgAddress);
siURI = new URL(SvcIndURI);
ServiceInd si = new ServiceInd();
si.SubmitMsg();
}
//Handle possible exceptions.
catch (BadMessageException exception) {
System.out.println("*** ERROR - bad message exception");
BadMessageResponse response = exception.getResponse();
System.out.println("*** ERROR = " +
response.getBadMessageFragment());
}
catch (WapPushException exception) {
System.out.println("*** ERROR - WapPushException (" +
exception.getMessage() + ")");
}
catch (FileNotFoundException exception) {
System.out.println("*** ERROR - input file not found");
}
catch (MalformedURLException exception) {
System.out.println("*** ERROR - malformed PPG URL");
}
catch (IOException exception) {
System.out.println( "*** ERROR - I/O exception");
}
catch (Exception exception) {
System.out.println("*** ERROR - exception(" +
exception.getMessage() + ")");
}
}//main()
}//class ServiceInd
來自 “ ITPUB博客 ” ,鏈接:http://blog.itpub.net/10294527/viewspace-125163/,如需轉載,請注明出處,否則將追究法律責任。
轉載于:http://blog.itpub.net/10294527/viewspace-125163/
總結
以上是生活随笔為你收集整理的用asp如何开发wap push(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [机器学习笔记]Note9--机器学习系
- 下一篇: 以下十种性格的人不适合做程序员,你赞同