Skip to content

Commit

Permalink
MP v16.20.2 fix bug: self menu onfig result. PR #2963 / Issue #2804 感谢
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreySu committed Dec 2, 2023
1 parent 479ecb4 commit 5ed4239
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,37 @@ public void DeleteMenuTest()
Assert.IsNotNull(result);
Assert.AreEqual("ok", result.errmsg);
}


[TestMethod]
public void GetCurrentSelfMenuInfoTest()
{
var appIdOrFackAccessToken = base._senparcWeixinSetting.WeixinAppId;// "75_eGhUgdbNzwM8IcroXssnKN4sP9QSWPcMJUJe5Ka3UTTisGP_UorAZYLb1UCZyQtdsp798EwLdbURX-cfdbacKB-IuDJ_QHMnjTHYANlch3h8_YRAw_oyfZ4mwf8LODdACAUXM";//错误的AccessToken

var result = CommonApi.GetCurrentSelfMenuInfo(appIdOrFackAccessToken);

Console.WriteLine(result);
if (result.ErrorCodeValue == 0)
{
Assert.IsTrue(true);
}
else
{
Assert.IsTrue(false);
}

string json = "{\"is_menu_open\":1,\"selfmenu_info\":{\"button\":[{\"type\":\"click\",\"name\":\"今日歌曲\",\"key\":\"V1001_TODAY_MUSIC\"},{\"name\":\"菜单\",\"sub_button\":{\"list\":[{\"type\":\"view\",\"name\":\"搜索\",\"url\":\"http:\\/\\/www.soso.com\\/\"},{\"type\":\"click\",\"name\":\"赞一下我们\",\"key\":\"V1001_GOOD\"}]}}]}}";
try
{
var test = Newtonsoft.Json.JsonConvert.DeserializeObject<SelfMenuConfigResult>(json);
Console.WriteLine(test);
Assert.IsTrue(true);
}
catch (Exception)
{
Assert.IsTrue(false);
throw;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ and limitations under the License.
修改标识:JaneConan - 20230417
修改描述:v16.18.10.7 修复自定义菜单实体问题
修改标识:Senparc - 20231202
修改描述:v16.20.2 fix bug: self menu onfig result. PR #2963 / Issue #2804
----------------------------------------------------------------*/

using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
v16.18.14 JSSDKHelper.GetNoncestr() 弃用 MD5 加密方法
v16.19.0 MessageHandler 和客服接口支持长文本自动切割后连续发送
v16.20.1 添加 TemplateApi.AddTemplate() 参数
v16.20.2 添加“小程序虚拟支付 ”功能
v16.20.2 fix bug: self menu onfig result. PR #2963 / Issue #2804
</PackageReleaseNotes>
<RepositoryUrl>https://github.com/JeffreySu/WeiXinMPSDK</RepositoryUrl>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Senparc.Weixin.MP/Senparc.WeixinTests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace Senparc.WeixinTests
/// </summary>
public class BaseTest
{
protected static IServiceProvider _serviceProvider;
protected static SenparcSetting _senparcSetting;
protected static SenparcWeixinSetting _senparcWeixinSetting;
protected IServiceProvider _serviceProvider;
protected SenparcSetting _senparcSetting;
protected SenparcWeixinSetting _senparcWeixinSetting;

public BaseTest()
{
Expand Down Expand Up @@ -85,7 +85,7 @@ protected void RegisterStart()
/// <summary>
/// 注册 IServiceCollection 和 MemoryCache
/// </summary>
public static void RegisterServiceCollection()
public void RegisterServiceCollection()
{
var serviceCollection = new ServiceCollection();
var configBuilder = new ConfigurationBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Senparc.Weixin.MP;
using Senparc.Weixin.MP.CommonAPIs;
using System;
using System.Collections.Generic;
using System.Text;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Senparc.WeixinTests.vs2017.CommonApis
{
Expand All @@ -13,11 +9,12 @@ public class CommonJsonSendTests : BaseTest
[TestMethod]
public void SendThrowTest()
{
var fakeAccessToken = "22_q1nIlrqQ1brYqvp-8xPV3eIWWSJ9LU_qCxs3AaTMVjv74WyD1XDovWi4SkMX6xfykOCMoobaVpzu-lspCsCWIo5u6DGw31tS3ZmFw4q7wEDkXOmBaTtCeQuhlvhsalkenoRCKTLckTnVCkXbTWZlCJANQT1";//错误的AccessToken
var appIdOrFackAccessToken = base._senparcWeixinSetting.WeixinAppId;// "22_q1nIlrqQ1brYqvp-8xPV3eIWWSJ9LU_qCxs3AaTMVjv74WyD1XDovWi4SkMX6xfykOCMoobaVpzu-lspCsCWIo5u6DGw31tS3ZmFw4q7wEDkXOmBaTtCeQuhlvhsalkenoRCKTLckTnVCkXbTWZlCJANQT1";//错误的AccessToken

try
{
//Senparc.Weixin.Config.ThrownWhenJsonResultFaild = true;//抛出异常(默认就是true)
var result = Senparc.Weixin.MP.AdvancedAPIs.UrlApi.ShortUrl(fakeAccessToken, "long2short", "https://sdk.weixin.senparc.com");
var result = Senparc.Weixin.MP.AdvancedAPIs.UrlApi.ShortUrl(appIdOrFackAccessToken, "long2short", "https://sdk.weixin.senparc.com");
Console.WriteLine("不应该到达这里");
Assert.Fail();//不应该到达这里
}
Expand All @@ -30,39 +27,11 @@ public void SendThrowTest()


Senparc.Weixin.Config.ThrownWhenJsonResultFaild = false;//不抛出异常
var result2 = Senparc.Weixin.MP.AdvancedAPIs.UrlApi.ShortUrl(fakeAccessToken, "long2short", "https://sdk.weixin.senparc.com");
var result2 = Senparc.Weixin.MP.AdvancedAPIs.UrlApi.ShortUrl(appIdOrFackAccessToken, "long2short", "https://sdk.weixin.senparc.com");
Console.WriteLine(result2);

Senparc.Weixin.Config.ThrownWhenJsonResultFaild = true;//还原
}

[TestMethod]
public void GetCurrentSelfMenuInfoTest()
{
var result = CommonApi.GetCurrentSelfMenuInfo("75_eGhUgdbNzwM8IcroXssnKN4sP9QSWPcMJUJe5Ka3UTTisGP_UorAZYLb1UCZyQtdsp798EwLdbURX-cfdbacKB-IuDJ_QHMnjTHYANlch3h8_YRAw_oyfZ4mwf8LODdACAUXM");

Console.WriteLine(result);
if (result.ErrorCodeValue == 0)
{
Assert.IsTrue(true);
}
else
{
Assert.IsTrue(false);
}

string json = "{\"is_menu_open\":1,\"selfmenu_info\":{\"button\":[{\"type\":\"click\",\"name\":\"今日歌曲\",\"key\":\"V1001_TODAY_MUSIC\"},{\"name\":\"菜单\",\"sub_button\":{\"list\":[{\"type\":\"view\",\"name\":\"搜索\",\"url\":\"http:\\/\\/www.soso.com\\/\"},{\"type\":\"click\",\"name\":\"赞一下我们\",\"key\":\"V1001_GOOD\"}]}}]}}";
try
{
var test = Newtonsoft.Json.JsonConvert.DeserializeObject<SelfMenuConfigResult>(json);
Console.WriteLine(test);
Assert.IsTrue(true);
}
catch (Exception)
{
Assert.IsTrue(false);
throw;
}
}
}
}

0 comments on commit 5ed4239

Please sign in to comment.