Skip to content

Commit

Permalink
Merge pull request #3093 from mojinxun/feature/urlscheme_nfc
Browse files Browse the repository at this point in the history
Feature/urlscheme nfc
  • Loading branch information
JeffreySu authored Nov 14, 2024
2 parents 096816e + 24c5169 commit fe00126
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ public static GenerateSchemeJsonResult GenerateScheme(string accessTokenOrAppId,
}, accessTokenOrAppId);
}

/// <summary>
/// 获取 NFC 的小程序 scheme
/// <para>该接口用于获取用于 NFC 的小程序 scheme 码,适用于 NFC 拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放,详见 NFC 标签打开小程序</para>
/// <para>详见<see langword="获取 NFC 的小程序 scheme" cref="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html"/></para>
/// <para>https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html</para>
/// </summary>
/// <param name="accessTokenOrAppId"></param>
/// <param name="jumpWxa">(必填)跳转到的目标小程序信息。</param>
/// <param name="isExpire">(非必填)生成的scheme码类型,到期失效:true,永久有效:false。</param>
/// <param name="expireTime">(非必填)到期失效的scheme码的失效时间,为Unix时间戳。生成的到期失效scheme码在该时间前有效。生成到期失效的scheme时必填。</param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static GenerateNFCSchemeJsonResult GenerateNFCScheme(string accessTokenOrAppId, GenerateNFCSchemeJumpWxa jumpWxa = null, string model_id = "",
string sn = null, int timeOut = Config.TIME_OUT)
{
return WxOpenApiHandlerWapper.TryCommonApi(accessToken =>
{
string urlFormat = Config.ApiMpHost + "/wxa/generatenfcscheme?access_token={0}";

var data = new
{
jump_wxa = jumpWxa,
model_id = model_id,
sn = sn
};

return CommonJsonSend.Send<GenerateNFCSchemeJsonResult>(accessToken, urlFormat, data, timeOut: timeOut,
jsonSetting: new CO2NET.Helpers.Serializers.JsonSetting(true));
}, accessTokenOrAppId);
}

#endregion

#region 异步方法
Expand Down Expand Up @@ -90,6 +121,37 @@ public static async Task<GenerateSchemeJsonResult> GenerateSchemeAsync(string ac
jsonSetting: new CO2NET.Helpers.Serializers.JsonSetting(true));
}, accessTokenOrAppId).ConfigureAwait(false);
}

/// <summary>
/// 获取 NFC 的小程序 scheme
/// <para>该接口用于获取用于 NFC 的小程序 scheme 码,适用于 NFC 拉起小程序的业务场景。目前仅针对国内非个人主体的小程序开放,详见 NFC 标签打开小程序</para>
/// <para>详见<see langword="获取 NFC 的小程序 scheme" cref="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html"/></para>
/// <para>https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html</para>
/// </summary>
/// <param name="accessTokenOrAppId"></param>
/// <param name="jumpWxa">(必填)跳转到的目标小程序信息。</param>
/// <param name="isExpire">(非必填)生成的scheme码类型,到期失效:true,永久有效:false。</param>
/// <param name="expireTime">(非必填)到期失效的scheme码的失效时间,为Unix时间戳。生成的到期失效scheme码在该时间前有效。生成到期失效的scheme时必填。</param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static async Task<GenerateNFCSchemeJsonResult> GenerateNFCSchemeAsync(string accessTokenOrAppId, GenerateNFCSchemeJumpWxa jumpWxa = null, string model_id = "",
string sn = null, int timeOut = Config.TIME_OUT)
{
return await WxOpenApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
string urlFormat = Config.ApiMpHost + "/wxa/generatenfcscheme?access_token={0}";

var data = new
{
jump_wxa = jumpWxa,
model_id = model_id,
sn = sn
};

return CommonJsonSend.Send<GenerateNFCSchemeJsonResult>(accessToken, urlFormat, data, timeOut: timeOut,
jsonSetting: new CO2NET.Helpers.Serializers.JsonSetting(true));
}, accessTokenOrAppId).ConfigureAwait(false);
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Senparc.Weixin.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Senparc.Weixin.WxOpen.AdvancedAPIs.UrlScheme
{
/// <summary>
/// GenerateNFCScheme() 接口返回参数
/// </summary>
public class GenerateNFCSchemeJsonResult : WxJsonResult
{
/// <summary>
/// 小程序scheme码
/// </summary>
public string openlink { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2024 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

/*----------------------------------------------------------------
Copyright (C) 2024 Senparc
文件名:GenerateNFCSchemeJumpWxa.cs
文件功能描述:GenerateNFCScheme() 接口中的 jumpWxa 参数
----------------------------------------------------------------*/


namespace Senparc.Weixin.WxOpen.AdvancedAPIs.UrlScheme
{
/// <summary>
///
/// </summary>
public class GenerateNFCSchemeJumpWxa
{
/// <summary>
/// (必填)通过scheme码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带query。path为空时会跳转小程序主页。
/// </summary>
public string path { get; set; }
/// <summary>
/// (必填)通过scheme码进入小程序时的query,最大128个字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~
/// </summary>
public string query { get; set; }
/// <summary>
/// (选填)默认值"release"。要打开的小程序版本。正式版为"release",体验版为"trial",开发版为"develop",仅在微信外打开时生效。
/// </summary>
public string env_version { get; set; }

/// <summary>
/// GenerateScheme() 接口中的 jumpWxa 参数
/// </summary>
/// <param name="path"></param>
/// <param name="query"></param>
/// <param name="env_version"></param>
public GenerateNFCSchemeJumpWxa(string path, string query, string env_version = null)
{
this.path = path ?? "";
this.query = query ?? "";
this.env_version = env_version ?? "release";
}
}
}

0 comments on commit fe00126

Please sign in to comment.