本主题介绍移动运营商通知事件的技术详细信息。
Event payload
MobileOperatorNotification 事件有效负载包括以下字段:
| Field | Description |
|---|---|
| MessageType | 触发事件的消息的枚举。 |
| Interface | 对应于与事件关联的物理接口的 GUID。 |
| EncodingType | The encoding method for the message, if MessageType is SMS/USSD. |
| MessageDataSize | The size of the message, in bytes, if MessageType is SMS/USSD. |
| Message | The raw message that is received, if MessageType is SMS/USSD. |
MobileOperatorNotification 事件通过对事件有效负载中的 MessageType 字段进行区分来启用移动运营商通知方案中描述的每个方案。 The MessageTypes are enumerated as follows:
| Enumeration | 类型 |
|---|---|
| 0 | GSM SMS |
| 1 | CDMA SMS |
| 2 | USSD |
| 3 | DataPlanThresholdReached |
| 4 | DataPlanReset |
| 5 | DataPlanDeleted |
| 6 | ProfileConnected |
| 7 | ProfileDisconnected |
| 8 | RegisteredRoaming |
| 9 | RegisteredHome |
| 10 | TetheringEntitlementCheck |
The work item that is associated with the MobileOperatorNotification event should start with logic that effectively differentiate the MessageType, and runs the appropriate code for each scenario.
GSM/CDMA 短信和 USSD
An incoming operator message, including SMS and USSD, triggers the MobileOperatorNotification event together with the appropriate corresponding MessageTypes. Unique to these types are EncodingType, MessageDataSize, and Message.
DataPlanThresholdReached
默认情况下,此消息类型处于禁用状态。 You can enable it by using provisioning metadata to specify the DataUsageInMobileOperatorNotificationEnabled field, as shown here.
<?xml version="1.0"?>
<CarrierProvisioning xmlns="http://www.microsoft.com/networking/CarrierControl/v1">
<Global>
<CarrierId>{2c85b76b-f859-47c4-8122-721fe8b6c25f}</CarrierId>
<SubscriberId>012345678901234</SubscriberId>
</Global>
<MBNProfiles>
<DefaultProfile xmlns="http://www.microsoft.com/networking/CarrierControl/WWAN/v1">
<Name>Contoso</Name>
<AssociatedPlan>SamplePlan</AssociatedPlan>
<Context>
<AccessString>Contoso.com</AccessString>
<UserLogonCred>
<UserName>User</UserName>
<Password>[PLACEHOLDER]</Password>
</UserLogonCred>
</Context>
</DefaultProfile>
</MBNProfiles>
<Plans>
<Plan xmlns="http://www.microsoft.com/networking/CarrierControl/Plans/v1" Name="SamplePlan">
<Description PlanType="Fixed">
<DataLimitInMegabytes>500</DataLimitInMegabytes>
<DataUsageInMobileOperatorNotificationEnabled>true</DataUsageInMobileOperatorNotificationEnabled>
</Description>
</Plan>
</Plans>
</CarrierProvisioning>
For more info about account provisioning metadata, see Account provisioning.
The event is generated with this MessageType when the local data counters estimate that usage (bytes sent and received) on the mobile broadband interface has changed by 5% since the last occurrence, except in the following cases:
连接到家庭网络(非漫游)时,如果未指定数据计划限制,则会每隔 100 MB 的本地数据使用量触发此事件。
连接到漫游网络时,数据计划限制不适用,并且此事件每 5 MB 触发一次本地数据使用情况。
Windows 8 中的本地数据计数器每一分钟更新一次;在大多数情况下,在所有描述的方案中,此事件每分钟生成一次。 在 Windows 8.1 中,达到 5 个% 阈值时,实时传送事件。
Note
虽然此信息是一个很好的第一顺序指南,但 Windows 无法考虑未计费的流量或共享相同数据限制的其他设备上的使用情况(例如家庭计划或 SIM 交换)。 移动运营商应用应仅使用本地数据计数器来近似使用,因为上次与运营商自己的计费系统同步。 对于已处理的数据使用情况,计费系统应被视为权威。
DataPlanReset
在计划重置日期,数据使用情况和订阅管理器(DUSM)将用户的当前本地数据使用情况重置为零。
DataPlanDeleted
For pre-paid data plans that have a fixed expiration date, the DUSM deletes the connection profile that is associated with the account on the expiration date and the MobileOperatorNotification event is triggered by using this MessageType. 删除连接配置文件后,Windows 连接管理器不再尝试自动连接到连接配置文件描述的网络。
ProfileConnected 和 ProfileDisconnected
The MobileOperatorNotification event is generated with these MessageTypes when Windows Connection Manager connects to the network profile that is provided by the operator experience metadata. 每次连接和断开连接时都会触发此事件,包括睡眠/恢复后的初始连接。 如果在下载并安装应用和服务元数据时设备已连接,也会触发它。
ProfileConnected MessageType 在移动宽带接口的 L2 连接上触发。
Note
此触发器在网络标识完成之前发生。 The NetworkStatusChanged event (part of the NetworkInformation API) is generated when network identification determines the connectivity level of the network. 有关网络标识的详细信息,请参阅 快速入门:检索网络连接信息和NetworkInformation 类。
RegisteredRoaming 和 RegisteredHome
The MobileOperatorNotification event is generated with these MessageTypes when Windows Connection Manager registers to a roaming network. 每次注册时都会触发此事件,包括睡眠/恢复后的初始注册。 如果在下载并安装应用和服务元数据时设备已注册到网络,也会触发它。
应用只应在漫游网络上注册时通知用户一次,一次通知他们返回其主网络。 由于每次注册时都会触发此事件,因此该应用负责跟踪应用会话数据中先前注册的状态。
TetheringEntitlementCheck
The MobileOperatorNotification event is generated with this MessageTypes when the user turns on Internet Sharing. The event is triggered every time the user tries to use Internet Sharing as long as the mobile operator has set the AllowTethering element in the service metadata schema to EntitlementCheckRequired. 有关服务元数据架构的详细信息,请参阅 服务元数据包架构参考。
The app should run the appropriate entitlement check mechanism supported by the mobile operator network and send the outcome to the system by using the AuthorizeTethering method of the NetworkOperatorNotificationEventDetails class in the Windows.Networking.NetworkOperators namespace. If the app does not have the capability to run the entitlement check, the mobile operator should change the Service Metadata AllowTethering element to Always or Never, so that the event is never generated.
使用元数据注册 MobileOperatorNotification 事件
一般情况下,应用必须至少由用户运行一次,然后才能向系统事件代理注册工作项。 但是,由于需要 MobileOperatorNotification 事件来完成关键的移动宽带方案,因此此事件使用服务元数据与移动宽带应用相关联。 In the service metadata, configure the DeviceCompanionApplications element.
<DeviceCompanionApplications>
<Package>
<Identity Name="MyOperatorNotification" Publisher="MyCorporation " />
<Applications>
<Application Id="MyOperatorNotification" />
<DeviceNotificationHandlers>
<DeviceNotificationHandler EventID="MobileOperatorNotificationHandler" EventAsset="backgroundtask.js" />
</DeviceNotificationHandlers>
</Applications>
</Package>
</DeviceCompanionApplications>
The EventID attribute tells the system what kind of event to expect from the device. The value of the EventAsset attribute should point to the entry point that implements the background task. 这会告知系统在发生该特定事件时要运行的任务。
使用此示例,系统将创建并注册特定于该设备的事件。 它还注册此事件的移动宽带应用。 应用必须有一个名为 backgroundtask.js 的 JavaScript 文件,每次系统收到作员通知时,该文件都会运行。
如果移动宽带应用是用 C# 编写的,则事件资产必须指向实现 backgroundtask 接口的运行时类。
<DeviceNotificationHandlers>
<DeviceNotificationHandler EventID="MobileOperatorNotificationHandler" EventAsset="MNOMessageBackground.OperatorNotification" />
下载服务元数据和应用时,设备安装管理器在运行应用之前向系统事件代理注册相应的工作项。 Immediately after the work item is registered, if the mobile broadband device is registered or connected to the network, the MobileOperatorNotification event is triggered together with the corresponding MessageType.
更改元数据中的后台任务注册
If the background task entry point is changed in an updated version of the mobile broadband app, the DeviceNotificationHandler element in the service metadata must also be changed.
在运行 Windows 8、Windows 8.1 和 Windows 10 的计算机上自动更新服务元数据。 移动宽带应用在 Microsoft 应用商店中更新。 You should avoid changing the DeviceNotificationHandler background task registration in service metadata. 如果需要更改,服务元数据应包含对所有受支持版本的移动宽带应用中使用的所有不同后台任务入口点的引用,以便为尚未更新移动宽带应用的用户保留功能。
在预配 XML 中定义筛选规则
Windows 接受基于 XML 的预配文件。 此处显示了预配 XML 的示例版本:
<?xml version="1.0" encoding="utf-8"?>
<CarrierProvisioning xmlns="http://www.microsoft.com/networking/CarrierControl/v1">
<Global>
<!-- Adjust the Carrier ID to fit match the Service Number in service metadata. Refer to the documentation about CarrierId. -->
<CarrierId>{11111111-1111-1111-1111-111111111111}</CarrierId>
<!-- Adjust the Subscriber ID. Refer to the documentation about Subscriber ID's. -->
<SubscriberId>1234567890</SubscriberId>
</Global>
<MBNProfiles>
<DefaultProfile xmlns="http://www.microsoft.com/networking/CarrierControl/WWAN/v1">
<!-- Adjust the profile name -->
<Name>Contoso</Name>
<AssociatedPlan>Limited</AssociatedPlan>
<!-- Adjust the home provider name for the given SIM/Device -->
<HomeProviderName>Contoso</HomeProviderName>
<Context>
<!-- Adjust the access string to your APN. -->
<AccessString>Contoso.Contoso</AccessString>
<!-- Adjust the UserLogonCred to fit your UserLogonCred. Refer to the documentation about UserLogonCred's. -->
<UserLogonCred>
<UserName>user</UserName>
<Password>[PLACEHOLDER]</Password>
</UserLogonCred>
</Context>
</DefaultProfile>
<Messages xmlns="http://www.microsoft.com/networking/CarrierControl/WWAN/v1">
<Message RuleId="Sample1" Silent="true">
<SMSBearer ClassZeroOnly="false" Sender="18005551212"/>
<!-- [^]* matches all messages from this sender, regardless of content -->
<Pattern>[^]*</Pattern>
<!-- Because no Fields are specified, this message will be passed to the operator app without parsing. -->
</Message>
<Message RuleId="Sample2" Silent="false">
<!-- Parsing a simple usage message. -->
<USSDBearer/>
<Pattern>(\d+\.\d+)(\w+) of (\d+)(\w+) used as of (\S+)</Pattern>
<!-- Using these field definitions, Windows will automatically update usage data before passing the message
to the operator app. -->
<Units G="GB" M="MB"/>
<Fields>
<!-- These fields are currently unordered, but an order will be required in RC. -->
<Usage Group="1" UnitGroup="2"/>
<UsageTimestamp Group="5" Format="%I:%M%p on %d %b"/>
<DataLimit Group="3" UnitGroup="4"/>
</Fields>
</Message>
</Messages>
</MBNProfiles>
<Provisioning />
</CarrierProvisioning>
For more info about account provisioning metadata, see Account provisioning.
可以在此 XML 中定义将文本消息标识为作员消息的规则。
Allowed sender The Sender attribute specifies the reserved sender address from which the notification is allowed to arrive. (此号码必须与短信中收到的发件人号码完全匹配,包括国际格式)。
Pattern The regular expression to identify and optionally extract the data fields from the text message. 若要匹配发件人的所有消息,请使用模式
[^]*。