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

添加功能:【企业微信】发送机器人消息支持模板卡片消息 & 【企业微信】客服消息支持以客服纬度查询 #2937

Merged
merged 3 commits into from
Feb 21, 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 @@ -2,6 +2,7 @@

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.article.NewArticle;
import me.chanjar.weixin.cp.bean.message.WxCpGroupRobotMessage;

import java.util.List;

Expand Down Expand Up @@ -96,4 +97,13 @@ public interface WxCpGroupRobotService {
* @throws WxErrorException 异常
*/
void sendFile(String webhookUrl, String mediaId) throws WxErrorException;

/**
* 发送模板卡片消息
* @param webhookUrl
* @param wxCpGroupRobotMessage
* @throws WxErrorException
*/
void sendTemplateCardMessage(String webhookUrl, WxCpGroupRobotMessage wxCpGroupRobotMessage) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ WxCpKfServiceStateTransResp transServiceState(String openKfid, String externalUs
* @return 微信消息 wx cp kf msg list resp
* @throws WxErrorException 异常
*/
@Deprecated
WxCpKfMsgListResp syncMsg(String cursor, String token, Integer limit, Integer voiceFormat)
throws WxErrorException;

WxCpKfMsgListResp syncMsg(String cursor, String token, Integer limit, Integer voiceFormat,String open_kfid)
throws WxErrorException;

/**
* 发送消息
* 当微信客户处于“新接入待处理”或“由智能助手接待”状态下,可调用该接口给用户发送消息。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.message.TemplateCardMessage;

import java.util.List;

Expand Down Expand Up @@ -48,4 +49,5 @@ void updateTemplateCardButton(List<String> userIds, List<Integer> partyIds,
List<Integer> tagIds, Integer atAll, String responseCode,
String replaceName) throws WxErrorException;

void updateTemplateCardButton(TemplateCardMessage templateCardMessage) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ public void sendFile(String webhookUrl, String mediaId) throws WxErrorException
.setMediaId(mediaId).toJson());
}

@Override
public void sendTemplateCardMessage(String webhookUrl, WxCpGroupRobotMessage wxCpGroupRobotMessage) throws WxErrorException {
this.cpService.postWithoutToken(webhookUrl, wxCpGroupRobotMessage.toJson());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ public WxCpKfMsgListResp syncMsg(String cursor, String token, Integer limit, Int
return WxCpKfMsgListResp.fromJson(responseContent);
}

@Override
public WxCpKfMsgListResp syncMsg(String cursor, String token, Integer limit, Integer voiceFormat, String openKfId) throws WxErrorException {
String url = cpService.getWxCpConfigStorage().getApiUrl(SYNC_MSG);

JsonObject json = new JsonObject();
if (cursor!=null) {
json.addProperty("cursor", cursor);
}
if (token!=null) {
json.addProperty("token", token);
}
if (limit!=null) {
json.addProperty("limit", limit);
}
if (voiceFormat!=null) {
json.addProperty("voice_format", voiceFormat);
}
if (openKfId != null) {
json.addProperty("open_kfid", openKfId);
}

String responseContent = cpService.post(url, json);
return WxCpKfMsgListResp.fromJson(responseContent);
}

@Override
public WxCpKfMsgSendResp sendMsg(WxCpKfMsgSendRequest request) throws WxErrorException {
String url = cpService.getWxCpConfigStorage().getApiUrl(SEND_MSG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpTaskCardService;
import me.chanjar.weixin.cp.bean.message.TemplateCardMessage;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -60,4 +61,10 @@ public void updateTemplateCardButton(List<String> userIds, List<Integer> partyId
this.mainService.post(url, WxGsonBuilder.create().toJson(data));

}

@Override
public void updateTemplateCardButton(TemplateCardMessage templateCardMessage) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_TEMPLATE_CARD);
this.mainService.post(url, WxGsonBuilder.create().toJson(templateCardMessage));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
package me.chanjar.weixin.cp.bean.message;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TemplateCardMessage implements Serializable {
private static final long serialVersionUID = 8833792280163704239L;

@JsonProperty("userids")
private List<String> userids;
@JsonProperty("partyids")
private List<Integer> partyids;
@JsonProperty("tagids")
private List<Integer> tagids;
@JsonProperty("atall")
private Integer atall;
@JsonProperty("agentid")
private Integer agentid;
@JsonProperty("response_code")
private String responseCode;
@JsonProperty("enable_id_trans")
private Integer enableIdTrans;
@JsonProperty("template_card")
private TemplateCardDTO templateCard;

@NoArgsConstructor
@Data
public static class TemplateCardDTO {
@JsonProperty("card_type")
private String cardType;
@JsonProperty("source")
private SourceDTO source;
@JsonProperty("main_title")
private MainTitleDTO mainTitle;
@JsonProperty("select_list")
private List<SelectListDTO> selectList;
@JsonProperty("submit_button")
private SubmitButtonDTO submitButton;
@JsonProperty("replace_text")
private String replaceText;

@JsonProperty("checkbox")
private CheckboxDTO checkbox;


@JsonProperty("action_menu")
private ActionMenuDTO actionMenu;
@JsonProperty("quote_area")
private QuoteAreaDTO quoteArea;
@JsonProperty("sub_title_text")
private String subTitleText;
@JsonProperty("horizontal_content_list")
private List<HorizontalContentListDTO> horizontalContentList;
@JsonProperty("card_action")
private CardActionDTO cardAction;
@JsonProperty("button_selection")
private ButtonSelectionDTO buttonSelection;
@JsonProperty("button_list")
private List<ButtonListDTO> buttonList;

@JsonProperty("image_text_area")
private ImageTextAreaDTO imageTextArea;
@JsonProperty("card_image")
private CardImageDTO cardImage;
@JsonProperty("vertical_content_list")
private List<MainTitleDTO> verticalContentList;
@JsonProperty("jump_list")
private List<JumpListDTO> jumpList;


@NoArgsConstructor
@Data
public static class SourceDTO {
@JsonProperty("icon_url")
private String iconUrl;
@JsonProperty("desc")
private String desc;
@JsonProperty("desc_color")
private Integer descColor;
}

@NoArgsConstructor
@Data
public static class ActionMenuDTO {
@JsonProperty("desc")
private String desc;
@JsonProperty("action_list")
private List<SubmitButtonDTO> actionList;
}

@NoArgsConstructor
@Data
public static class QuoteAreaDTO {
@JsonProperty("type")
private Integer type;
@JsonProperty("url")
private String url;
@JsonProperty("title")
private String title;
@JsonProperty("quote_text")
private String quoteText;
}

@NoArgsConstructor
@Data
public static class CardActionDTO {
@JsonProperty("type")
private Integer type;
@JsonProperty("url")
private String url;
@JsonProperty("appid")
private String appid;
@JsonProperty("pagepath")
private String pagepath;
}

@NoArgsConstructor
@Data
public static class ButtonSelectionDTO {
@JsonProperty("question_key")
private String questionKey;
@JsonProperty("title")
private String title;
@JsonProperty("option_list")
private List<SelectListDTO.OptionListDTO> optionList;
@JsonProperty("selected_id")
private String selectedId;
}

@NoArgsConstructor
@Data
public static class HorizontalContentListDTO {
@JsonProperty("keyname")
private String keyname;
@JsonProperty("value")
private String value;
@JsonProperty("type")
private Integer type;
@JsonProperty("url")
private String url;
@JsonProperty("media_id")
private String mediaId;
@JsonProperty("userid")
private String userid;
}

@NoArgsConstructor
@Data
public static class ButtonListDTO {
@JsonProperty("text")
private String text;
@JsonProperty("style")
private Integer style;
@JsonProperty("key")
private String key;
}


@NoArgsConstructor
@Data
public static class CheckboxDTO {
@JsonProperty("question_key")
private String questionKey;
@JsonProperty("option_list")
private List<OptionListDTO> optionList;
@JsonProperty("disable")
private Boolean disable;
@JsonProperty("mode")
private Integer mode;

@NoArgsConstructor
@Data
public static class OptionListDTO {
@JsonProperty("id")
private String id;
@JsonProperty("text")
private String text;
@JsonProperty("is_checked")
private Boolean isChecked;
}

}

@NoArgsConstructor
@Data
public static class MainTitleDTO {
@JsonProperty("title")
private String title;
@JsonProperty("desc")
private String desc;
}

@NoArgsConstructor
@Data
public static class SubmitButtonDTO {
@JsonProperty("text")
private String text;
@JsonProperty("key")
private String key;
}

@NoArgsConstructor
@Data
public static class SelectListDTO {
@JsonProperty("question_key")
private String questionKey;
@JsonProperty("title")
private String title;
@JsonProperty("selected_id")
private String selectedId;
@JsonProperty("disable")
private Boolean disable;
@JsonProperty("option_list")
private List<OptionListDTO> optionList;

@NoArgsConstructor
@Data
public static class OptionListDTO {
@JsonProperty("id")
private String id;
@JsonProperty("text")
private String text;
}
}

@NoArgsConstructor
@Data
public static class ImageTextAreaDTO {
@JsonProperty("type")
private Integer type;
@JsonProperty("url")
private String url;
@JsonProperty("title")
private String title;
@JsonProperty("desc")
private String desc;
@JsonProperty("image_url")
private String imageUrl;
}

@NoArgsConstructor
@Data
public static class CardImageDTO {
@JsonProperty("url")
private String url;
@JsonProperty("aspect_ratio")
private Double aspectRatio;
}

@NoArgsConstructor
@Data
public static class JumpListDTO {
@JsonProperty("type")
private Integer type;
@JsonProperty("title")
private String title;
@JsonProperty("url")
private String url;
@JsonProperty("appid")
private String appid;
@JsonProperty("pagepath")
private String pagepath;
}


}

}
Loading