search
HomeDatabaseMysql TutorialWap Push Access Protocol(PAP)介绍

最近因为某些项目的原因,需要实现WapPush的功能,本想偷懒在网上搜索一下,看有没有合适的内容,结果找不到一个合适的.只好自已动手来写一个. 看了一下PAP协议的内容,其实也并不复杂,属于HTTP协议的扩展,因此,使用.NET的HttpWebRequest类库便可以方便的实现PAP

  最近因为某些项目的原因,需要实现WapPush的功能,本想偷懒在网上搜索一下,看有没有合适的内容,结果找不到一个合适的.只好自已动手来写一个.

  看了一下PAP协议的内容,其实也并不复杂,属于HTTP协议的扩展,因此,使用.NET的HttpWebRequest类库便可以方便的实现PAP的通讯层.剩下的工作便是PAP协议内容的组合了,PAP协议主要有四个方法及一个交互方法,分别是:

  • Submit a Push 提交一个Push信息

  • Cancel a Push 取消一个Push信息

  • Query for status of a Push 查询提交Push信息的状态

  • Query for wireless device capabilities 查询无线设备能力

 

  如果需要接收PPG(推送代理网关)返回的发送结果通知消息,则需要提供一个回调地址,供PPG发送通知响应.PI(推送发起人)与PPG之间的关系如下图:

Wap Push Access Protocol(PAP)介绍

  PI端与PPG之间使用PAP协议通讯,PPG则调用空中协议传送到手机端.

  Wap Push Access Protocol(PAP)介绍

  上图则是PI发送一个WapPush信息,PI与PPG之间的交互过程

  1. PI发起一个推送请求

  2. PPG返回一个接收响应包

  3. PPG推送WapPush到手机终端

  4. 手机终端响应接收结果

  5. PPG推最终发送结果到PI端

  6. PI端返回一个响应包到PPG,完成整个发送过程

  对于Cancel a Push, Query for status of a Push , Query for wireless device capabilities 这三种方式,都是PI与PPG之间的交互,即发起请求,得到响应的方式,因此,不作详细说明.

消息体格式

  PAP协议的消息体是采用多段的方式提交请求的,即Content-Type类型为"multipart/related",到于具体的信息,可以参考RFC2387.整个PAP协议包包括三种结构,分别为

  • 控制实体(Control Entity):提供一些控制命令

  • 内容实体(Content Entity):提供传送的内容信息

  • 能力实体(Capabilities Entity):提供终端的支持的能力配置信息

除了推送消息需要使用到三种消息以外,其它请求方法都只使用到控制实体包。这三种类型的包都是MIME类型格式,下面是一个请求包的具体格式

Content-Type: multipart/related; boundary=asdlfkjiurwghasf;
  type="application/xml"

--asdlfkjiurwghasf
Content-Type: application/xml  


br />          "http://www.wapforum.org/DTD/pap_2.0.dtd"
          []>

  ..control for PPG..


--asdlfkjiurwghasf
Content-Type: text/vnd.wap.si

  ..Service Indication push message example..

--asdlfkjiurwghasf
Content-Type: application/xml

  ..assumed client capabilities..

--asdlfkjiurwghasf--

控制实体介绍

  控制实体的定义如下

                                 | push-response
                                 | cancel-message
                                 | cancel-response
                                 | resultnotification-message
                                 | resultnotification-response
                                 | statusquery-message
                                 | statusquery-response
                                 | ccq-message
                                 | ccq-response 
                                 | badmessage-response) >
          product-name           CDATA             #IMPLIED
>

  它一共支持11种控制命令,这些命令都必须放在PAP节点下面,如:

  

支持的11种控制命令分别如下:

push-message :PI -> PPG ,发起一个Push请求
push-response :PPG -> PI,PPG对Push请求的响应结果
cancel-message :PI->PPG,取消消息的请求
cancel-response :PPG -> PI,PPG对取消请求的响应结果
resultnotification-message :PPG->PI,结果提醒消息,由PPG调用通过PUSH消息时提供的通知地址传送
resultnotification-response:PI->PPG,PI端对PPG的结果提醒消息的响应
statusquery-message :PI->PPG,状态查询消息,查询发送消息的当前状态
statusquery-response :PPG->PI,PPG对查询请求的响应结果
ccq-message :PI->PPG,发起一个终端能力查询请求
ccq-response  :PPG->PI,PPG对终端能力查询的响应结果
badmessage-response:PPG->PI,PPG在接收到错误请求包的时候,返回的响应信息

 

push-message介绍

结构定义如下:


          push-id                    CDATA             #REQUIRED
          replace-push-id            CDATA             #IMPLIED
          replace-method             ( pending-only | all )           "all"
          deliver-before-timestamp   %Datetime;        #IMPLIED
          deliver-after-timestamp    %Datetime;        #IMPLIED
          source-reference           CDATA             #IMPLIED
          ppg-notify-requested-to    CDATA             #IMPLIED 
          progress-notes-requested   ( true | false )  "false"
