Skip to content

Commit fe00126

Browse files
authored
Merge pull request #3093 from mojinxun/feature/urlscheme_nfc
Feature/urlscheme nfc
2 parents 096816e + 24c5169 commit fe00126

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

src/Senparc.Weixin.WxOpen/src/Senparc.Weixin.WxOpen/Senparc.Weixin.WxOpen/AdvancedAPIs/WxApp/UrlScheme/UrlSchemeApi.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,37 @@ public static GenerateSchemeJsonResult GenerateScheme(string accessTokenOrAppId,
5656
}, accessTokenOrAppId);
5757
}
5858

59+
/// <summary>
60+
/// 获取 NFC 的小程序 scheme
61+
/// <para>该接口用于获取用于 NFC 的小程序 scheme 码,适用于 NFC 拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放,详见 NFC 标签打开小程序</para>
62+
/// <para>详见<see langword="获取 NFC 的小程序 scheme" cref="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html"/></para>
63+
/// <para>https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html</para>
64+
/// </summary>
65+
/// <param name="accessTokenOrAppId"></param>
66+
/// <param name="jumpWxa">(必填)跳转到的目标小程序信息。</param>
67+
/// <param name="isExpire">(非必填)生成的scheme码类型,到期失效:true,永久有效:false。</param>
68+
/// <param name="expireTime">(非必填)到期失效的scheme码的失效时间,为Unix时间戳。生成的到期失效scheme码在该时间前有效。生成到期失效的scheme时必填。</param>
69+
/// <param name="timeOut"></param>
70+
/// <returns></returns>
71+
public static GenerateNFCSchemeJsonResult GenerateNFCScheme(string accessTokenOrAppId, GenerateNFCSchemeJumpWxa jumpWxa = null, string model_id = "",
72+
string sn = null, int timeOut = Config.TIME_OUT)
73+
{
74+
return WxOpenApiHandlerWapper.TryCommonApi(accessToken =>
75+
{
76+
string urlFormat = Config.ApiMpHost + "/wxa/generatenfcscheme?access_token={0}";
77+
78+
var data = new
79+
{
80+
jump_wxa = jumpWxa,
81+
model_id = model_id,
82+
sn = sn
83+
};
84+
85+
return CommonJsonSend.Send<GenerateNFCSchemeJsonResult>(accessToken, urlFormat, data, timeOut: timeOut,
86+
jsonSetting: new CO2NET.Helpers.Serializers.JsonSetting(true));
87+
}, accessTokenOrAppId);
88+
}
89+
5990
#endregion
6091

6192
#region 异步方法
@@ -90,6 +121,37 @@ public static async Task<GenerateSchemeJsonResult> GenerateSchemeAsync(string ac
90121
jsonSetting: new CO2NET.Helpers.Serializers.JsonSetting(true));
91122
}, accessTokenOrAppId).ConfigureAwait(false);
92123
}
124+
125+
/// <summary>
126+
/// 获取 NFC 的小程序 scheme
127+
/// <para>该接口用于获取用于 NFC 的小程序 scheme 码,适用于 NFC 拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放,详见 NFC 标签打开小程序</para>
128+
/// <para>详见<see langword="获取 NFC 的小程序 scheme" cref="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html"/></para>
129+
/// <para>https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html</para>
130+
/// </summary>
131+
/// <param name="accessTokenOrAppId"></param>
132+
/// <param name="jumpWxa">(必填)跳转到的目标小程序信息。</param>
133+
/// <param name="isExpire">(非必填)生成的scheme码类型,到期失效:true,永久有效:false。</param>
134+
/// <param name="expireTime">(非必填)到期失效的scheme码的失效时间,为Unix时间戳。生成的到期失效scheme码在该时间前有效。生成到期失效的scheme时必填。</param>
135+
/// <param name="timeOut"></param>
136+
/// <returns></returns>
137+
public static async Task<GenerateNFCSchemeJsonResult> GenerateNFCSchemeAsync(string accessTokenOrAppId, GenerateNFCSchemeJumpWxa jumpWxa = null, string model_id = "",
138+
string sn = null, int timeOut = Config.TIME_OUT)
139+
{
140+
return await WxOpenApiHandlerWapper.TryCommonApiAsync(async accessToken =>
141+
{
142+
string urlFormat = Config.ApiMpHost + "/wxa/generatenfcscheme?access_token={0}";
143+
144+
var data = new
145+
{
146+
jump_wxa = jumpWxa,
147+
model_id = model_id,
148+
sn = sn
149+
};
150+
151+
return CommonJsonSend.Send<GenerateNFCSchemeJsonResult>(accessToken, urlFormat, data, timeOut: timeOut,
152+
jsonSetting: new CO2NET.Helpers.Serializers.JsonSetting(true));
153+
}, accessTokenOrAppId).ConfigureAwait(false);
154+
}
93155
#endregion
94156
}
95157
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Senparc.Weixin.Entities;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Senparc.Weixin.WxOpen.AdvancedAPIs.UrlScheme
9+
{
10+
/// <summary>
11+
/// GenerateNFCScheme() 接口返回参数
12+
/// </summary>
13+
public class GenerateNFCSchemeJsonResult : WxJsonResult
14+
{
15+
/// <summary>
16+
/// 小程序scheme码
17+
/// </summary>
18+
public string openlink { get; set; }
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#region Apache License Version 2.0
2+
/*----------------------------------------------------------------
3+
4+
Copyright 2024 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
7+
except in compliance with the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software distributed under the
12+
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
either express or implied. See the License for the specific language governing permissions
14+
and limitations under the License.
15+
16+
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
17+
18+
----------------------------------------------------------------*/
19+
#endregion Apache License Version 2.0
20+
21+
/*----------------------------------------------------------------
22+
Copyright (C) 2024 Senparc
23+
24+
文件名:GenerateNFCSchemeJumpWxa.cs
25+
文件功能描述:GenerateNFCScheme() 接口中的 jumpWxa 参数
26+
27+
----------------------------------------------------------------*/
28+
29+
30+
namespace Senparc.Weixin.WxOpen.AdvancedAPIs.UrlScheme
31+
{
32+
/// <summary>
33+
///
34+
/// </summary>
35+
public class GenerateNFCSchemeJumpWxa
36+
{
37+
/// <summary>
38+
/// (必填)通过scheme码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带query。path为空时会跳转小程序主页。
39+
/// </summary>
40+
public string path { get; set; }
41+
/// <summary>
42+
/// (必填)通过scheme码进入小程序时的query,最大128个字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~
43+
/// </summary>
44+
public string query { get; set; }
45+
/// <summary>
46+
/// (选填)默认值"release"。要打开的小程序版本。正式版为"release",体验版为"trial",开发版为"develop",仅在微信外打开时生效。
47+
/// </summary>
48+
public string env_version { get; set; }
49+
50+
/// <summary>
51+
/// GenerateScheme() 接口中的 jumpWxa 参数
52+
/// </summary>
53+
/// <param name="path"></param>
54+
/// <param name="query"></param>
55+
/// <param name="env_version"></param>
56+
public GenerateNFCSchemeJumpWxa(string path, string query, string env_version = null)
57+
{
58+
this.path = path ?? "";
59+
this.query = query ?? "";
60+
this.env_version = env_version ?? "release";
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)