移动运营商通知事件技术详细信息

本主题介绍移动运营商通知事件的技术详细信息。

事件有效负载

MobileOperatorNotification 事件有效负载包括以下字段:

字段 说明
MessageType 触发事件的消息的枚举。
Interface 与事件关联的物理接口对应的 GUID。
EncodingType 消息的编码方法(如果 MessageType 为 SMS/USSD)。
MessageDataSize 如果 MessageType 为 SMS/USSD,则 为消息 的大小(以字节为单位)。
Message 如果 MessageType 为 SMS/USSD,则为收到的原始消息。

MobileOperatorNotification 事件通过在事件有效负载中使用 MessageType 字段来区分移动运营商通知方案中描述的每个方案。 按如下所示枚举 MessageType

枚举 类型
0 GSM 短信
1 CDMA 短信
2 USSD
3 DataPlanThresholdReached
4 DataPlanReset
5 DataPlanDeleted
6 ProfileConnected
7 ProfileDisconnected
8 RegisteredRoaming
9 RegisteredHome
10 TetheringEntitlementCheck

与 MobileOperatorNotification 事件关联的工作项应从有效区分 MessageType 的逻辑开始,并为每个方案运行相应的代码。

GSM/CDMA 短信和 USSD

传入的操作员消息(包括 SMS 和 USSD)将触发 MobileOperatorNotification 事件以及相应的 MessageType。 这些类型的唯一类型是 EncodingTypeMessageDataSizeMessage

DataPlanThresholdReached

默认情况下,此消息类型处于禁用状态。 可以通过使用预配元数据来指定 DataUsageInMobileOperatorNotificationEnabled 字段来启用它,如下所示。

<?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>

有关帐户预配元数据的详细信息,请参阅 帐户预配