>


          address-value          CDATA             #REQUIRED 
>


          priority               ( high | medium | low )        "medium"
          delivery-method        ( confirmed | preferconfirmed 
                                 | unconfirmed | notspecified ) "notspecified"
          network                CDATA                          #IMPLIED
          network-required       ( true | false )               "false"
          bearer                 CDATA                          #IMPLIED
          bearer-required        ( true | false )               "false"
>

  push-message节点是推送一个消息的控制节点,它有多个属性,含义如下:

push-id:推送流水ID,由PI端创建管理,需要全局唯一,返回响应包、通知包会根据此ID来判断请求
replace-push-id:替换推送ID,指被替换的旧PushID,多用于使用新的消息替换以提交却未发送的消息
replace-method:替换的方法,有pending-only和all两种选项可选,all表示替换旧消息的所有接收者,pending-only则表示替换有可能被取消的接收者
deliver-before-timestamp:发送终止时间,指超过指定的时间则不发送消息了,格式为标准的UTC时间:YYYY-MM-DDThh:mm:ssZ
deliver-after-timestamp:发送的开始时间,须在指定的时间才能开始发送,格式为标准的UTC时间:YYYY-MM-DDThh:mm:ssZ 
source-reference:内容提供者的文本名称,PPG网关可能需要此参数判断PI的权限及能力
ppg-notify-requested-to:PPG发送结果响应请求的Url地址
progress-notes-requested:是否在响应包中包括处理日志信息
  address节点需要包括在push-message节点下,如果有多个接收人,则增加多个address节点即可,address-value是实际的接收地址,它可以是一个逻辑地址,具体的格式大致如下:
wappush=12345678/type=PLMN@ppg.operator.com

  quality-of-service节点也须要放在push-message节点下,它描述了当前消息的各种发送属性,如:优先级、使用网络、承载体等,不同的网络或许有不同的参数,请咨询相应的运营商。

具体的参数说明可以参考标准文档:wap-247

 

push-response介绍


          push-id                CDATA             #REQUIRED
          sender-address         CDATA             #IMPLIED
          sender-name            CDATA             #IMPLIED
          reply-time             %Datetime;        #IMPLIED
>

  push-response是PI提交push-message到PPG后,PPG返回的响应包结构,它有四个属性,如下:

push-id:相关的push-id
sender-address:发送者地址,一般是PPG的地址
sender-name:发送者名称,一般是PPG的名称
reply-time:应答时间,标准的UTC时间

progress-note节点不多介绍,是属于处理日志节点

response-result节点包含了所发送消息的响应结果,其定义如下:


          code                   CDATA             #REQUIRED
          desc                   CDATA             #IMPLIED
>
  code是响应的结果,具体可参考标准文档的说明,desc则是相应的描述信息

  对于其它几个请求结构相对简单,此处不再说明,参考标准文档即可。

 

HTTP请求处理说明

  PAP协议是基于HTTP协议,因此,建立一个PAP协议只需要发起一个HTTP请求即可,截取一段发送代码如下:

 

Wap Push Access Protocol(PAP)介绍Wap Push Access Protocol(PAP)介绍Code
//Pap请求
                HttpWebRequest papRequest = (HttpWebRequest)HttpWebRequest.Create(Config.ServiceUrl);
                papRequest.Method 
= "POST";
                papRequest.ContentType 
= "multipart/related; type=application/xml;boundary=" + IRequest.Boundary;
                papRequest.Headers.Add(
"Authorization", Config.EncPass);
               
                
byte[] papData = rqeuestObj.GetBytes(Config.enc);

                Stream requestStream 
= papRequest.GetRequestStream();
                requestStream.Write(papData, 
0, papData.Length);
                requestStream.Close();

                HttpWebResponse response 
= (HttpWebResponse)papRequest.GetResponse();
                StreamReader sr 
= new StreamReader(response.GetResponseStream(), Config.enc);
                ret 
= ReplaceXml(sr.ReadToEnd());
                sr.Close();

主要设置几个属性,分别为Method、ContentType以及Authorization,对于前两个不作说明,Authorization则表示认证信息,有些PPG网关不需要认证信息,因此可以忽略这个属性。认证属性的值为Base64编码的字串,格式为:Base base64String

用户名和密码以这样的格式编写:UserName:Password,然后对这个串进行编码,放在Base 后面即可。表示基本的Base64认证串。对于其它的代码就不多做解释了:)大家可以看源码。

关于源码:

  目前仅实现了PAP协议的解析、生成等功能,未实现对数据发送的队列控制、流量控制等等,这些都需要进一步完善,如果各位有兴趣完善的话,希望也提交到项目里面咯:)

下载地址:http://paplib.codeplex.com/

 

 

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft