Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加更新模版卡片消息 #2850

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ and limitations under the License.
using Senparc.Weixin.Helpers;
using Senparc.Weixin.Work.AdvancedAPIs.Mass;
using Senparc.Weixin.Work.AdvancedAPIs.Mass.SendTemplateCard;
using Senparc.Weixin.Work.AdvancedAPIs.Mass.UpdateTemplateCard;
using Senparc.Weixin.Work.CommonAPIs;
using Senparc.Weixin.Work.Entities;

Expand All @@ -84,6 +85,7 @@ namespace Senparc.Weixin.Work.AdvancedAPIs
public static class MassApi
{
private static string _urlFormat = Config.ApiWorkHost + "/cgi-bin/message/send?access_token={0}";
private static string _updateTemplateCardFormat = Config.ApiWorkHost + "/cgi-bin/message/update_template_card?access_token={0}";
private static string _taskUrlFormat = Config.ApiWorkHost + "/cgi-bin/message/update_taskcard?access_token={0}";
private static string _recallUrlFormat = Config.ApiWorkHost + "/cgi-bin/message/recall?access_token={0}";

Expand Down Expand Up @@ -575,6 +577,23 @@ public static MassResult SendTemplateCard(string accessTokenOrAppKey, SendTempla
}, accessTokenOrAppKey);
}

/// <summary>
/// 更新模版卡片消息
/// https://developer.work.weixin.qq.com/document/path/94888
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static MassResult UpdateTemplateCard(string accessTokenOrAppKey, UpdateTemplateCardRequest data, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
JsonSetting jsonSetting = new JsonSetting(true);
return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<MassResult>(accessToken, _updateTemplateCardFormat, data, CommonJsonSendType.POST, timeOut, jsonSetting: jsonSetting);
}, accessTokenOrAppKey);
}

#endregion

/// <summary>
Expand Down Expand Up @@ -1095,6 +1114,23 @@ public static async Task<MassResult> SendTemplateCardAsync(string accessTokenOrA
}, accessTokenOrAppKey);
}

/// <summary>
/// 【异步方法】更新模版卡片消息
/// https://developer.work.weixin.qq.com/document/path/94888
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static async Task<MassResult> UpdateTemplateCardAsync(string accessTokenOrAppKey, UpdateTemplateCardRequest data, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
JsonSetting jsonSetting = new JsonSetting(true);
return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<MassResult>(accessToken, _updateTemplateCardFormat, data, CommonJsonSendType.POST, timeOut, jsonSetting: jsonSetting);
}, accessTokenOrAppKey);
}

#endregion


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public class Card_Image
public class Template_Card_ButtonInteraction : Template_CardWithJumpListBase
{
public Checkbox checkbox { get; set; }
public Submit_Button submit_button { get; set; }
public Button_List[] button_list { get; set; }

public string sub_title_text { get; set; }
public Template_Card_ButtonInteraction()
Expand All @@ -181,10 +181,16 @@ public class Option_List
public bool is_checked { get; set; }
}

public class Submit_Button
public class Button_List
{
public string text { get; set; }
public string key { get; set; }

public int type { get; set; }

public int style { get; set; }

public string url { get; set; }
}

}
Expand Down Expand Up @@ -264,7 +270,14 @@ public class Option_List

}


public class Template_Card_Button : Template_CardBase
{
public Button button { get; set; }
public class Button
{
public string replace_name { get; set; }
}
}
#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Senparc.Weixin.Work.AdvancedAPIs.Chat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Senparc.Weixin.Work.AdvancedAPIs.Mass.UpdateTemplateCard
{
public class UpdateTemplateCardRequest
{
public string[] userids { get; set; }
public int[] partyids { get; set; }

public int[] tagids { get; set; }

public int atall { get;set; }

public int agentid { get; set; }

public string response_code { get; set; }

public int enable_id_trans { get; set; } = 0;

public SendTemplateCard.Template_CardBase template_card { get; private set; }

public Button button { get; set; }

UpdateTemplateCardRequest() {

}

public UpdateTemplateCardRequest(SendTemplateCard.Template_CardBase templateCard): this()
{
template_card = templateCard;
}

public class Button
{
public string replace_name { get; set; }
}
}
}