当本地数据计数器估计自上次发生以来,移动宽带接口上发送和接收) 的使用量 (字节已更改 5%时,会使用此 MessageType 生成事件,但以下情况除外:

  1. 连接到家庭网络 (非漫游) 时,如果未指定数据计划限制,则每使用 100 MB 本地数据就会触发此事件。

  2. 连接到漫游网络时,数据计划限制不适用,并且每使用 5 MB 本地数据就会触发此事件。

Windows 8 中的本地数据计数器每分钟更新一次;在所有描述的方案中,此事件最多每分钟生成一次。 在Windows 8.1达到 5% 阈值时实时传送事件。

注意

尽管此信息是很好的第一手指南,但 Windows 无法考虑未计费的流量或共享相同数据限制的其他设备上的使用情况, (家庭套餐或 SIM 交换) 。 自上次与运营商自己的计费系统同步以来,移动运营商应用应仅使用本地数据计数器来大致使用。 对于已处理的数据使用情况,计费系统应被视为权威系统。

DataPlanReset

在计划重置日期,数据使用情况和订阅管理器 (DUSM) 将用户的当前本地数据使用量重置为零。

DataPlanDeleted

对于具有固定到期日期的预付费数据计划,DUSM 会删除在到期日期与帐户关联的连接配置文件,并使用此 MessageType 触发 MobileOperatorNotification 事件。 删除连接配置文件后,Windows 连接管理器不再尝试自动连接到连接配置文件描述的网络。

ProfileConnected 和 ProfileDisconnected

当 Windows 连接管理器连接到操作员体验元数据提供的网络配置文件时,将使用这些 MessageType生成 MobileOperatorNotification 事件。 此事件在每次连接和断开连接时触发,包括睡眠/恢复后的初始连接。 如果在下载并安装应用和服务元数据时设备已连接,也会触发该操作。

ProfileConnected MessageType 在移动宽带接口的 L2 连接上触发。

注意

此触发器在网络标识完成之前发生。 NetworkStatusChanged 事件 (NetworkInformation API) 的一部分是在网络标识确定网络连接级别时生成的。 有关网络标识的详细信息,请参阅 快速入门:检索网络连接信息和NetworkInformation 类。

RegisteredRoaming 和 RegisteredHome

当 Windows 连接管理器注册到漫游网络时,将使用这些 MessageType生成 MobileOperatorNotification 事件。 此事件在每次注册时触发,包括睡眠/恢复后的初始注册。 如果在下载并安装应用和服务元数据时设备已注册到网络,也会触发此事件。

当用户在漫游网络上注册时,应用应仅通知用户一次,当用户返回到其家庭网络时,应用应仅通知一次。 由于每次注册时都会触发此事件,因此应用负责在应用的会话数据中跟踪以前注册的状态。

TetheringEntitlementCheck

当用户打开 Internet 共享时,将使用此 MessageType生成 MobileOperatorNotification 事件。 只要移动运营商将服务元数据架构中的 AllowTethering 元素设置为 EntitlementCheckRequired,用户每次尝试使用 Internet 共享时都会触发该事件。 有关服务元数据架构的详细信息,请参阅 服务元数据包架构参考

应用应运行移动运营商网络支持的相应权利检查机制,并使用 Windows.Networking.NetworkOperators 命名空间中 NetworkOperatorNotificationEventDetails 类的 AuthorizeTethering 方法将结果发送到系统。 如果应用无法检查运行权利,移动运营商应将服务元数据 AllowTethering 元素更改为 AlwaysNever,以便永远不会生成事件。

使用元数据注册 MobileOperatorNotification 事件

通常,应用必须至少由用户运行一次,然后才能向系统事件代理注册工作项。 但是,由于完成关键移动宽带方案需要 MobileOperatorNotification 事件,因此此事件使用服务元数据与移动宽带应用相关联。 在服务元数据中,配置 DeviceCompanionApplications 元素。

<DeviceCompanionApplications>
  <Package>
    <Identity Name="MyOperatorNotification" Publisher="MyCorporation " />
    <Applications>
      <Application Id="MyOperatorNotification" />
        <DeviceNotificationHandlers>
          <DeviceNotificationHandler EventID="MobileOperatorNotificationHandler" EventAsset="backgroundtask.js" />
      </DeviceNotificationHandlers>
    </Applications>
  </Package>
</DeviceCompanionApplications>

EventID 属性告知系统设备需要哪种类型的事件。 EventAsset 属性的值应指向实现后台任务的入口点。 这将告知系统在发生特定事件时要运行哪个任务。

使用此示例,系统会创建并注册特定于该设备的事件。 它还会为此事件注册移动宽带应用。 应用必须具有一个名为 backgroundtask.js 的 JavaScript 文件,该文件在每次收到操作员通知时由系统运行。

如果移动宽带应用是用 C# 编写的,则事件资产必须指向实现 backgroundtask 接口的运行时类。

<DeviceNotificationHandlers>
  <DeviceNotificationHandler EventID="MobileOperatorNotificationHandler" EventAsset="MNOMessageBackground.OperatorNotification" />

下载服务元数据和应用后,设备安装程序管理器在运行应用之前向系统事件代理注册相应的工作项。 注册工作项后,如果移动宽带设备已注册或连接到网络,则 MobileOperatorNotification 事件会立即与相应的 MessageType 一起触发。

更改元数据中的后台任务注册

如果在移动宽带应用的更新版本中更改了后台任务入口点,则还必须更改服务元数据中的 DeviceNotificationHandler 元素。

在运行Windows 8、Windows 8.1和Windows 10的计算机上自动更新服务元数据。 移动宽带应用在 Microsoft Store 中更新。 应避免在服务元数据中更改 DeviceNotificationHandler 后台任务注册。 如果需要更改,服务元数据应包含对所有受支持的移动宽带应用版本中使用的所有不同后台任务入口点的引用,以便为尚未更新移动宽带应用的用户保留功能。

在预配 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 Susbscriber 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>

有关帐户预配元数据的详细信息,请参阅 帐户预配

可将文本消息标识为操作员消息的规则可以在此 XML 中定义。

  • 允许的发件人 Sender 属性指定允许通知从其到达的保留发件人地址。 (此号码必须与短信中收到的发件人号码完全匹配,包括国际格式) 。

  • 模式 用于标识和选择性地从文本消息中提取数据字段的正则表达式。 若要匹配来自发件人的所有消息,请使用模式 [^]*

启用移动运营商通知和系统事件

创建和配置 Internet 共享体验