优化:飞书发送通道允许选择消息类型(纯文本/消息卡片)

pull/127/head
pppscn 3 years ago
parent bf5547d84b
commit 8d90548049

@ -1636,9 +1636,11 @@ public class SenderActivity extends AppCompatActivity {
final EditText editTextFeishuWebhook = view1.findViewById(R.id.editTextFeishuWebhook);
final ClearEditText editTextFeishuSecret = view1.findViewById(R.id.editTextFeishuSecret);
final RadioGroup radioGroupFeishuMsgType = view1.findViewById(R.id.radioGroupFeishuMsgType);
if (feiShuSettingVo != null) {
editTextFeishuWebhook.setText(feiShuSettingVo.getWebhook());
editTextFeishuSecret.setText(feiShuSettingVo.getSecret());
radioGroupFeishuMsgType.check(feiShuSettingVo.getMsgTypeCheckId());
}
Button buttonOk = view1.findViewById(R.id.buttonOk);
@ -1660,12 +1662,13 @@ public class SenderActivity extends AppCompatActivity {
String webHook = editTextFeishuWebhook.getText().toString().trim();
String secret = editTextFeishuSecret.getText().trim();
String msgType = radioGroupFeishuMsgType.getCheckedRadioButtonId() == R.id.radioFeishuMsgTypeText ? "text" : "interactive";
if (!CommonUtil.checkUrl(webHook, false)) {
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
return;
}
FeiShuSettingVo feiShuSettingVoNew = new FeiShuSettingVo(webHook, secret);
FeiShuSettingVo feiShuSettingVoNew = new FeiShuSettingVo(webHook, secret, msgType);
if (isClone || senderModel == null) {
SenderModel newSenderModel = new SenderModel();
newSenderModel.setName(senderName);
@ -1699,6 +1702,7 @@ public class SenderActivity extends AppCompatActivity {
buttonTest.setOnClickListener(view -> {
String webHook = editTextFeishuWebhook.getText().toString().trim();
String secret = editTextFeishuSecret.getText().trim();
String msgType = radioGroupFeishuMsgType.getCheckedRadioButtonId() == R.id.radioFeishuMsgTypeText ? "text" : "interactive";
if (!CommonUtil.checkUrl(webHook, false)) {
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
return;
@ -1706,7 +1710,7 @@ public class SenderActivity extends AppCompatActivity {
try {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderFeishuMsg.sendMsg(0, handler, null, webHook, secret, smsVo.getMobile(), new Date(), smsVo.getSmsVoForSend());
SenderFeishuMsg.sendMsg(0, handler, null, webHook, secret, msgType, smsVo.getMobile(), new Date(), smsVo.getSmsVoForSend());
} catch (Exception e) {
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
e.printStackTrace();

@ -1,5 +1,7 @@
package com.idormy.sms.forwarder.model.vo;
import com.idormy.sms.forwarder.R;
import java.io.Serializable;
import lombok.Data;
@ -8,12 +10,22 @@ import lombok.Data;
public class FeiShuSettingVo implements Serializable {
private String webhook;
private String secret;
private String msgType;
public FeiShuSettingVo() {
}
public FeiShuSettingVo(String webhook, String secret) {
public FeiShuSettingVo(String webhook, String secret, String msgType) {
this.webhook = webhook;
this.secret = secret;
this.msgType = msgType;
}
public int getMsgTypeCheckId() {
if (msgType == null || msgType.equals("interactive")) {
return R.id.radioFeishuMsgTypeInteractive;
} else {
return R.id.radioFeishuMsgTypeText;
}
}
}

@ -346,7 +346,7 @@ public class SendUtil {
FeiShuSettingVo feiShuSettingVo = JSON.parseObject(senderModel.getJsonSetting(), FeiShuSettingVo.class);
if (feiShuSettingVo != null) {
try {
SenderFeishuMsg.sendMsg(logId, handError, retryInterceptor, feiShuSettingVo.getWebhook(), feiShuSettingVo.getSecret(), smsVo.getMobile(), smsVo.getDate(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
SenderFeishuMsg.sendMsg(logId, handError, retryInterceptor, feiShuSettingVo.getWebhook(), feiShuSettingVo.getSecret(), feiShuSettingVo.getMsgType(), smsVo.getMobile(), smsVo.getDate(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: feishu error " + e.getMessage());

@ -90,7 +90,7 @@ public class SenderFeishuMsg extends SenderBaseMsg {
" }\n" +
"}";
public static void sendMsg(final long logId, final Handler handError, final RetryIntercepter retryInterceptor, String webhook, String secret, String from, Date date, String content) throws Exception {
public static void sendMsg(final long logId, final Handler handError, final RetryIntercepter retryInterceptor, String webhook, String secret, String msgType, String from, Date date, String content) throws Exception {
Log.i(TAG, "sendMsg webhook:" + webhook + " secret:" + secret + " content:" + content);
if (webhook == null || webhook.isEmpty()) {
@ -117,8 +117,15 @@ public class SenderFeishuMsg extends SenderBaseMsg {
}
//组装报文
textMsgMap.put("msg_type", "interactive");
textMsgMap.put("card", "${CARD_BODY}");
if (msgType == null || msgType.equals("interactive")) {
textMsgMap.put("msg_type", "interactive");
textMsgMap.put("card", "${CARD_BODY}");
} else {
textMsgMap.put("msg_type", "text");
Map contentMap = new HashMap();
contentMap.put("text", content);
textMsgMap.put("content", contentMap);
}
Log.i(TAG, "requestUrl:" + webhook);
final String requestMsg = JSON.toJSONString(textMsgMap).replace("\"${CARD_BODY}\"", buildMsg(from, date, content));

@ -90,6 +90,45 @@
app:showEye="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/feishu_msg_type"
android:textStyle="bold" />
<RadioGroup
android:id="@+id/radioGroupFeishuMsgType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radioFeishuMsgTypeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/feishu_msg_type_text" />
<RadioButton
android:id="@+id/radioFeishuMsgTypeInteractive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/feishu_msg_type_interactive" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

@ -144,6 +144,9 @@
<string name="email_title">Email Title</string>
<string name="feishu_webhook">Webhook</string>
<string name="feishu_secret">Secret (optional)</string>
<string name="feishu_msg_type">Msg Type</string>
<string name="feishu_msg_type_text">Text</string>
<string name="feishu_msg_type_interactive">Interactive</string>
<string name="Corp_ID">Corp ID</string>
<string name="Agent_ID">Agent ID</string>
<string name="App_Secret">App Secret</string>

@ -144,6 +144,9 @@
<string name="email_title">邮件主题</string>
<string name="feishu_webhook">Webhook 地址</string>
<string name="feishu_secret">加签 Secret (没有可不填)</string>
<string name="feishu_msg_type">消息类型</string>
<string name="feishu_msg_type_text">纯文本</string>
<string name="feishu_msg_type_interactive">消息卡片</string>
<string name="Corp_ID">企业ID</string>
<string name="Agent_ID">应用AgentId</string>
<string name="App_Secret">应用Secret</string>

Loading…
Cancel
Save