mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 09:27:41 +08:00
优化:飞书发送通道允许选择消息类型(纯文本/消息卡片)
This commit is contained in:
parent
bf5547d84b
commit
8d90548049
@ -1636,9 +1636,11 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
final EditText editTextFeishuWebhook = view1.findViewById(R.id.editTextFeishuWebhook);
|
final EditText editTextFeishuWebhook = view1.findViewById(R.id.editTextFeishuWebhook);
|
||||||
final ClearEditText editTextFeishuSecret = view1.findViewById(R.id.editTextFeishuSecret);
|
final ClearEditText editTextFeishuSecret = view1.findViewById(R.id.editTextFeishuSecret);
|
||||||
|
final RadioGroup radioGroupFeishuMsgType = view1.findViewById(R.id.radioGroupFeishuMsgType);
|
||||||
if (feiShuSettingVo != null) {
|
if (feiShuSettingVo != null) {
|
||||||
editTextFeishuWebhook.setText(feiShuSettingVo.getWebhook());
|
editTextFeishuWebhook.setText(feiShuSettingVo.getWebhook());
|
||||||
editTextFeishuSecret.setText(feiShuSettingVo.getSecret());
|
editTextFeishuSecret.setText(feiShuSettingVo.getSecret());
|
||||||
|
radioGroupFeishuMsgType.check(feiShuSettingVo.getMsgTypeCheckId());
|
||||||
}
|
}
|
||||||
|
|
||||||
Button buttonOk = view1.findViewById(R.id.buttonOk);
|
Button buttonOk = view1.findViewById(R.id.buttonOk);
|
||||||
@ -1660,12 +1662,13 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
String webHook = editTextFeishuWebhook.getText().toString().trim();
|
String webHook = editTextFeishuWebhook.getText().toString().trim();
|
||||||
String secret = editTextFeishuSecret.getText().trim();
|
String secret = editTextFeishuSecret.getText().trim();
|
||||||
|
String msgType = radioGroupFeishuMsgType.getCheckedRadioButtonId() == R.id.radioFeishuMsgTypeText ? "text" : "interactive";
|
||||||
if (!CommonUtil.checkUrl(webHook, false)) {
|
if (!CommonUtil.checkUrl(webHook, false)) {
|
||||||
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
|
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FeiShuSettingVo feiShuSettingVoNew = new FeiShuSettingVo(webHook, secret);
|
FeiShuSettingVo feiShuSettingVoNew = new FeiShuSettingVo(webHook, secret, msgType);
|
||||||
if (isClone || senderModel == null) {
|
if (isClone || senderModel == null) {
|
||||||
SenderModel newSenderModel = new SenderModel();
|
SenderModel newSenderModel = new SenderModel();
|
||||||
newSenderModel.setName(senderName);
|
newSenderModel.setName(senderName);
|
||||||
@ -1699,6 +1702,7 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
buttonTest.setOnClickListener(view -> {
|
buttonTest.setOnClickListener(view -> {
|
||||||
String webHook = editTextFeishuWebhook.getText().toString().trim();
|
String webHook = editTextFeishuWebhook.getText().toString().trim();
|
||||||
String secret = editTextFeishuSecret.getText().trim();
|
String secret = editTextFeishuSecret.getText().trim();
|
||||||
|
String msgType = radioGroupFeishuMsgType.getCheckedRadioButtonId() == R.id.radioFeishuMsgTypeText ? "text" : "interactive";
|
||||||
if (!CommonUtil.checkUrl(webHook, false)) {
|
if (!CommonUtil.checkUrl(webHook, false)) {
|
||||||
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
|
ToastUtils.delayedShow(R.string.invalid_webhook, 3000);
|
||||||
return;
|
return;
|
||||||
@ -1706,7 +1710,7 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
try {
|
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));
|
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) {
|
} catch (Exception e) {
|
||||||
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
|
ToastUtils.delayedShow(getString(R.string.failed_to_fwd) + e.getMessage(), 3000);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.idormy.sms.forwarder.model.vo;
|
package com.idormy.sms.forwarder.model.vo;
|
||||||
|
|
||||||
|
import com.idormy.sms.forwarder.R;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -8,12 +10,22 @@ import lombok.Data;
|
|||||||
public class FeiShuSettingVo implements Serializable {
|
public class FeiShuSettingVo implements Serializable {
|
||||||
private String webhook;
|
private String webhook;
|
||||||
private String secret;
|
private String secret;
|
||||||
|
private String msgType;
|
||||||
|
|
||||||
public FeiShuSettingVo() {
|
public FeiShuSettingVo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeiShuSettingVo(String webhook, String secret) {
|
public FeiShuSettingVo(String webhook, String secret, String msgType) {
|
||||||
this.webhook = webhook;
|
this.webhook = webhook;
|
||||||
this.secret = secret;
|
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);
|
FeiShuSettingVo feiShuSettingVo = JSON.parseObject(senderModel.getJsonSetting(), FeiShuSettingVo.class);
|
||||||
if (feiShuSettingVo != null) {
|
if (feiShuSettingVo != null) {
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
LogUtil.updateLog(logId, 0, e.getMessage());
|
LogUtil.updateLog(logId, 0, e.getMessage());
|
||||||
Log.e(TAG, "senderSendMsg: feishu error " + e.getMessage());
|
Log.e(TAG, "senderSendMsg: feishu error " + e.getMessage());
|
||||||
|
@ -90,7 +90,7 @@ public class SenderFeishuMsg extends SenderBaseMsg {
|
|||||||
" }\n" +
|
" }\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);
|
Log.i(TAG, "sendMsg webhook:" + webhook + " secret:" + secret + " content:" + content);
|
||||||
|
|
||||||
if (webhook == null || webhook.isEmpty()) {
|
if (webhook == null || webhook.isEmpty()) {
|
||||||
@ -117,8 +117,15 @@ public class SenderFeishuMsg extends SenderBaseMsg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//组装报文
|
//组装报文
|
||||||
textMsgMap.put("msg_type", "interactive");
|
if (msgType == null || msgType.equals("interactive")) {
|
||||||
textMsgMap.put("card", "${CARD_BODY}");
|
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);
|
Log.i(TAG, "requestUrl:" + webhook);
|
||||||
final String requestMsg = JSON.toJSONString(textMsgMap).replace("\"${CARD_BODY}\"", buildMsg(from, date, content));
|
final String requestMsg = JSON.toJSONString(textMsgMap).replace("\"${CARD_BODY}\"", buildMsg(from, date, content));
|
||||||
|
@ -90,6 +90,45 @@
|
|||||||
app:showEye="true" />
|
app:showEye="true" />
|
||||||
</LinearLayout>
|
</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
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -144,6 +144,9 @@
|
|||||||
<string name="email_title">Email Title</string>
|
<string name="email_title">Email Title</string>
|
||||||
<string name="feishu_webhook">Webhook</string>
|
<string name="feishu_webhook">Webhook</string>
|
||||||
<string name="feishu_secret">Secret (optional)</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="Corp_ID">Corp ID</string>
|
||||||
<string name="Agent_ID">Agent ID</string>
|
<string name="Agent_ID">Agent ID</string>
|
||||||
<string name="App_Secret">App Secret</string>
|
<string name="App_Secret">App Secret</string>
|
||||||
|
@ -144,6 +144,9 @@
|
|||||||
<string name="email_title">邮件主题</string>
|
<string name="email_title">邮件主题</string>
|
||||||
<string name="feishu_webhook">Webhook 地址</string>
|
<string name="feishu_webhook">Webhook 地址</string>
|
||||||
<string name="feishu_secret">加签 Secret (没有可不填)</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="Corp_ID">企业ID</string>
|
||||||
<string name="Agent_ID">应用AgentId</string>
|
<string name="Agent_ID">应用AgentId</string>
|
||||||
<string name="App_Secret">应用Secret</string>
|
<string name="App_Secret">应用Secret</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user