Skip to content

Commit

Permalink
1,钉钉机器人添加 @ 功能
Browse files Browse the repository at this point in the history
  • Loading branch information
timsengit committed Jan 25, 2021
1 parent 65a8d10 commit 7931af5
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 17 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ APP下载 [https://pan.baidu.com/s/1kbelTFIf5nwkOY9g6itkvA]
| ---- | ---- |
| 转发监听 | 已实现 |
| 转发钉钉 | 单个钉钉群已实现 |
| 转发钉钉@某人 | 已实现 |
| 转发邮箱 | 单个邮箱已实现 |
| 转发企业微信群机器人 | 已实现 |
| 转发web页面 | 单个web页面已实现([向设置的url发送POST请求](doc/POST_WEB.md)|
| 转发规则 | (规则即:什么短信转发到哪里)已实现实现 |
| 兼容 | 已兼容6.xx、7.xx、8.xx、9.xx、10.xx |
Expand Down Expand Up @@ -66,6 +68,8 @@ APP下载 [https://pan.baidu.com/s/1kbelTFIf5nwkOY9g6itkvA]
![应用更新](pic/update-dingdingsecret.jpg "应用更新")

### 更新记录:
> [v3.5.0](app/release/TSMS_release_20210126_3.5.0.apk) 1,钉钉机器人添加 @ 功能
> [v3.4.0](pic/TSMS_release_20210120_3.4.0.apk) 1,增加企业微信群机器人通知。2,修复设置开机启动崩溃
> [v3.3.0](pic/TSMS_release_20210113_3.3.0.apk) 1,增加网页通知验签。2,修复网页及钉钉配置测试崩溃
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.tim.tsms.transpondsms"
minSdkVersion 23
targetSdkVersion 28
versionCode 34
versionName "3.4.0"
versionCode 35
versionName "3.5.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file added app/release/TSMS_release_20210126_3.5.0.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":34,"versionName":"3.4.0","enabled":true,"outputFile":"TSMS_release_20210120_3.4.0.apk","fullName":"release","baseName":"release"},"path":"TSMS_release_20210120_3.4.0.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":35,"versionName":"3.5.0","enabled":true,"outputFile":"TSMS_release_20210126_3.5.0.apk","fullName":"release","baseName":"release"},"path":"TSMS_release_20210126_3.5.0.apk","properties":{}}]
22 changes: 19 additions & 3 deletions app/src/main/java/com/tim/tsms/transpondsms/SenderActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ private void setDingDing(final SenderModel senderModel) {
final EditText editTextDingdingSecret = view1.findViewById(R.id.editTextDingdingSecret);
if (dingDingSettingVo != null)
editTextDingdingSecret.setText(dingDingSettingVo.getSecret());
final EditText editTextDingdingAtMobiles = view1.findViewById(R.id.editTextDingdingAtMobiles);
if (dingDingSettingVo != null)
editTextDingdingAtMobiles.setText(dingDingSettingVo.getAtMobils());
final Switch switchDingdingAtAll = view1.findViewById(R.id.switchDingdingAtAll);
if (dingDingSettingVo != null)
switchDingdingAtAll.setChecked(dingDingSettingVo.getAtAll());

Button buttondingdingok = view1.findViewById(R.id.buttondingdingok);
Button buttondingdingdel = view1.findViewById(R.id.buttondingdingdel);
Expand All @@ -180,7 +186,11 @@ public void onClick(View view) {
newSenderModel.setName(editTextDingdingName.getText().toString());
newSenderModel.setType(TYPE_DINGDING);
newSenderModel.setStatus(STATUS_ON);
DingDingSettingVo dingDingSettingVonew = new DingDingSettingVo(editTextDingdingToken.getText().toString(), editTextDingdingSecret.getText().toString());
DingDingSettingVo dingDingSettingVonew = new DingDingSettingVo(
editTextDingdingToken.getText().toString(),
editTextDingdingSecret.getText().toString(),
editTextDingdingAtMobiles.getText().toString(),
switchDingdingAtAll.isChecked());
newSenderModel.setJsonSetting(JSON.toJSONString(dingDingSettingVonew));
SenderUtil.addSender(newSenderModel);
initSenders();
Expand All @@ -190,7 +200,11 @@ public void onClick(View view) {
senderModel.setName(editTextDingdingName.getText().toString());
senderModel.setType(TYPE_DINGDING);
senderModel.setStatus(STATUS_ON);
DingDingSettingVo dingDingSettingVonew = new DingDingSettingVo(editTextDingdingToken.getText().toString(), editTextDingdingSecret.getText().toString());
DingDingSettingVo dingDingSettingVonew = new DingDingSettingVo(
editTextDingdingToken.getText().toString(),
editTextDingdingSecret.getText().toString(),
editTextDingdingAtMobiles.getText().toString(),
switchDingdingAtAll.isChecked());
senderModel.setJsonSetting(JSON.toJSONString(dingDingSettingVonew));
SenderUtil.updateSender(senderModel);
initSenders();
Expand Down Expand Up @@ -222,9 +236,11 @@ public void onClick(View view) {
public void onClick(View view) {
String token = editTextDingdingToken.getText().toString();
String secret = editTextDingdingSecret.getText().toString();
String atMobiles = editTextDingdingAtMobiles.getText().toString();
Boolean atAll = switchDingdingAtAll.isChecked();
if (token != null && !token.isEmpty()) {
try {
SenderDingdingMsg.sendMsg(handler, token, secret, "test@" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SenderDingdingMsg.sendMsg(handler, token, secret,atMobiles,atAll, "test@" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
} catch (Exception e) {
Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
public class DingDingSettingVo implements Serializable {
private String token;
private String secret;
private String atMobils;
private Boolean atAll;

public DingDingSettingVo() {
}

public DingDingSettingVo(String token, String secret) {
public DingDingSettingVo(String token, String secret, String atMobils, Boolean atAll) {
this.token = token;
this.secret = secret;
this.atMobils = atMobils;
this.atAll = atAll;
}

public String getToken() {
Expand All @@ -29,4 +33,20 @@ public String getSecret() {
public void setSecret(String secret) {
this.secret = secret;
}

public String getAtMobils() {
return atMobils;
}

public void setAtMobils(String atMobils) {
this.atMobils = atMobils;
}

public Boolean getAtAll() {
return atAll;
}

public void setAtAll(Boolean atAll) {
this.atAll = atAll;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static void senderSendMsg(SmsVo smsVo,SenderModel senderModel) {
DingDingSettingVo dingDingSettingVo = JSON.parseObject(senderModel.getJsonSetting(), DingDingSettingVo.class);
if(dingDingSettingVo!=null){
try {
SenderDingdingMsg.sendMsg(null, dingDingSettingVo.getToken(), dingDingSettingVo.getSecret(), smsVo.getSmsVoForSend());
SenderDingdingMsg.sendMsg(null, dingDingSettingVo.getToken(), dingDingSettingVo.getSecret(),dingDingSettingVo.getAtMobils(),dingDingSettingVo.getAtAll(), smsVo.getSmsVoForSend());
}catch (Exception e){
Log.e(TAG, "senderSendMsg: dingding error "+e.getMessage() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;


import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.util.Base64;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

Expand Down Expand Up @@ -78,8 +85,8 @@ public void onResponse(Call call, Response response) throws IOException {
});
}

public static void sendMsg(final Handler handError, String token, String secret, String msg) throws Exception {
Log.i(TAG, "sendMsg token:"+token+" secret:"+secret+" msg:"+msg);
public static void sendMsg(final Handler handError, String token, String secret,String atMobiles,Boolean atAll, String msg) throws Exception {
Log.i(TAG, "sendMsg token:"+token+" secret:"+secret+" atMobiles:"+atMobiles+" atAll:"+atAll+" msg:"+msg);

if (token == null || token.isEmpty()) {
return;
Expand All @@ -97,8 +104,40 @@ public static void sendMsg(final Handler handError, String token, String secret,

}

final String msgf = msg;
String textMsg = "{ \"msgtype\": \"text\", \"text\": {\"content\": \"" + msg + "\"}}";
Map textMsgMap =new HashMap();
textMsgMap.put("msgtype","text");
Map textText=new HashMap();
textText.put("content",msg);
textMsgMap.put("text",textText);
if(atMobiles != null || atAll !=null){
Map AtMap=new HashMap();
if(atMobiles!=null){
String[] atMobilesArray = atMobiles.split(",");
List<String> atMobilesList=new ArrayList<>();
for (String atMobile:atMobilesArray
) {
if(TextUtils.isDigitsOnly(atMobile)){
atMobilesList.add(atMobile);
}
}
if(!atMobilesList.isEmpty()){
AtMap.put("atMobiles",atMobilesList);

}
}

AtMap.put("isAtAll",false);
if(atAll !=null){
AtMap.put("isAtAll",atAll);

}

textMsgMap.put("at",AtMap);
}

String textMsg = JSON.toJSONString(textMsgMap);
Log.i(TAG, "textMsg:" + textMsg);

OkHttpClient client = new OkHttpClient();
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"),
textMsg);
Expand All @@ -114,8 +153,6 @@ public static void sendMsg(final Handler handError, String token, String secret,
public void onFailure(Call call, final IOException e) {
Log.d(TAG, "onFailure:" + e.getMessage());

// SendHistory.addHistory("钉钉转发:"+msgf+"onFailure:" + e.getMessage());

if(handError != null){
android.os.Message msg = new android.os.Message();
msg.what = NOTIFY;
Expand Down Expand Up @@ -143,7 +180,6 @@ public void onResponse(Call call, Response response) throws IOException {
Log.d(TAG, "Coxxyyde:" + String.valueOf(response.code()) + responseStr);
}

// SendHistory.addHistory("钉钉转发:"+msgf+"Code:" + String.valueOf(response.code())+responseStr);
}
});
}
Expand Down
46 changes: 44 additions & 2 deletions app/src/main/res/layout/activity_alter_dialog_setview_dingding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:layout_margin="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置Token" />
android:text="设置Token 例如 https://oapi.dingtalk.com/robot/send?access_token=XXXXXX" />


<EditText
Expand All @@ -58,7 +58,7 @@
android:layout_margin="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置Secret" />
android:text="加签 Secret 没有可不填" />


<EditText
Expand All @@ -70,6 +70,48 @@
android:inputType=""
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<TextView
android:layout_margin="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="转发时@某人 填写某人的手机号,多个用逗号分开 例如:18888888888,19999999999" />


<EditText
android:id="@+id/editTextDingdingAtMobiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:ems="10"
android:inputType=""
android:text="" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="是否@所有人。" />

<Switch
android:id="@+id/switchDingdingAtAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:ems="10"
android:checked="false"/>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Expand Down

0 comments on commit 7931af5

Please sign in to comment.