手册

介绍

左侧边栏包含指向相应部分的链接:

  • 用户名 - 链接到个人资料。
  • 仪表盘 - 以图表和图形的形式查看当前状态。
  • 应用程序 - 应用管理。
  • 解锁代码 - 自动生成或由您下载的解锁码。
  • 付款 - 用户收款历史。
  • 手册 - 当前的用户手册。

仪表盘

您可以为仪表板中的所有小部件设置通用过滤器:

  • 货币 - 在仪表板上将收入和支出金额转换为的货币。
  • 时期 - 在仪表板的图表和表格中显示数据的时间段。它确定了对支付、应用程序和其他参数的信息和统计信息进行分析和显示的时间间隔。

余额

余额包括以下金额:

  • 总额 - 所选时期内所有用户付款的总金额,不包括支付系统和PayToUse的费用。
  • 净额 - 所选时期内所有付款的总金额减去支付系统和PayToUse的费用。
  • 待处理金额 - 指定时期内的所有付款总金额减去支付系统和PayToUse的费用,待提取到开发者账户。付款在支付后7天后可用于提取。
  • 可用金额 - 所有时间内所有付款的总金额减去支付系统和PayToUse的费用,可用于提取到开发者账户。

付款

支付小部件包括按应用程序分组的所选时期内的付款表。

表字段:

  • 应用程序 - 应用程序。仅显示在所选时期内进行了付款的应用程序。
  • 付款 - 付款数量。
  • 总额 - 所选时期内所有用户付款的总金额,不包括支付系统和PayToUse的费用。
  • 净额 - 所选时期内所有付款的总金额减去支付系统和PayToUse的费用。

图表显示了每天净额总额值的动态。

新用户

新用户图表显示了每天的两个动态值:

  • 新用户 - 新API调用的数量。仅当发送到API的请求中传递了device参数(唯一设备标识符)时,才会记录API访问。此参数必须对设备真正唯一。 (查看发送请求)
  • 付款 - 同一时期每天的付款数量。

转化

转化率指标是评估您的销售效率将新用户转化为付款的指标。

图表显示了付款新用户的数量比例,以百分比表示。

应用程序

当您进入此部分时,将打开您的应用程序列表。

应用程序表中的列列表:

  • # - 唯一应用标识符。在验证应用程序代码或显示付款表单时使用。
  • 名称 - 应用程序名称。名称仅在报告和仪表板中向您显示。单击应用程序名称将打开应用程序编辑页面。
  • 状态 - 应用程序的当前状态。可能是:
    • 创建时间 - 应用程序刚刚创建,尚未配置。
    • 已发布 - 应用程序正在运行。
  • 创建时间 - 应用程序创建日期。
  • 其他控制按钮
    • 删除 - 从列表中删除应用程序。

创建或编辑应用程序

为了接受付款,您必须连续填写所有必要的应用程序数据并激活应用程序。

创建新应用程序的按钮位于应用程序列表的标题栏中。

应用程序

创建应用程序时可用的字段:

  • 名称 - 您在报告或仪表板上可以看到的应用程序名称。名称将显示在已保存应用程序的页面标题中。只要应用程序尚未保存,名称将显示为“New app”。必须输入该字段。
  • 联系邮箱 - 将发送给用户的消息副本的电子邮件地址。此地址也指定在“回复”字段中,并用于用户回复带有代码的收到的电子邮件。必须输入该字段。默认情况下,该字段填充了来自开发者配置文件的值。该值可以更改为不同的值。
  • 应用程序类型 - 应用程序类型。如果选择了组类型的应用程序,则会显示一个应用程序列表进行分组。列表中仅显示生成解锁代码的单个应用程序。
  • 允许付款反馈 - 向付款表单添加一个字段,供用户输入自由文本。反馈将添加到开发人员的电子邮件副本中。还可以在付款详细信息中看到反馈。

开始输入更改值,保存按钮将出现。保存按钮允许您在不转到下一页的情况下保存更改。下一页按钮保存更改并移动到下一页。您始终可以返回以稍后进行更改。

在页面标题中,只有已保存的应用程序页面可用于导航。您可以单击“下一页”或转到页面标题中的部分。

描述

从列表中选择一种语言,然后单击“添加”。

将显示一个选定语言的本地化应用程序文本选项卡。

可用语言:

  • 德语
  • 英语
  • 法语
  • 西班牙语
  • 俄语
  • 简体中文

描述中的字段用于在付款表单上显示信息,并在向用户的回复消息中显示:

  • 名称 - 选择的语言的应用程序名称。显示在付款表单上和付款通知电子邮件中。默认情况下,添加语言时会插入应用程序名称。您可以为每种语言设置不同的名称。必填字段。
  • 描述 - 应用程序的简要描述。显示在应用程序名称下的付款表单上。可选字段。如果您不希望显示任何描述,可以将其留空。
  • 回复 - 付款成功后将发送给用户的附加信息。响应文本将添加到标准响应之后的电子邮件末尾。

必须添加至少一种语言才能保存并转到下一页。

在付款表单中显示的语言是根据用户在浏览器设置中指定的偏好自动确定的。您可以为应用程序保存应用程序语言。

开始输入或更改值,然后会出现“保存”按钮。保存按钮允许您在不转到下一页的情况下保存更改。下一页按钮保存更改并转到下一页。您始终可以返回以稍后进行更改。

在页面标题中,只有已保存的应用程序页面可用于导航。您可以单击“下一页”或转到页面标题中的部分。

价格

该页面包含与付款相关的价格列表和字段:

  • 试用期 - 试用期的长度。
  • 时间单位 - 试用期的时间单位。例如,如果您指定为7天,则表示在应用程序的第一次 API 调用后的 7 天之后,它将返回试用期已过期的响应。保存了第一次设备调用的时间。
  • 价格计算方法 - 价格计算方法从列表中选择:
    • 根据期限计算价格 - 在付款表单中,用户指定代码的激活期限,价格根据下面的表格自动计算。用户将在响应电子邮件中收到自动生成的解锁代码。
    • 根据价格计算期限 - 在付款表单中,用户从列表中选择一个价格或输入自己的价格值,期限根据下面的表格自动计算。用户将在响应消息中收到自动生成的代码。
    • 永久代码 - 在付款表单中,用户从列表中选择一个价格或输入自己的价格值。付款后,他们将在响应电子邮件中收到与所选价格对应的代码。
    • 捐赠 - 在付款表单中,用户从列表中选择一个价格或输入自己的价格值。对于捐款类型的应用程序,不生成解锁代码。

价格以美元为单位。最低价格为1美元。

开始输入或更改值,然后会出现“保存”按钮。保存按钮允许您在不转到下一页的情况下保存更改。下一页按钮保存更改并转到下一页。您始终可以返回以稍后进行更改。

在页面标题中,只有已保存的应用程序页面可用于导航。您可以单击“下一页”或转到页面标题中的部分。

预览

此页面设置以下值:

  • 代码长度 - 生成的代码的长度(如果适用)。
  • 代码字符集 - 生成代码的字符集:
    • 数字代码 - 仅使用数字 0、1、2、3、4、5、6、7、8、9 生成代码。代码中可能包含前导零。验证代码时,前导零是重要的。
    • 字母数字代码 - 使用字符 1、2、3、4、5、6、7、8、9、A、B、C、D、E、F、G、H、I、G、K、L、M、N、P、Q、R、S、T、U、V、X、Y、Z 生成代码。代码使用大写字符生成并发送给用户。验证代码时,字符的大小写不重要。
  • 检查代码的链接 - 用于代码验证的示例链接。
  • 支付链接 - 付款链接。您可以复制链接并将其粘贴到应用程序发布的网站上的描述中。 需要传递的参数:
    • app - 应用程序的唯一标识符。必需参数。
    • amount - 购买时在价格字段中指定的金额。默认价格将被忽略。但是,金额不能低于最低价格,也不能低于应用程序设置的最低价格。可选参数。

要开始接受付款,您需要使用“启动”按钮激活应用程序。在激活应用程序之前,请确保输入的所有数据都是正确的。应用程序生成的密钥无法更改。

代码验证

应用程序解锁代码的检查分为3个步骤:

  1. 编写并发送用于代码验证的请求
  2. API端的检查
  3. 接收并处理 API 响应
发送请求

要验证代码,您的应用程序用户必须在应用程序设置中的字段中输入它。

/resources/settings/properties.xml
<properties>
	<property id="UnlockCode" type="string"></property>
	<property id="UnlockResult" type="string">Checking...</property>
	...
<properties>
/resources/settings/settings.xml
<settings>
	<setting propertyKey="@Properties.UnlockCode" title="@Strings.UnlockCode">
		<settingConfig type="alphaNumeric" maxLength="12"/>
	</setting>
	<setting propertyKey="@Properties.UnlockResult" title="@Strings.UnlockResult">
		<settingConfig type="alphaNumeric" readonly="true"/>
	</setting>
	...
</settings>

然后,您需要向付费使用 API 服务器发送请求:

/source/background.mc
function onTemporalEvent() as Void {
	var ds = System.getDeviceSettings();
	return Toybox.Communications.makeWebRequest(
		"https://api.pay-to-use.com", // API URL
		{
			"device" => ds.uniqueIdentifier, // 设备唯一标识符
			"app" => "6", // 您的应用程序 ID
			"model" => ds.partNumber, // device part number
			"code" => Application.Properties.getValue("UnlockCode") // 您的应用程序中的解锁代码值
		},
		{
			:method => Communications.HTTP_REQUEST_METHOD_POST,
			:headers => { "Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON },
			:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
		},
		method(:onReceive)
	);
}

API 请求参数:

  • url - https://api.pay-to-use.com. Using HTTPS is mandatory.
  • 请求的正文(传递的值)。键值对字典:
    • device - 设备的唯一标识符。
    • app - 您的应用程序的唯一标识符。
    • model - device model identifier. Optional parameter. Data is used to display statistics for new devices.
    • code - 用户在您的应用程序设置中输入的解锁代码。
  • 请求选项:
    • :method - API 支持 GET 和 POST 请求方法。
    • :headers - 对于 POST 方法,参数需要以 JSON 格式传递。
    • :responseType - 响应以 JSON 格式返回。
  • responseCallback - 链接到回调方法,该方法应该接受两个参数:
    • responseCode - 服务器响应头代码。
    • data - 如果请求成功,则为内容,否则为 null。
API端的检查

如果没有向 API 传递参数,则 API 返回 HTTP/1.1 404 Not Found 头。

如果至少向 API 传递了一个参数,则 API 返回头 HTTP/1.1 200 OK

服务器响应包括:

  • response - 响应代码
  • msg - 响应的文本描述
  • expires - UNIXTIME 时间戳(如果适用)

进行检查以确保传入的应用程序标识符是正确的。 支付时应用程序必须处于 已发布 状态。 如果出错,将返回响应代码 301

如果传输了唯一设备标识符,则会搜索并存储该设备标识符。 如果在检查或保存时出现错误,则返回错误代码 402。 如果发现此类返回代码,请立即写信给支持团队,地址为 [email protected]

如果代码通过,那么对于 根据期限计算价格根据价格计算期限 计算方法的应用程序,将执行以下步骤:

  • 如果传输了空代码,则会从前面步骤中定义的唯一设备标识符中分离。
  • 如果传输了非空代码并且未激活,则根据购买代码时指定的价格条件激活代码,而与激活日期无关。
  • 如果未传输代码或传输的代码未找到,则返回错误代码 201
  • 已激活的代码与设备进行检查,如果在激活期间传输了与存储的唯一设备标识符不同的唯一设备标识符,则返回错误代码 202
  • 如果传输的代码没有到期日期并且所有先前的检查都已通过,则返回代码 101
  • 如果代码是有时间限制的,则执行检查。如果密钥未过期,则返回代码 101。如果代码已过期,则返回错误代码 203
  • 此类应用程序要求代码绑定到设备。如果未传输唯一设备标识符,则返回错误代码 304

对于具有 永久代码 的应用程序,仅检查购买时代码的可用性。 如果找到代码,则返回代码 101。如果找不到代码,则返回错误代码 201

对于具有 捐赠 计算方法的应用程序,不检查代码。 始终返回代码 101

如果先前的检查未通过,则检查测试期。 如果自设备首次联系以来的时间已经过去比当前应用程序设置的时间长,则返回错误代码 204。 如果试用期尚未到期,则返回错误代码 102

如果仅传输应用程序 ID,而没有传输解锁代码或唯一设备 ID,则返回错误代码 303

如果返回的响应是 500,您应该写信至 [email protected] 请求支持

以下是所有返回的代码表:

返回 消息
101 根据期限计算价格根据价格计算期限 计算方法:
  • 永久激活
{
	"response":101,
	"msg":"Active forever",
	"expires":0
}
  • 激活直至 [日期]
{
	"response":101,
	"msg":"Active until 8 Mar 2026",
	"expires":1772981728
}
永久代码:
{
	"response":101,
	"msg":"The code check was successfull",
	"expires":0
}
捐赠:
{
	"response":101,
	"msg":"No code check required",
	"expires":0
}
102
{
	"response":102,
	"msg":"Trial period expires in 1d 23h 7m",
	"expires":1745848953
}
201
{
	"response":201,
	"msg":"Code not found"
}
202
{
	"response":202,
	"msg":"Used on the another device"
}
203
{
	"response":203,
	"msg":"Expiration: 7 Mar 2025",
	"expires":1741359328
}
204
{
	"response":204,
	"msg":"Trial period expired"
}
301
{
	"response":301,
	"msg":"Application not found"
}
302
{
	"response":302,
	"msg":"Term undefined"
}
303
{
	"response":303,
	"msg":"Not enought arguments"
}
304
{
	"response":304,
	"msg":"Device is nesessary"
}
401
{
	"response":401,
	"msg":"Error code saving"
}
402
{
	"response":402,
	"msg":"Error device saving"
}
500
{
	"response":500,
	"msg":"Unknown error"
}
检查响应

然后您应该检查 Pay-to-use API 服务器的响应:

/source/background.mc
function onReceive(responseHeader, data) as Void {
	if (responseHeader == 200) { Toybox.Background.exit(data); }
}

您可以检查所有标题和代码,您可以为用户方便显示自己的消息,但在最简单的形式中,验证将看起来像这样:

/source/app.mc
function onBackgroundData(data) as Void {
	if (data.hasKey("response")) {
		if (data.hasKey("msg")) {
			// 您可以在属性字段中使用名称“UnlockResult”显示data["msg"]。
			Application.Properties.setValue("UnlockResult", data["msg"]);
		}
		if (data["response"].toString().substring(0, 1).equals("2")) {
			// 代码验证失败
			// 付费功能不可用
			...
		} else {
			// 代码检查成功或错误是您的错误或 API 的错误
			// 付费功能可用
			...
		}
	}
}

解锁代码

当您进入此部分时,将打开一个解锁代码列表。

解锁代码列表

您可以在顶部搜索栏中搜索电子邮件字段或代码。找到的代码将显示在列表中。您可以使用电子邮件或代码的全部或部分作为搜索标准。匹配项将以颜色突出显示。搜索和过滤器同时工作,彼此不排斥。

用户的最后使用的过滤器会被保存。也就是说,下次进入页面时,最后使用的过滤器将自动应用。解锁代码列表提供以下过滤器:

  • - 选择在解锁代码列表中显示的表列。
  • 应用程序 - 仅显示所选应用程序的解锁代码。
  • 状态 - 仅显示处于所选状态的解锁代码。

解锁代码表中的列列表:

  • 应用程序 - 您的应用程序。您可以按照链接编辑其设置。
  • 代码 - 解锁代码。
  • 电子邮件 - 与解锁代码注册相关联的电子邮件地址。该地址用于在网站的我的购买部分搜索客户的解锁代码。此部分对用户可见。
  • 期限 - 发送的代码的有效期(在应用程序设置中指定)。代码设置了一个有效期,与创建时应用程序设置的条件相对应。
  • 状态 - 解锁代码状态。 (查看解锁代码状态)
  • 创建时间 - 解锁代码创建日期。
  • 已激活 - 代码的激活日期。当特定用户设备首次联系PayToUse API服务并提交此代码时,将设置激活日期。代码的状态变为已激活。只有非活动代码才能被激活。如果由具有不同ID的设备提交了活动代码,则API将返回错误202。一个代码只能与一个设备关联。
  • 到期时间 - 代码激活到期日期。对于在代码激活时具有有限有效期的代码进行设置。对于没有限制有效期的代码,到期日期保持为空白。
  • 已删除 - 代码删除日期。删除后,代码状态设置为未知
  • 支付编号 - 支付的唯一序列号。您可以单击链接查看付款的详细信息。
  • 解锁代码的操作按钮。例如,删除。

解锁代码状态

在其生命周期中,解锁代码经历了不同的状态,可以通过代码状态进行跟踪。

状态 描述
可用 状态分配给未执行任何操作的解锁代码,或者如果代码的设备链接被重置。
已激活 该状态适用于设置了激活日期的代码。当设备首次成功访问PayToUse API服务时,激活日期将被设置。此外,激活代码时还会设置代码的过期日期。
过期 该状态适用于已过期的代码。解除代码与设备的关联不会重置代码的过期日期。使用此状态检查代码将返回错误203(查看API端的检查)
未知 当代码被删除时,将设置该状态。使用此状态检查代码将返回错误201(查看API端的检查)

付款

当您进入此部分时,将打开用户付款列表。

以下支付系统用于接收付款:

系统 描述
支付系统费用为每次成功的信用卡收费为2.9% + 0.30美元。支持信用卡、钱包和其他支付选项。费用取决于支付方法,可能与信用卡支付费用不同。关于支付系统收取的费用的详细信息,您可以在支付系统的网站上找到。
支付系统费用为每次成功付款的3.4% + 0.30美元。支持信用卡和PayPal。有关支付系统收取的费用的详细信息,您可以在支付系统的网站上找到。
支付系统费用为每次成功付款的3.9%。支持信用卡和其他支付选项。费用取决于支付方式。有关支付系统收取的费用的详细信息,您可以在支付系统的网站上找到。

支付系统费用之后,PayToUse将收取13%的费用。我们一直在努力降低费用。

如果支付系统出现任何争议或退款,支付系统的处罚将重新发给开发者。因此,您不应允许发生这种情况。在有争议的情况下,PayToUse不会收取费用。

付款列表

您可以在顶部搜索栏中搜索电子邮件字段或发送的代码。找到的付款将显示在列表中。您可以将电子邮件或发送的代码的全部或部分用作搜索标准。匹配项将以颜色高亮显示。搜索和过滤器同时工作,彼此不互斥。

最后使用的过滤器将保存给用户。也就是说,下次您进入页面时,将自动应用上次使用的过滤器。对付款列表可用的过滤器有:

  • - 选择要在付款列表中显示的表列。
  • 应用程序 - 仅显示所选应用程序的付款。
  • 系统 - 仅显示来自所选支付系统的付款。
  • 状态 - 仅显示具有所选状态的付款。

付款表中的列列表:

  • 应用程序 - 您的应用程序。您可以按照链接编辑其设置。
  • # - 付款的唯一序列号。当用户从支付表单转到支付系统中的支付页面时,此序列号会自动分配给付款。您可以单击链接查看付款的详细信息。
  • 备注 - 用户在付款表单中输入的消息。
  • 系统 - 用户选择的支付系统。
  • 状态 - 付款状态。 (查看付款状态)
  • 电子邮件 - 用户在付款表单中填写的电子邮件地址。
  • 期限 - 发送的代码的有效期(在应用程序设置中指定)。
  • 创建时间 - 付款创建日期。
  • 发票金额 - 用户支付的金额。根据应用设置在付款表单中指定。
  • 付款日期 - 付款日期。
  • 付款金额 - 支付系统确认的支付金额。
  • 发送的代码 - 发送给用户的代码。
  • 可用金额 - 可提取金额。
  • 支付金额 - 用于付款的提取金额。

无法更改付款。

付款状态

在其生命周期内,支付会进入不同的状态,可以通过支付状态进行跟踪。

状态 描述
不完整 给尚未执行任何操作的支付分配了状态。支付创建于用户从付款表单切换到付款系统表单的时刻。支付被分配一个唯一的序列号,以及支付的基本属性:金额、支付系统、日期。
成功 该状态分配给从支付系统接收到正面响应的支付。下一步是向用户发送包含生成的代码或其他数据的电子邮件,具体取决于应用程序的设置。如果支付保留在此状态,则需要特别注意,因为尚未执行后续操作。
错误 该状态分配给从支付系统接收到负面答复的支付。不会执行后续步骤。需要特别注意此类支付,因为支付系统一侧的状态可能会延迟处理。
待处理 该状态分配给从支付系统接收到正面答复的支付,所有后续步骤均已成功完成。此状态的支付不可提款。支付将在7天内自动转移到下一个状态。
可用 该状态的支付可提款。
发送中 此状态用于下一次提款中包含的支付。如果提款被取消或拒绝,支付状态将返回可用状态。
已发送 此状态用于已进行提款的支付。等待确认收款。
已完成 此状态用于成功提款的支付。您可以通过在相应部分确认提款来手动设置状态。支付提款后14天状态也会自动更改。
已退款 已发出退款的支付转移到此状态。发出退款时会收取退款费用。该费用将从提款金额中扣除。

提款

当您进入此部分时,将打开您的提款列表。

提款列表

用户的上次使用的过滤器将被存储。也就是说,下次进入页面时,将自动应用上次使用的过滤器。提款列表可用的过滤器包括:

  • - 在提款列表中仅显示选定的列。
  • 状态 - 仅显示处于选定状态的提款。

提款表中的列列表:

  • # - 提款的唯一序列号。当提款保存时,它会自动分配给提款。您可以单击链接查看提款的详细信息。
  • 状态 - 提款状态。 (查看提款状态)
  • 创建时间 - 提款请求的日期。
  • 金额 - 提款金额。
  • 提款 - 提款发送的日期。
  • 提款操作的按钮。例如,确认。

您可以在提现处于已发送状态时确认提现。

提款状态

提现在其生命周期中会进入不同的状态,可以通过提现状态进行跟踪。

状态 描述
待处理 状态分配给在创建时没有执行任何操作的提现。
已取消 此状态分配给已取消的提现。提现可能因多种原因而取消。例如,未指定资金接收方式。此提现的所有款项都会进入 可用 状态,可再次提现。
已发送 当提现款项发送时,此状态被设置。
已完成 手动提现收到开发人员确认收款时设置此状态。或在发送后14天自动设置。
已拒绝 当银行或支付系统在发送后退还资金时,此状态用于提现。此提现的所有款项都会进入 可用 状态,并可再次提现。

API

Overview

API PayToUse performs the following functions:

  1. Checks the activation status of an unlock code and activates it if necessary.
  2. Retrieves blood glucose data from the NightScout app.
  3. Retrieves current weather data for a specified location.

All information can be requested and returned in a single request.

API Endpoints

You can use one of the following endpoints:

  • https://api.pay-to-use.com
  • https://api.p2u.io

Both endpoints handle GET and POST requests.

Request Parameters

  • device: string (required) — unique device identifier
  • app: integer (required) — your Application ID
  • model: string (optional) — device model code, needed for collecting and displaying statistics for devices using the app
  • code: string (optional) — unlock code
  • bg: associative array (optional) — data for requesting blood glucose levels from the NightScout app
    • url: string (optional) — address of the NightScout app
  • weather: associative array (optional) — data for requesting current weather
    • appid: string (optional) — weather API access key
    • lat: float (optional) — latitude
    • lon: float (optional) — longitude
    • provider: integer (optional) — weather provider

List of Supported Weather Providers

1. OpenWeatherMap

  • 描述: OpenWeatherMap provides global weather data, including real-time weather, historical data, and 16-day forecasts. With wide geographic coverage and frequent updates, OpenWeatherMap is a popular choice for applications requiring both current weather and extended forecasts.
  • Data Provided: Real-time temperature, humidity, wind speed, air quality, precipitation probability, and more. Offers both current and forecast data, including minute-by-minute weather data for select locations.
  • Provider Selection: Include provider = 1 in the weather section of your request to select OpenWeatherMap as the weather provider.
  • Usage Notes: Offers free and paid tiers, with data accessible via API key authentication. Advanced data layers and premium features are available in paid plans.
  • API Documentation: Available here.

2. QWeather

  • 描述: QWeather, also known as HeWeather, provides comprehensive weather data focused on China but includes international data as well. It offers extensive details such as real-time weather, forecasts, air quality information, and alerts.
  • Data Provided: Current temperature, humidity, UV index, pollution levels, daily and hourly forecasts, as well as warnings for severe weather conditions. Known for its granular air quality data and its real-time updates on changing weather conditions.
  • Provider Selection: Include provider = 2 in the weather section of your request to select QWeather as the weather provider.
  • Usage Notes: QWeather offers API access with free and premium tiers. The free tier provides limited data, while premium options expand to cover additional data points and locations.
  • API Documentation: Available here.

3. MET Weather (MET Norway)

  • 描述: The MET Weather API, provided by MET Norway, gives access to a variety of open meteorological data, including forecasts, historical data, and specific data for Norway and the Nordic regions. Known for its accuracy and transparency, MET Weather is ideal for applications in need of highly reliable weather data.
  • Data Provided: Current weather conditions, forecasts, precipitation, temperature, wind data, and UV index. MET Weather offers specialized data for the Nordic regions but also supports global weather information.
  • Provider Selection: Include provider = 3 in the weather section of your request to select MET Weather as the weather provider.
  • Usage Notes: All data provided by MET Weather is freely available for use under a Creative Commons license, allowing both non-commercial and commercial applications without cost. MET Norway is renowned for its environmental data, making it a trusted provider, particularly in Europe.
  • API Documentation: Available here.

Example Request

/source/background.mc
function onTemporalEvent() as Void {
	var ds = System.getDeviceSettings();
	if (!ds.phoneConnected) { // Checks that the device is connected to the phone for sending the request
		return;
	}

	var id = ds.uniqueIdentifier;
	if (id == null) { // Verifies that the device has been assigned a unique identifier
		return;
	}

	var request = {};

	var lockCheck = Application.Storage.getValue("LastCodeCheckTimestamp");
	if (lockCheck == null || lockCheck <= Time.now().value()) { // Sends the code if necessary
		request.put("code", Application.Properties.getValue("UnlockCode"));
	}

	var ns_url = Application.Properties.getValue("NS");
	if (!ns_url.equals("")) { // Sends the NightScout app URL if needed
		request.put("bg", { "url" => ns_url });
	}

	var wP = Application.Properties.getValue("Weather");
	if (wP != 0) { // Sends weather request parameters if needed
		var lat = Application.Properties.getValue("latitude");
		var lon = Application.Properties.getValue("longitude");
		if (!lat.equals("") && !lon.equals("")) {
			request.put("weather", {
				"appid" => Application.Properties.getValue("appID"),
				"lat" => lat,
				"lon" => lon,
				"provider" => wP
			});
		}
	}

	if (!request.isEmpty()) {

		// Fills in the required request parameters
		request.put("device", id);
		request.put("app", p2uAppID); // 您的应用程序 ID
		request.put("model", ds.partNumber);

		Toybox.Communications.makeWebRequest(
			"https://api.p2u.io", // API Endpoint
			request,
			{
				:method => 3, // Communications.HTTP_REQUEST_METHOD_POST
				:headers => {
					"Content-Type" => 1 // Communications.REQUEST_CONTENT_TYPE_JSON
				},
				:responseType => 0 // Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
			},
			method(:onReceive)
		);
	}
}

API Response

The API returns a JSON object with information on unlock status, glucose level, and weather.

Response Parameters

Unlock Code Verification Results (if a request was sent):

  • response: integer — return code
  • msg: string — message about the verification result
  • expires: integer — expiration timestamp of the code in UNIXTIMESTAMP format
  • qr: array — QR code for purchase or serial number verification, if applicable

NightScout App Response (if a request was sent):

  • bg: associative array — formatted response from the NightScout app
    • value: integer — blood glucose level in mg/dL
    • date: integer — timestamp of the code expiration in UNIXTIMESTAMP format
    • direction: string — trend in blood glucose level change

Weather API Response (if a request was sent):

  • weather: associative array — formatted response from the Weather API
    • provider: integer — weather provider identifier
    • weather: array — current weather conditions. May return one or two values; if two values are returned, they represent day and night conditions
    • temp: float — current temperature in Celsius
    • feels_like: float — feels-like temperature in Celsius
      Внимание! Отсутствует для MET Norway
    • pressure: integer — atmospheric pressure in hPa
    • humidity: integer — humidity in %
    • precipitation: integer — precipitation probability in %
      Внимание! Отсутствует для MET Norway
    • wind: integer — wind direction in degrees
    • wind_speed: float — wind speed in m/s
    • temp_low: float — today’s low temperature in Celsius
    • temp_high: float — today’s high temperature in Celsius
    • sunrise_today: integer — today’s sunrise timestamp in UNIXTIMESTAMP format
    • sunset_today: integer — today’s sunset timestamp in UNIXTIMESTAMP format
    • sunrise_tomorrow: integer — tomorrow’s sunrise timestamp in UNIXTIMESTAMP format
    • sunset_tomorrow: integer — tomorrow’s sunset timestamp in UNIXTIMESTAMP format
    • aqi: associative array — air quality index
      • level: integer — air quality index level
      • value: integer — air quality index value

Example Response

https://api.p2u.io
{
	"response": 103,
	"msg": "Free for beta tester",
	"expires": 0,
	"qr": [
		"11111110111011010110101111111",
		"10000010111001001101001000001",
		"10111010101100110110101011101",
		"10111010110101000001001011101",
		"10111010000001010100001011101",
		"10000010100110001101001000001",
		"11111110101010101010101111111",
		"00000000010010110111100000000",
		"11001110000100100100100101111",
		"11111100011011011010011111111",
		"01111011100111111100101000001",
		"01111100101100110111011011011",
		"00110110101010100101110000010",
		"11001000010001011000001011111",
		"01101010001001110100000001101",
		"10111101100010100101100110011",
		"01010111111100110100100100010",
		"10000100111011011000101111011",
		"00000110110110110100100000101",
		"00111100011100001100101100011",
		"11110111110010100111111111001",
		"00000000111001011101100010001",
		"11111110010001011111101011101",
		"10000010100010100111100010010",
		"10111010101101100111111111001",
		"10111010010010110000010000001",
		"10111010001111111110000001111",
		"10000010111101011111101101011",
		"11111110100011011110110010010"
	],
	"bg": {
		"value": -102,
		"date": 1730546101,
		"direction": ""
	},
	"weather": {
		"provider": 1,
		"weather": [
			89
		],
		"temp": 0.27,
		"feels_like": -3.14,
		"pressure": 999,
		"humidity": 78,
		"precipitation": 0,
		"wind": 120,
		"wind_speed": 2.96,
		"temp_low": -3.8,
		"temp_high": 0.27,
		"sunrise_today": 1730527969,
		"sunset_today": 1730551770,
		"sunrise_tomorrow": 1730614492,
		"sunset_tomorrow": 1730638051,
		"aqi": {
			"level": 1,
			"value": 38
		}
	}
}

Notes

  • Requests with bg require a connection to the NightScout app.
  • For every request with a code, the API automatically checks the code status and activates it if inactive.
  • Please note that API parameters may be updated or modified over time to improve functionality, compatibility, and security. It is recommended to periodically review the API documentation for any changes that might affect integration or usage.

Garmin

For a detailed description of Garmin SDK weather functions and constants, refer to this link. You may store values obtained from the API or results from Garmin SDK weather functions, depending on the selected weather provider, to ensure consistency in displaying values on the screen.

ID 描述 Day Night
0 清除
0x53

0x54
40 Fair
23 Mostly clear
0x55

0x56
1 Partly cloudy
0x57

0x58
22 Partly clear
2 Mostly cloudy
0x59
52 Thin clouds
20 Cloudy
0x5A
45 Cloudy chance of rain
31 Drizzle
0x3E
14 Light rain
0x42
24 Light showers
3 Rain
0x43
25 Showers
27 Chance of showers
0x46
11 Scattered showers
15 Heavy rain
26 Heavy showers
28 Chance of thunderstorms
0x36

0x37
12 Scattered thunderstorms
0x38
6 Thunderstorms
0x39
8 Fog
0x4E
9 Hazy
29 Mist
39 Haze
30 Dust
0x4F
35 Sand
33 Smoke
38 Volcanic ash
37 Sandstorm
13 Unknown precipitation
5 Windy
0x52
36 Squall
48 Flurries
32 Tornado
0x50
41 Hurricane
42 Tropical storm
50 Sleet
0x45
7 Wintry mix
18 Light rain snow
19 Heavy rain snow
21 Rain snow
49 Freezing rain
44 Chance of rain snow
47 Cloudy chance of rain snow
34 Ice
51 Ice snow
43 Chance of snow
0x4C

0x4D
16 Light snow
46 Cloudy chance of snow
0x4A
4 Snow
17 Heavy snow
0x4B
10 Hail
0x3A

Open Weather Map

Check out the icon set for OpenWeatherMap as an example here.

ID 描述 Day Night
2xx Thunderstorm
200 Thunderstorm with light rain
0x36

0x37
201 Thunderstorm with rain
0x38
202 Thunderstorm with heavy rain
210 Light thunderstorm
211 Thunderstorm
0x39
212 Heavy thunderstorm
0x3B
221 Ragged thunderstorm
230 Thunderstorm with light drizzle
0x3A
231 Thunderstorm with drizzle
232 Thunderstorm with heavy drizzle
3xx Drizzle
300 Light intensity drizzle
0x3C

0x3D
301 Drizzle
0x3E
302 Heavy intensity drizzle
0x3F
310 Light intensity drizzle rain
0x40
311 Drizzle rain
312 Heavy intensity drizzle rain
0x41
313 Shower rain and drizzle
314 Heavy shower rain and drizzle
321 Shower drizzle
5xx Rain
500 Light rain
0x42
501 Moderate rain
0x43
502 Heavy intensity rain
0x44
503 Very heavy rain
504 Extreme rain
511 Freezing rain
0x45
520 Light intensity shower rain
0x46
521 Shower rain
522 Heavy intensity shower rain
531 Ragged shower rain
6xx Snow
600 Light snow
0x4C

0x4D
601 Snow
0x4A
602 Heavy snow
611 Sleet
0x45
612 Light shower sleet
613 Shower sleet
615 Light rain and snow
616 Rain and snow
620 Light shower snow
0x4B
621 Shower snow
622 Heavy shower snow
7xx Atmosphere
701 Mist
0x4E
711 Smoke
0x4F
721 Haze
731 Sand/ dust whirls
741 Fog
751 Sand
0x4F
761 Dust
762 Volcanic ash
771 Squalls
0x52
781 Tornado
0x50
800 清除
800 Clear sky
0x53

0x54
80x Clouds
801 Few clouds 11-25%
0x55

0x56
802 Scattered clouds 25-50%
0x57

0x58
803 Broken clouds 51-84%
0x59
804 Overcast clouds 85-100%
0x5A

QWeather

You can check out the original set of weather icons by clicking here

ID 描述 Day Night
302 Thundershower
0x36

0x37
303 Heavy Thunderstorm
0x38
310 Rainstorm
0x39
317 Rainstorm to Heavy Rainstorm
304 Hail
0x3A
311 Heavy Rainstorm
0x3B
312 Severe Rainstorm
318 Heavy to Severe Rainstorm
309 Drizzle Rain
0x3C

0x3D
404 Sleet
0x3E
305 Light Rain
0x42
314 Light to Moderate Rain
306 Moderate Rain
0x43
315 Moderate to Heavy Rain
399 Rain
308 Extreme Rain
0x44
316 Heavy Rain to Rainstorm
313 Freezing Rain
0x45
405 Rain and Snow
300 Shower Rain
0x46
301 Heavy Shower Rain
307 Heavy Rain
350 Shower Rain
351 Heavy Shower Rain
400 Light Snow
0x4C

0x4D
408 Light to Moderate Snow
499 Snow
401 Moderate Snow
0x4A
402 Heavy Snow
409 Moderate to Heavy Snow
410 Heavy Snow to Snowstorm
403 Snowstorm
0x4B
406 Shower Rain and Snow
407 Snow Flurry
456 Shower Rain and Snow
457 Snow Flurry
503 Sand
0x4E
504 Dust
507 Duststorm
508 Sandstorm
511 Moderate Haze
512 Heavy Haze
513 Severe Haze
500 Mist
0x4F
501 Fog
502 Haze
509 Dense Fog
510 Strong Fog
514 Heavy Fog
515 Extra Heavy Fog
100 Sunny
0x53

0x54
150 清除
101 Cloudy
0x55

0x56
151 Cloudy
102 Few Clouds
0x57

0x58
152 Few Clouds
103 Partly Cloudy
0x59
153 Partly Cloudy
104 Overcast
0x5A

MET Weather

Check out the icon set for MET Weather as an example here.

ID 描述 Day Night
lightrainshowers Light rain showers
0x36

0x37
lightrainshowersandthunder Light rain showers and thunder
rainshowersandthunder Rain showers and thunder
heavyrainshowersandthunder Heavy rain showers and thunder
heavyrainandthunder Heavy rain and thunder
0x38
rainandthunder Rain and thunder
lightrainandthunder Light rain and thunder
0x39
heavysleetandthunder Heavy sleet and thunder
0x3B
lightsleetandthunder Light sleet and thunder
0x3A
lightssleetshowersandthunder Light sleet showers and thunder
sleetandthunder Sleet and thunder
lightsleetshowers Light sleet showers
0x3C

0x3D
sleetshowers Sleet showers
sleetshowersandthunder Sleet showers and thunder
heavysleetshowers Heavy sleet showers
heavysleetshowersandthunder Heavy sleet showers and thunder
lightsleet Light sleet
0x3E
sleet Sleet
0x3F
heavysleet Heavy sleet
0x45
lightrain Light rain
0x42
rain Rain
0x43
heavyrain Heavy rain
0x44
rainshowers Rain showers
0x46
heavyrainshowers Heavy rain showers
heavysnow Heavy snow
0x4B
heavysnowandthunder Heavy snow and thunder
snow Snow
snowandthunder Snow and thunder
lightsnowshowers Light snow showers
0x4C

0x4D
lightssnowshowersandthunder Light snow showers and thunder
snowshowers Snow showers
snowshowersandthunder Snow showers and thunder
heavysnowshowers Heavy snow showers
heavysnowshowersandthunder Heavy snow showers and thunder
lightsnow Light snow
0x4A
lightsnowandthunder Light snow and thunder
fog Fog
0x4F
clearsky Clear sky
0x53

0x54
fair Fair
0x55

0x56
partlycloudy Partly cloudy
0x57

0x58
cloudy Cloudy
0x59