优化:企微群机器人发送通道支持Markdown格式消息 #292

This commit is contained in:
pppscn 2023-05-07 14:21:40 +08:00
parent c7ead43a29
commit 862477e15c
6 changed files with 404 additions and 343 deletions

View File

@ -1,7 +1,18 @@
package com.idormy.sms.forwarder.entity.setting
import com.idormy.sms.forwarder.R
import java.io.Serializable
data class WeworkRobotSetting(
var webHook: String,
) : Serializable
val msgType: String = "text",
) : Serializable {
fun getMsgTypeCheckId(): Int {
return if (msgType == "markdown") {
R.id.rb_msg_type_markdown
} else {
R.id.rb_msg_type_text
}
}
}

View File

@ -121,6 +121,7 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
Log.d(TAG, settingVo.toString())
if (settingVo != null) {
binding!!.etWebHook.setText(settingVo.webHook)
binding!!.rgMsgType.check(settingVo.getMsgTypeCheckId())
}
}
})
@ -155,6 +156,7 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
}.start()
return
}
R.id.btn_del -> {
if (senderId <= 0 || isClone) {
popToBack()
@ -174,6 +176,7 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
.show()
return
}
R.id.btn_save -> {
val name = binding!!.etName.text.toString().trim()
if (TextUtils.isEmpty(name)) {
@ -203,8 +206,8 @@ class WeworkRobotFragment : BaseFragment<FragmentSendersWeworkRobotBinding?>(),
if (!CommonUtils.checkUrl(webHook, false)) {
throw Exception(getString(R.string.invalid_webhook))
}
return WeworkRobotSetting(webHook)
val msgType = if (binding!!.rgMsgType.checkedRadioButtonId == R.id.rb_msg_type_markdown) "markdown" else "text"
return WeworkRobotSetting(webHook, msgType)
}
override fun onDestroyView() {

View File

@ -13,7 +13,6 @@ import com.xuexiang.xhttp2.cache.model.CacheMode
import com.xuexiang.xhttp2.callback.SimpleCallBack
import com.xuexiang.xhttp2.exception.ApiException
@Suppress("PrivatePropertyName", "UNUSED_PARAMETER")
class WeworkRobotUtils private constructor() {
companion object {
@ -37,11 +36,17 @@ class WeworkRobotUtils private constructor() {
Log.i(TAG, "requestUrl:$requestUrl")
val msgMap: MutableMap<String, Any> = mutableMapOf()
msgMap["msgtype"] = "text"
msgMap["msgtype"] = setting.msgType
if (setting.msgType == "markdown") {
val markdownText: MutableMap<String, Any> = mutableMapOf()
markdownText["content"] = content
msgMap["markdown"] = markdownText
} else {
val textText: MutableMap<String, Any> = mutableMapOf()
textText["content"] = content
msgMap["text"] = textText
}
val requestMsg: String = Gson().toJson(msgMap)
Log.i(TAG, "requestMsg:$requestMsg")

View File

@ -77,6 +77,42 @@
</LinearLayout>
<LinearLayout
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wework_msg_type"
android:textStyle="bold" />
<RadioGroup
android:id="@+id/rg_msg_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_msg_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/wework_msg_type_text" />
<RadioButton
android:id="@+id/rb_msg_type_markdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wework_msg_type_markdown" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -559,10 +559,10 @@
<string name="keep_alive_tips">It is recommended to open the first three switch, do not disable the notification bar, to avoid APP being killed</string>
<string name="custom_settings">Custom Settings</string>
<string name="custom_settings_tips">Please fill in the remarks manually or click the refresh button to get it automatically</string>
<string name="times">,</string>
<string name="times">times</string>
<string name="interval">Interval</string>
<string name="timeout">Timeout</string>
<string name="seconds">s</string>
<string name="seconds">secs</string>
<string name="seconds_n">%s sec</string>
<string name="retry">Retry</string>
<string name="test_sender_sms">[Test Channel] Congratulations, the sending channel test is successful, please continue to add forwarding rules!</string>
@ -743,6 +743,9 @@
<string name="wework_webHook">WebHook</string>
<string name="wework_webHook_tips">Example: https://qyapi.weixin.qq.com/cgixx?key=xxx</string>
<string name="wework_msg_type">Msg Type</string>
<string name="wework_msg_type_text">Text</string>
<string name="wework_msg_type_markdown">Markdown</string>
<string name="url_scheme">URL Scheme</string>
<string name="url_scheme_tips">Examplemyapp://api/add?&amp;type=0&amp;msg=[msg]</string>

View File

@ -744,6 +744,9 @@
<string name="wework_webHook">WebHook地址</string>
<string name="wework_webHook_tips">示例https://qyapi.weixin.qq.com/cgixx?key=xxx</string>
<string name="wework_msg_type">消息类型</string>
<string name="wework_msg_type_text">纯文本</string>
<string name="wework_msg_type_markdown">markdown</string>
<string name="url_scheme">URL Scheme</string>
<string name="url_scheme_tips">示例myapp://api/add?&amp;type=0&amp;msg=[msg]</string>