新增:钉钉群机器人支持at钉钉号/海外手机号 #312

pull/335/head
pppscn 1 year ago
parent 2b96dca226
commit 652a9c68d7

@ -7,4 +7,5 @@ data class DingtalkGroupRobotSetting(
var secret: String? = "",
var atAll: Boolean? = false,
var atMobiles: String? = "",
var atDingtalkIds: String? = "",
) : Serializable

@ -123,15 +123,9 @@ class DingtalkGroupRobotFragment : BaseFragment<FragmentSendersDingtalkGroupRobo
if (settingVo != null) {
binding!!.etToken.setText(settingVo.token)
binding!!.etSecret.setText(settingVo.secret)
/*if (TextUtils.isEmpty(settingVo.atMobiles)) {
binding!!.sbAtAll.isChecked = true
binding!!.etAtMobiles.setText("")
} else {
binding!!.sbAtAll.isChecked = settingVo.atAll == true
binding!!.etAtMobiles.setText(settingVo.atMobiles)
}*/
binding!!.sbAtAll.isChecked = settingVo.atAll == true
binding!!.etAtMobiles.setText(settingVo.atMobiles)
binding!!.etAtDingtalkIds.setText(settingVo.atDingtalkIds)
}
}
})
@ -149,9 +143,12 @@ class DingtalkGroupRobotFragment : BaseFragment<FragmentSendersDingtalkGroupRobo
//这里只有一个监听不需要判断id
if (isChecked) {
binding!!.layoutAtMobiles.visibility = View.GONE
binding!!.layoutAtDingtalkIds.visibility = View.GONE
binding!!.etAtMobiles.setText("")
binding!!.etAtDingtalkIds.setText("")
} else {
binding!!.layoutAtMobiles.visibility = View.VISIBLE
binding!!.layoutAtDingtalkIds.visibility = View.VISIBLE
}
}
@ -229,11 +226,9 @@ class DingtalkGroupRobotFragment : BaseFragment<FragmentSendersDingtalkGroupRobo
val secret = binding!!.etSecret.text.toString().trim()
val atAll = binding!!.sbAtAll.isChecked
val atMobiles = binding!!.etAtMobiles.text.toString().trim()
/*if (!atAll && TextUtils.isEmpty(atMobiles)) {
throw Exception(getString(R.string.invalid_at_mobiles))
}*/
val atDingtalkIds = binding!!.etAtDingtalkIds.text.toString().trim()
return DingtalkGroupRobotSetting(token, secret, atAll, atMobiles)
return DingtalkGroupRobotSetting(token, secret, atAll, atMobiles, atDingtalkIds)
}
override fun onDestroyView() {

@ -33,7 +33,7 @@ class DingtalkGroupRobotUtils private constructor() {
logId: Long = 0L,
msgId: Long = 0L
) {
val content: String = if (rule != null) {
var content: String = if (rule != null) {
msgInfo.getContentForSend(rule.smsTemplate, rule.regexReplace)
} else {
msgInfo.getContentForSend(SettingUtils.smsTemplate)
@ -56,10 +56,6 @@ class DingtalkGroupRobotUtils private constructor() {
val msgMap: MutableMap<String, Any> = mutableMapOf()
msgMap["msgtype"] = "text"
val textText: MutableMap<String, Any> = mutableMapOf()
textText["content"] = content
msgMap["text"] = textText
val atMap: MutableMap<String, Any> = mutableMapOf()
msgMap["at"] = atMap
if (setting.atAll == true) {
@ -69,19 +65,31 @@ class DingtalkGroupRobotUtils private constructor() {
if (!TextUtils.isEmpty(setting.atMobiles)) {
val atMobilesArray: Array<String> = setting.atMobiles.toString().replace("[,;]".toRegex(), ",").trim(',').split(',').toTypedArray()
if (atMobilesArray.isNotEmpty()) {
val atMobilesList: MutableList<String> = ArrayList()
atMap["atMobiles"] = atMobilesArray
for (atMobile in atMobilesArray) {
if (TextUtils.isDigitsOnly(atMobile)) {
atMobilesList.add(atMobile)
if (!content.contains("@${atMobile}")) {
content += " @${atMobile}"
}
}
if (atMobilesList.isNotEmpty()) {
atMap["atMobiles"] = atMobilesList
}
}
if (!TextUtils.isEmpty(setting.atDingtalkIds)) {
val atDingtalkIdsArray: Array<String> = setting.atDingtalkIds.toString().replace("[,;]".toRegex(), ",").trim(',').split(',').toTypedArray()
if (atDingtalkIdsArray.isNotEmpty()) {
atMap["atDingtalkIds"] = atDingtalkIdsArray
for (atDingtalkId in atDingtalkIdsArray) {
if (!content.contains("@${atDingtalkId}")) {
content += " @${atDingtalkId}"
}
}
}
}
}
val textText: MutableMap<String, Any> = mutableMapOf()
textText["content"] = content
msgMap["text"] = textText
val requestMsg: String = Gson().toJson(msgMap)
Log.i(TAG, "requestMsg:$requestMsg")

@ -1,198 +1,229 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/xui_config_color_background"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<LinearLayout
style="@style/senderBarStyleWithSwitch"
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/sender_name_status"
android:textStyle="bold" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:singleLine="true"
app:met_clearButton="true" />
<com.xuexiang.xui.widget.button.switchbutton.SwitchButton
android:id="@+id/sb_enable"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</LinearLayout>
<LinearLayout
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_token"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_token_tips"
android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_token"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dingtalk_token_hint"
android:singleLine="true"
app:met_passWordButton="true" />
</LinearLayout>
<LinearLayout
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_secret"
android:textStyle="bold" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_secret"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dingtalk_secret_hint"
android:singleLine="true"
app:met_passWordButton="true" />
</LinearLayout>
<LinearLayout
style="@style/senderBarStyleWithSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/is_at_all"
android:textStyle="bold" />
<com.xuexiang.xui.widget.button.switchbutton.SwitchButton
android:id="@+id/sb_at_all"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_at_mobiles"
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_at"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/dingtalk_at_tip"
android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_at_mobiles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
app:met_clearButton="true" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<com.xuexiang.xui.widget.textview.supertextview.SuperButton
android:id="@+id/btn_del"
style="@style/SuperButton.Gray.Icon"
android:drawableStart="@drawable/icon_delete"
android:paddingStart="15dp"
android:text="@string/del"
android:textSize="11sp"
tools:ignore="RtlSymmetry" />
<com.xuexiang.xui.widget.textview.supertextview.SuperButton
android:id="@+id/btn_save"
style="@style/SuperButton.Blue.Icon"
android:layout_marginStart="10dp"
android:drawableStart="@drawable/icon_save"
android:paddingStart="15dp"
android:text="@string/save"
android:textSize="11sp"
tools:ignore="RtlSymmetry" />
<com.xuexiang.xui.widget.textview.supertextview.SuperButton
android:id="@+id/btn_test"
style="@style/SuperButton.Green.Icon"
android:layout_marginStart="10dp"
android:drawableStart="@drawable/icon_test"
android:paddingStart="15dp"
android:text="@string/test"
android:textSize="11sp"
tools:ignore="RtlSymmetry" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/xui_config_color_background"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<LinearLayout
style="@style/senderBarStyleWithSwitch"
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/sender_name_status"
android:textStyle="bold" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:singleLine="true"
app:met_clearButton="true" />
<com.xuexiang.xui.widget.button.switchbutton.SwitchButton
android:id="@+id/sb_enable"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</LinearLayout>
<LinearLayout
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_token"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_token_tips"
android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_token"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dingtalk_token_hint"
android:singleLine="true"
app:met_passWordButton="true" />
</LinearLayout>
<LinearLayout
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_secret"
android:textStyle="bold" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_secret"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dingtalk_secret_hint"
android:singleLine="true"
app:met_passWordButton="true" />
</LinearLayout>
<LinearLayout
style="@style/senderBarStyleWithSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/is_at_all"
android:textStyle="bold" />
<com.xuexiang.xui.widget.button.switchbutton.SwitchButton
android:id="@+id/sb_at_all"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_at_mobiles"
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_at_mobiles"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/dingtalk_at_mobiles_tip"
android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_at_mobiles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
app:met_clearButton="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_at_dingtalk_ids"
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dingtalk_at_dingtalkids"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/dingtalk_at_dingtalkids_tip"
android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_at_dingtalk_ids"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
app:met_clearButton="true" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<com.xuexiang.xui.widget.textview.supertextview.SuperButton
android:id="@+id/btn_del"
style="@style/SuperButton.Gray.Icon"
android:drawableStart="@drawable/icon_delete"
android:paddingStart="15dp"
android:text="@string/del"
android:textSize="11sp"
tools:ignore="RtlSymmetry" />
<com.xuexiang.xui.widget.textview.supertextview.SuperButton
android:id="@+id/btn_save"
style="@style/SuperButton.Blue.Icon"
android:layout_marginStart="10dp"
android:drawableStart="@drawable/icon_save"
android:paddingStart="15dp"
android:text="@string/save"
android:textSize="11sp"
tools:ignore="RtlSymmetry" />
<com.xuexiang.xui.widget.textview.supertextview.SuperButton
android:id="@+id/btn_test"
style="@style/SuperButton.Green.Icon"
android:layout_marginStart="10dp"
android:drawableStart="@drawable/icon_test"
android:paddingStart="15dp"
android:text="@string/test"
android:textSize="11sp"
tools:ignore="RtlSymmetry" />
</LinearLayout>
</LinearLayout>

@ -324,7 +324,7 @@
<string name="server_chan_send_key">SendKey</string>
<string name="server_chan_channel">Message Channel</string>
<string name="server_chan_channel_tips">Tip: Dynamically specified, supports up to two channels, separated by a vertical bar |</string>
<string name="server_chan_channel_hint">Optional, for example: to send service number and enterprise WeChat application, then fill in 9|66</string>
<string name="server_chan_channel_hint">Optional, e.g. to send service number and enterprise WeChat application, then fill in 9|66</string>
<string name="server_chan_openid">CC OpenID</string>
<string name="server_chan_openid_tips">Tip: Only test accounts and Wework application message channels are supported</string>
<string name="server_chan_openid_hint">Optional, multiple openids are separated by commas</string>
@ -704,23 +704,25 @@
<string name="dingtalk_token_hint">Robot Settings→webhook→access_token</string>
<string name="dingtalk_secret">Secret</string>
<string name="dingtalk_secret_hint">Robot Settings→Security Settings→Sign Up</string>
<string name="dingtalk_at">\@someone when retweeting</string>
<string name="dingtalk_at_tip">Tips: Separate multiple phone numbers with commas, for example: 18888888888,19999999999</string>
<string name="dingtalk_at_mobiles">At Mobiles</string>
<string name="dingtalk_at_mobiles_tip">Tips: Separate multiple mobiles with commas, e.g. 18888888888,19999999999</string>
<string name="dingtalk_at_dingtalkids">At DingtalkIds</string>
<string name="dingtalk_at_dingtalkids_tip">TipsSeparate multiple DingtalkIds with commas, e.g. user1,user2</string>
<string name="bark_server">Bark-Server</string>
<string name="bark_server_tips">Example: https://api.day.app/XXXXXXXX/</string>
<string name="bark_server_regex">^https?://[^/]+/[^/]+/$</string>
<string name="bark_server_error">The Url format is wrong, for example: https://api.day.app/XXXXXXXX/</string>
<string name="bark_server_error">The Url format is wrong, e.g. https://api.day.app/XXXXXXXX/</string>
<string name="bark_group">Group Name</string>
<string name="bark_group_tips">Optional, eg: SmsForwarder</string>
<string name="bark_icon">Message Icon</string>
<string name="bark_icon_tips">Optional, fill in Url, the picture should not be too big</string>
<string name="bark_sound">Message Sound</string>
<string name="bark_sound_tips">Optional, for example: minuet.caf</string>
<string name="bark_sound_tips">Optional, e.g. minuet.caf</string>
<string name="bark_badge">Message Badge</string>
<string name="bark_badge_tips">Optional, eg: 888</string>
<string name="bark_url">Message Link</string>
<string name="bark_url_tips">Optional, for example: https://github.com/pppscn/SmsForwarder</string>
<string name="bark_url_tips">Optional, e.g. https://github.com/pppscn/SmsForwarder</string>
<string name="bark_level">Notification Level</string>
<string name="bark_level_active">Immediately display notifications</string>
<string name="bark_level_timeSensitive">Time-sensitive notifications that can be displayed in a focused state</string>
@ -766,7 +768,7 @@
<string name="webhook_server_tips">For example: https://a.b.com/msg?token=xyz</string>
<string name="webhook_params">Params</string>
<string name="msg_template">Msg Template</string>
<string name="webhook_params_tips" formatted="false">For example: payload=%7B%22text%22%3A%22[msg]%22%7D [msg] will be replaced with SMS content.\nJson format is supported, for example: {\"text\":\"[msg]\"}.\nNote: msg is automatically URLEncoder except in JSON format</string>
<string name="webhook_params_tips" formatted="false">For example: payload=%7B%22text%22%3A%22[msg]%22%7D [msg] will be replaced with SMS content.\nJson format is supported, e.g. {\"text\":\"[msg]\"}.\nNote: msg is automatically URLEncoder except in JSON format</string>
<string name="webhook_secret">Secret: If it is empty, the sign will not be calculated</string>
<string name="headers">Headers</string>
<string name="header_key">Key</string>

@ -311,7 +311,7 @@
<string name="Corp_ID">企业ID</string>
<string name="Agent_ID">AgentId</string>
<string name="App_Secret">Secret</string>
<string name="is_at_all">是否@all</string>
<string name="is_at_all">是否@所有人</string>
<string name="specified_member">指定成员</string>
<string name="at_all">\@all</string>
<string name="specified_member_tips">Tip接收消息的成员ID列表多个接收者用|分隔最多支持1000个</string>
@ -705,8 +705,10 @@
<string name="dingtalk_token_hint">机器人设置→webhook→access_token</string>
<string name="dingtalk_secret">加签 Secret</string>
<string name="dingtalk_secret_hint">机器人设置→安全设置→加签</string>
<string name="dingtalk_at">转发时@某人</string>
<string name="dingtalk_at_tip">Tips多个手机号用逗号分开例如18888888888,19999999999</string>
<string name="dingtalk_at_mobiles">被@人的手机号</string>
<string name="dingtalk_at_mobiles_tip">Tips多个手机号用逗号分开例如18888888888,19999999999</string>
<string name="dingtalk_at_dingtalkids">被@人的钉钉号</string>
<string name="dingtalk_at_dingtalkids_tip">Tips多个钉钉号用逗号分开例如user1,user2</string>
<string name="bark_server">Bark-Server</string>
<string name="bark_server_tips">https://api.day.app/XXXXXXXX/</string>

Loading…
Cancel
Save