mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
新增转发到企业微信应用消息
This commit is contained in:
parent
2212d51931
commit
43ff9cb03f
10
README.md
10
README.md
@ -1,6 +1,6 @@
|
|||||||
# SmsForwarder (短信转发器)
|
# SmsForwarder (短信转发器)
|
||||||
|
|
||||||
Android手机监听短信并根据指定规则转发到其他手机、钉钉机器人、企业微信群机器人、邮箱、bark、webhook等
|
Android手机监听短信并根据指定规则转发到其他手机:钉钉机器人、企业微信群机器人、企业微信应用消息、邮箱、bark、webhook等
|
||||||
|
|
||||||
> ⚠ 此项目在 [xiaoyuanhost/TranspondSms](https://github.com/xiaoyuanhost/TranspondSms) 的基础上优化改造而来,感谢原作者!
|
> ⚠ 此项目在 [xiaoyuanhost/TranspondSms](https://github.com/xiaoyuanhost/TranspondSms) 的基础上优化改造而来,感谢原作者!
|
||||||
|
|
||||||
@ -41,7 +41,8 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
|
|||||||
- [x] 转发到邮箱(支持:SMTP)
|
- [x] 转发到邮箱(支持:SMTP)
|
||||||
- [x] 转发到Bark(支持:验证码/动态密码自动复制)
|
- [x] 转发到Bark(支持:验证码/动态密码自动复制)
|
||||||
- [x] 转发到webhook(支持:单个web页面([向设置的url发送POST请求](doc/POST_WEB.md)))
|
- [x] 转发到webhook(支持:单个web页面([向设置的url发送POST请求](doc/POST_WEB.md)))
|
||||||
- [x] 转发到企业微信群机器人(待验证)
|
- [x] 转发到企业微信群机器人
|
||||||
|
- [x] 转发到企业微信应用消息
|
||||||
- [x] 在线检测新版本、升级
|
- [x] 在线检测新版本、升级
|
||||||
- [x] 清理缓存
|
- [x] 清理缓存
|
||||||
- [x] 兼容6.xx、7.xx、8.xx、9.xx、10.xx
|
- [x] 兼容6.xx、7.xx、8.xx、9.xx、10.xx
|
||||||
@ -50,7 +51,7 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
|
|||||||
|
|
||||||
### 使用流程:
|
### 使用流程:
|
||||||
1. 在Android手机上安装SmsForwarder 本APP后点击应用图标打开
|
1. 在Android手机上安装SmsForwarder 本APP后点击应用图标打开
|
||||||
2. 在设置发送方页面,添加或点击已添加的发送方来设置转发短信使用的方式,现在支持钉钉机器人、企业微信群机器人、邮箱、网页、Bark:
|
2. 在设置发送方页面,添加或点击已添加的发送方来设置转发短信使用的方式,现在支持钉钉机器人、企业微信群机器人、企业微信应用消息、邮箱、网页、Bark:
|
||||||
+ 设置钉钉机器人请先在钉钉群中添加自定义机器人,复制机器人的token和secret,填入弹出框。点击测试会使用该机器人向群内发送一条消息;点击确认即可添加配置。
|
+ 设置钉钉机器人请先在钉钉群中添加自定义机器人,复制机器人的token和secret,填入弹出框。点击测试会使用该机器人向群内发送一条消息;点击确认即可添加配置。
|
||||||
+ 配置邮箱请先在你邮箱的后台管理页面配置smtp选项,并设置密码(授权码),并参照说明配置SmsForwarder弹出框的smtp信息。点击测试会使用该邮箱向配置的邮箱发送一条测试邮件;点击确认即可添加配置。
|
+ 配置邮箱请先在你邮箱的后台管理页面配置smtp选项,并设置密码(授权码),并参照说明配置SmsForwarder弹出框的smtp信息。点击测试会使用该邮箱向配置的邮箱发送一条测试邮件;点击确认即可添加配置。
|
||||||
+ 配置网页通知请先在 msg.allmything.com 注册登陆并添加一个消息通道,复制消息通道token填入配置弹框。点击测试会向该消息通道推送一条测试消息,可在 msg.allmything.com 的消息页面查看(页面会自动刷新);点击确认即可添加配置。
|
+ 配置网页通知请先在 msg.allmything.com 注册登陆并添加一个消息通道,复制消息通道token填入配置弹框。点击测试会向该消息通道推送一条测试消息,可在 msg.allmything.com 的消息页面查看(页面会自动刷新);点击确认即可添加配置。
|
||||||
@ -75,7 +76,7 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
|
|||||||
|  |  |
|
|  |  |
|
||||||
|  |  |
|
|  |  |
|
||||||
|  |  |
|
|  |  |
|
||||||
|  | |
|
| |  |
|
||||||
|
|
||||||
--------
|
--------
|
||||||
|
|
||||||
@ -93,6 +94,7 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
|
|||||||
+ [v1.3.0](app/release/SmsForwarder_release_20210303_1.3.0.apk) 支持双卡手机,增加卡槽标识/运营商/手机号(如果能获取的话)
|
+ [v1.3.0](app/release/SmsForwarder_release_20210303_1.3.0.apk) 支持双卡手机,增加卡槽标识/运营商/手机号(如果能获取的话)
|
||||||
+ [v1.4.0](app/release/SmsForwarder_release_20210304_1.4.0.apk) 支持多重匹配规则
|
+ [v1.4.0](app/release/SmsForwarder_release_20210304_1.4.0.apk) 支持多重匹配规则
|
||||||
+ [v1.4.1](app/release/SmsForwarder_release_20210304_1.4.1.apk) 设置中允许关闭页面帮助/表单填写提示
|
+ [v1.4.1](app/release/SmsForwarder_release_20210304_1.4.1.apk) 设置中允许关闭页面帮助/表单填写提示
|
||||||
|
+ [v1.5.0](app/release/SmsForwarder_release_20210305_1.5.0.apk) 新增转发到企业微信应用消息
|
||||||
|
|
||||||
|
|
||||||
## LICENSE
|
## LICENSE
|
||||||
|
@ -14,8 +14,8 @@ android {
|
|||||||
applicationId "com.idormy.sms.forwarder"
|
applicationId "com.idormy.sms.forwarder"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 12
|
versionCode 13
|
||||||
versionName "1.4.1"
|
versionName "1.5.0"
|
||||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
BIN
app/release/SmsForwarder_release_20210305_1.5.0.apk
Normal file
BIN
app/release/SmsForwarder_release_20210305_1.5.0.apk
Normal file
Binary file not shown.
@ -10,9 +10,9 @@
|
|||||||
{
|
{
|
||||||
"type": "SINGLE",
|
"type": "SINGLE",
|
||||||
"filters": [],
|
"filters": [],
|
||||||
"versionCode": 12,
|
"versionCode": 13,
|
||||||
"versionName": "1.4.1",
|
"versionName": "1.5.0",
|
||||||
"outputFile": "SmsForwarder_release_20210304_1.4.1.apk"
|
"outputFile": "SmsForwarder_release_20210305_1.5.0.apk"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -26,6 +26,9 @@ public class MyApplication extends Application {
|
|||||||
public static Map<String, Map> SimInfo = new HashMap();
|
public static Map<String, Map> SimInfo = new HashMap();
|
||||||
//是否关闭页面提示
|
//是否关闭页面提示
|
||||||
public static boolean showHelpTip = true;
|
public static boolean showHelpTip = true;
|
||||||
|
//企业微信
|
||||||
|
public static String QyWxAccessToken;
|
||||||
|
public static long QyWxAccessTokenExpiresIn = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <meta-data
|
* <meta-data
|
||||||
|
@ -8,7 +8,9 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -23,11 +25,13 @@ import com.idormy.sms.forwarder.model.SenderModel;
|
|||||||
import com.idormy.sms.forwarder.model.vo.BarkSettingVo;
|
import com.idormy.sms.forwarder.model.vo.BarkSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.DingDingSettingVo;
|
import com.idormy.sms.forwarder.model.vo.DingDingSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.EmailSettingVo;
|
import com.idormy.sms.forwarder.model.vo.EmailSettingVo;
|
||||||
|
import com.idormy.sms.forwarder.model.vo.QYWXAppSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
|
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.WebNotifySettingVo;
|
import com.idormy.sms.forwarder.model.vo.WebNotifySettingVo;
|
||||||
import com.idormy.sms.forwarder.utils.SenderBarkMsg;
|
import com.idormy.sms.forwarder.utils.SenderBarkMsg;
|
||||||
import com.idormy.sms.forwarder.utils.SenderDingdingMsg;
|
import com.idormy.sms.forwarder.utils.SenderDingdingMsg;
|
||||||
import com.idormy.sms.forwarder.utils.SenderMailMsg;
|
import com.idormy.sms.forwarder.utils.SenderMailMsg;
|
||||||
|
import com.idormy.sms.forwarder.utils.SenderQyWxAppMsg;
|
||||||
import com.idormy.sms.forwarder.utils.SenderQyWxGroupRobotMsg;
|
import com.idormy.sms.forwarder.utils.SenderQyWxGroupRobotMsg;
|
||||||
import com.idormy.sms.forwarder.utils.SenderUtil;
|
import com.idormy.sms.forwarder.utils.SenderUtil;
|
||||||
import com.idormy.sms.forwarder.utils.SenderWebNotifyMsg;
|
import com.idormy.sms.forwarder.utils.SenderWebNotifyMsg;
|
||||||
@ -42,6 +46,7 @@ import static com.idormy.sms.forwarder.model.SenderModel.STATUS_ON;
|
|||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_BARK;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_BARK;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_DINGDING;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_DINGDING;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_EMAIL;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_EMAIL;
|
||||||
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_APP;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_GROUP_ROBOT;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_GROUP_ROBOT;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_WEB_NOTIFY;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_WEB_NOTIFY;
|
||||||
|
|
||||||
@ -104,14 +109,17 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
case TYPE_EMAIL:
|
case TYPE_EMAIL:
|
||||||
setEmail(senderModel);
|
setEmail(senderModel);
|
||||||
break;
|
break;
|
||||||
|
case TYPE_BARK:
|
||||||
|
setBark(senderModel);
|
||||||
|
break;
|
||||||
case TYPE_WEB_NOTIFY:
|
case TYPE_WEB_NOTIFY:
|
||||||
setWebNotify(senderModel);
|
setWebNotify(senderModel);
|
||||||
break;
|
break;
|
||||||
case TYPE_QYWX_GROUP_ROBOT:
|
case TYPE_QYWX_GROUP_ROBOT:
|
||||||
setQYWXGroupRobot(senderModel);
|
setQYWXGroupRobot(senderModel);
|
||||||
break;
|
break;
|
||||||
case TYPE_BARK:
|
case TYPE_QYWX_APP:
|
||||||
setBark(senderModel);
|
setQYWXApp(senderModel);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Toast.makeText(SenderActivity.this, "异常的发送方类型,自动删除!", Toast.LENGTH_LONG).show();
|
Toast.makeText(SenderActivity.this, "异常的发送方类型,自动删除!", Toast.LENGTH_LONG).show();
|
||||||
@ -179,14 +187,17 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
case TYPE_EMAIL:
|
case TYPE_EMAIL:
|
||||||
setEmail(null);
|
setEmail(null);
|
||||||
break;
|
break;
|
||||||
|
case TYPE_BARK:
|
||||||
|
setBark(null);
|
||||||
|
break;
|
||||||
case TYPE_WEB_NOTIFY:
|
case TYPE_WEB_NOTIFY:
|
||||||
setWebNotify(null);
|
setWebNotify(null);
|
||||||
break;
|
break;
|
||||||
case TYPE_QYWX_GROUP_ROBOT:
|
case TYPE_QYWX_GROUP_ROBOT:
|
||||||
setQYWXGroupRobot(null);
|
setQYWXGroupRobot(null);
|
||||||
break;
|
break;
|
||||||
case TYPE_BARK:
|
case TYPE_QYWX_APP:
|
||||||
setBark(null);
|
setQYWXApp(null);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Toast.makeText(SenderActivity.this, "暂不支持这种转发!", Toast.LENGTH_LONG).show();
|
Toast.makeText(SenderActivity.this, "暂不支持这种转发!", Toast.LENGTH_LONG).show();
|
||||||
@ -427,6 +438,96 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setBark(final SenderModel senderModel) {
|
||||||
|
BarkSettingVo barkSettingVo = null;
|
||||||
|
//try phrase json setting
|
||||||
|
if (senderModel != null) {
|
||||||
|
String jsonSettingStr = senderModel.getJsonSetting();
|
||||||
|
if (jsonSettingStr != null) {
|
||||||
|
barkSettingVo = JSON.parseObject(jsonSettingStr, BarkSettingVo.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final AlertDialog.Builder alertDialog71 = new AlertDialog.Builder(SenderActivity.this);
|
||||||
|
View view1 = View.inflate(SenderActivity.this, R.layout.activity_alter_dialog_setview_bark, null);
|
||||||
|
|
||||||
|
final EditText editTextBarkName = view1.findViewById(R.id.editTextBarkName);
|
||||||
|
if (senderModel != null) editTextBarkName.setText(senderModel.getName());
|
||||||
|
final EditText editTextBarkServer = view1.findViewById(R.id.editTextBarkServer);
|
||||||
|
if (barkSettingVo != null) editTextBarkServer.setText(barkSettingVo.getServer());
|
||||||
|
|
||||||
|
Button buttonBarkOk = view1.findViewById(R.id.buttonBarkOk);
|
||||||
|
Button buttonBarkDel = view1.findViewById(R.id.buttonBarkDel);
|
||||||
|
Button buttonBarkTest = view1.findViewById(R.id.buttonBarkTest);
|
||||||
|
alertDialog71
|
||||||
|
.setTitle(R.string.setbarktitle)
|
||||||
|
.setIcon(R.mipmap.bark)
|
||||||
|
.setView(view1)
|
||||||
|
.create();
|
||||||
|
final AlertDialog show = alertDialog71.show();
|
||||||
|
|
||||||
|
buttonBarkOk.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
|
||||||
|
if (senderModel == null) {
|
||||||
|
SenderModel newSenderModel = new SenderModel();
|
||||||
|
newSenderModel.setName(editTextBarkName.getText().toString());
|
||||||
|
newSenderModel.setType(TYPE_BARK);
|
||||||
|
newSenderModel.setStatus(STATUS_ON);
|
||||||
|
BarkSettingVo barkSettingVoNew = new BarkSettingVo(
|
||||||
|
editTextBarkServer.getText().toString()
|
||||||
|
);
|
||||||
|
newSenderModel.setJsonSetting(JSON.toJSONString(barkSettingVoNew));
|
||||||
|
SenderUtil.addSender(newSenderModel);
|
||||||
|
initSenders();
|
||||||
|
adapter.add(senderModels);
|
||||||
|
} else {
|
||||||
|
senderModel.setName(editTextBarkName.getText().toString());
|
||||||
|
senderModel.setType(TYPE_BARK);
|
||||||
|
senderModel.setStatus(STATUS_ON);
|
||||||
|
BarkSettingVo barkSettingVoNew = new BarkSettingVo(
|
||||||
|
editTextBarkServer.getText().toString()
|
||||||
|
);
|
||||||
|
senderModel.setJsonSetting(JSON.toJSONString(barkSettingVoNew));
|
||||||
|
SenderUtil.updateSender(senderModel);
|
||||||
|
initSenders();
|
||||||
|
adapter.update(senderModels);
|
||||||
|
}
|
||||||
|
|
||||||
|
show.dismiss();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonBarkDel.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (senderModel != null) {
|
||||||
|
SenderUtil.delSender(senderModel.getId());
|
||||||
|
initSenders();
|
||||||
|
adapter.del(senderModels);
|
||||||
|
}
|
||||||
|
show.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonBarkTest.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
String barkServer = editTextBarkServer.getText().toString();
|
||||||
|
if (!barkServer.isEmpty()) {
|
||||||
|
try {
|
||||||
|
SenderBarkMsg.sendMsg(handler, barkServer, "19999999999", "【京东】验证码为387481(切勿将验证码告知他人),请在页面中输入完成验证,如有问题请点击 ihelp.jd.com 联系京东客服", "18888888888");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(SenderActivity.this, "bark-server 不能为空", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void setWebNotify(final SenderModel senderModel) {
|
private void setWebNotify(final SenderModel senderModel) {
|
||||||
WebNotifySettingVo webNotifySettingVo = null;
|
WebNotifySettingVo webNotifySettingVo = null;
|
||||||
//try phrase json setting
|
//try phrase json setting
|
||||||
@ -615,68 +716,105 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBark(final SenderModel senderModel) {
|
//企业微信应用
|
||||||
BarkSettingVo barkSettingVo = null;
|
private void setQYWXApp(final SenderModel senderModel) {
|
||||||
|
QYWXAppSettingVo QYWXAppSettingVo = null;
|
||||||
//try phrase json setting
|
//try phrase json setting
|
||||||
if (senderModel != null) {
|
if (senderModel != null) {
|
||||||
String jsonSettingStr = senderModel.getJsonSetting();
|
String jsonSettingStr = senderModel.getJsonSetting();
|
||||||
if (jsonSettingStr != null) {
|
if (jsonSettingStr != null) {
|
||||||
barkSettingVo = JSON.parseObject(jsonSettingStr, BarkSettingVo.class);
|
QYWXAppSettingVo = JSON.parseObject(jsonSettingStr, QYWXAppSettingVo.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final AlertDialog.Builder alertDialog71 = new AlertDialog.Builder(SenderActivity.this);
|
final AlertDialog.Builder alertDialog71 = new AlertDialog.Builder(SenderActivity.this);
|
||||||
View view1 = View.inflate(SenderActivity.this, R.layout.activity_alter_dialog_setview_bark, null);
|
View view1 = View.inflate(SenderActivity.this, R.layout.activity_alter_dialog_setview_qywxapp, null);
|
||||||
|
|
||||||
final EditText editTextBarkName = view1.findViewById(R.id.editTextBarkName);
|
final EditText editTextQYWXAppName = view1.findViewById(R.id.editTextQYWXAppName);
|
||||||
if (senderModel != null) editTextBarkName.setText(senderModel.getName());
|
if (senderModel != null)
|
||||||
final EditText editTextBarkServer = view1.findViewById(R.id.editTextBarkServer);
|
editTextQYWXAppName.setText(senderModel.getName());
|
||||||
if (barkSettingVo != null) editTextBarkServer.setText(barkSettingVo.getServer());
|
final EditText editTextQYWXAppCorpID = view1.findViewById(R.id.editTextQYWXAppCorpID);
|
||||||
|
final EditText editTextQYWXAppAgentID = view1.findViewById(R.id.editTextQYWXAppAgentID);
|
||||||
|
final EditText editTextQYWXAppSecret = view1.findViewById(R.id.editTextQYWXAppSecret);
|
||||||
|
final LinearLayout linearLayoutQYWXAppToUser = view1.findViewById(R.id.linearLayoutQYWXAppToUser);
|
||||||
|
final EditText editTextQYWXAppToUser = view1.findViewById(R.id.editTextQYWXAppToUser);
|
||||||
|
final Switch switchQYWXAppAtAll = view1.findViewById(R.id.switchQYWXAppAtAll);
|
||||||
|
if (QYWXAppSettingVo != null) {
|
||||||
|
editTextQYWXAppCorpID.setText(QYWXAppSettingVo.getCorpID());
|
||||||
|
editTextQYWXAppAgentID.setText(QYWXAppSettingVo.getAgentID());
|
||||||
|
editTextQYWXAppSecret.setText(QYWXAppSettingVo.getSecret());
|
||||||
|
editTextQYWXAppToUser.setText(QYWXAppSettingVo.getToUser());
|
||||||
|
switchQYWXAppAtAll.setChecked(QYWXAppSettingVo.getAtAll());
|
||||||
|
linearLayoutQYWXAppToUser.setVisibility((Boolean) QYWXAppSettingVo.getAtAll() ? View.GONE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
switchQYWXAppAtAll.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
linearLayoutQYWXAppToUser.setVisibility(View.GONE);
|
||||||
|
editTextQYWXAppToUser.setText("@all");
|
||||||
|
} else {
|
||||||
|
linearLayoutQYWXAppToUser.setVisibility(View.VISIBLE);
|
||||||
|
editTextQYWXAppToUser.setText("");
|
||||||
|
}
|
||||||
|
Log.d(TAG, "onCheckedChanged:" + isChecked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Button buttonBarkOk = view1.findViewById(R.id.buttonBarkOk);
|
Button buttonQYWXAppok = view1.findViewById(R.id.buttonQYWXAppOk);
|
||||||
Button buttonBarkDel = view1.findViewById(R.id.buttonBarkDel);
|
Button buttonQYWXAppdel = view1.findViewById(R.id.buttonQYWXAppDel);
|
||||||
Button buttonBarkTest = view1.findViewById(R.id.buttonBarkTest);
|
Button buttonQYWXApptest = view1.findViewById(R.id.buttonQYWXAppTest);
|
||||||
alertDialog71
|
alertDialog71
|
||||||
.setTitle(R.string.setbarktitle)
|
.setTitle(R.string.setqywxapptitle)
|
||||||
.setIcon(R.mipmap.bark)
|
.setIcon(R.mipmap.qywxapp)
|
||||||
.setView(view1)
|
.setView(view1)
|
||||||
.create();
|
.create();
|
||||||
final AlertDialog show = alertDialog71.show();
|
final AlertDialog show = alertDialog71.show();
|
||||||
|
buttonQYWXAppok.setOnClickListener(new View.OnClickListener() {
|
||||||
buttonBarkOk.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
String toUser = editTextQYWXAppToUser.getText().toString();
|
||||||
|
if (toUser == null || toUser.isEmpty()) {
|
||||||
|
Toast.makeText(SenderActivity.this, "指定成员 不能为空 或者 选择@all", Toast.LENGTH_LONG).show();
|
||||||
|
editTextQYWXAppToUser.setFocusable(true);
|
||||||
|
editTextQYWXAppToUser.requestFocus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (senderModel == null) {
|
if (senderModel == null) {
|
||||||
SenderModel newSenderModel = new SenderModel();
|
SenderModel newSenderModel = new SenderModel();
|
||||||
newSenderModel.setName(editTextBarkName.getText().toString());
|
newSenderModel.setName(editTextQYWXAppName.getText().toString());
|
||||||
newSenderModel.setType(TYPE_BARK);
|
newSenderModel.setType(TYPE_QYWX_APP);
|
||||||
newSenderModel.setStatus(STATUS_ON);
|
newSenderModel.setStatus(STATUS_ON);
|
||||||
BarkSettingVo barkSettingVoNew = new BarkSettingVo(
|
QYWXAppSettingVo QYWXAppSettingVonew = new QYWXAppSettingVo(
|
||||||
editTextBarkServer.getText().toString()
|
editTextQYWXAppCorpID.getText().toString(),
|
||||||
);
|
editTextQYWXAppAgentID.getText().toString(),
|
||||||
newSenderModel.setJsonSetting(JSON.toJSONString(barkSettingVoNew));
|
editTextQYWXAppSecret.getText().toString(),
|
||||||
|
editTextQYWXAppToUser.getText().toString(),
|
||||||
|
switchQYWXAppAtAll.isChecked());
|
||||||
|
newSenderModel.setJsonSetting(JSON.toJSONString(QYWXAppSettingVonew));
|
||||||
SenderUtil.addSender(newSenderModel);
|
SenderUtil.addSender(newSenderModel);
|
||||||
initSenders();
|
initSenders();
|
||||||
adapter.add(senderModels);
|
adapter.add(senderModels);
|
||||||
} else {
|
} else {
|
||||||
senderModel.setName(editTextBarkName.getText().toString());
|
senderModel.setName(editTextQYWXAppName.getText().toString());
|
||||||
senderModel.setType(TYPE_BARK);
|
senderModel.setType(TYPE_QYWX_APP);
|
||||||
senderModel.setStatus(STATUS_ON);
|
senderModel.setStatus(STATUS_ON);
|
||||||
BarkSettingVo barkSettingVoNew = new BarkSettingVo(
|
QYWXAppSettingVo QYWXAppSettingVonew = new QYWXAppSettingVo(
|
||||||
editTextBarkServer.getText().toString()
|
editTextQYWXAppCorpID.getText().toString(),
|
||||||
);
|
editTextQYWXAppAgentID.getText().toString(),
|
||||||
senderModel.setJsonSetting(JSON.toJSONString(barkSettingVoNew));
|
editTextQYWXAppSecret.getText().toString(),
|
||||||
|
editTextQYWXAppToUser.getText().toString(),
|
||||||
|
switchQYWXAppAtAll.isChecked());
|
||||||
|
senderModel.setJsonSetting(JSON.toJSONString(QYWXAppSettingVonew));
|
||||||
SenderUtil.updateSender(senderModel);
|
SenderUtil.updateSender(senderModel);
|
||||||
initSenders();
|
initSenders();
|
||||||
adapter.update(senderModels);
|
adapter.update(senderModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
show.dismiss();
|
show.dismiss();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
buttonBarkDel.setOnClickListener(new View.OnClickListener() {
|
buttonQYWXAppdel.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (senderModel != null) {
|
if (senderModel != null) {
|
||||||
@ -687,19 +825,23 @@ public class SenderActivity extends AppCompatActivity {
|
|||||||
show.dismiss();
|
show.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
buttonBarkTest.setOnClickListener(new View.OnClickListener() {
|
buttonQYWXApptest.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
String barkServer = editTextBarkServer.getText().toString();
|
String cropID = editTextQYWXAppCorpID.getText().toString();
|
||||||
if (!barkServer.isEmpty()) {
|
String agentID = editTextQYWXAppAgentID.getText().toString();
|
||||||
|
String secret = editTextQYWXAppSecret.getText().toString();
|
||||||
|
String toUser = editTextQYWXAppToUser.getText().toString();
|
||||||
|
//Boolean atAll = switchQYWXAppAtAll.isChecked();
|
||||||
|
if (toUser != null && !toUser.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
SenderBarkMsg.sendMsg(handler, barkServer, "19999999999", "【京东】验证码为387481(切勿将验证码告知他人),请在页面中输入完成验证,如有问题请点击 ihelp.jd.com 联系京东客服", "18888888888");
|
SenderQyWxAppMsg.sendMsg(handler, cropID, agentID, secret, toUser, "测试内容(content)@" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())), true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show();
|
Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(SenderActivity.this, "bark-server 不能为空", Toast.LENGTH_LONG).show();
|
Toast.makeText(SenderActivity.this, "指定成员 不能为空 或者 选择@all", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -11,7 +11,8 @@ public class SenderModel {
|
|||||||
public static final int TYPE_BARK = 2;
|
public static final int TYPE_BARK = 2;
|
||||||
public static final int TYPE_WEB_NOTIFY = 3;
|
public static final int TYPE_WEB_NOTIFY = 3;
|
||||||
public static final int TYPE_QYWX_GROUP_ROBOT = 4;
|
public static final int TYPE_QYWX_GROUP_ROBOT = 4;
|
||||||
public static final int TYPE_MESSAGE = 5;
|
public static final int TYPE_QYWX_APP = 5;
|
||||||
|
public static final int TYPE_MESSAGE = 6;
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
private int status;
|
private int status;
|
||||||
@ -37,17 +38,18 @@ public class SenderModel {
|
|||||||
return R.mipmap.dingding;
|
return R.mipmap.dingding;
|
||||||
case (TYPE_EMAIL):
|
case (TYPE_EMAIL):
|
||||||
return R.mipmap.email;
|
return R.mipmap.email;
|
||||||
case (TYPE_MESSAGE):
|
case (TYPE_BARK):
|
||||||
return R.mipmap.sms;
|
return R.mipmap.bark;
|
||||||
case (TYPE_WEB_NOTIFY):
|
case (TYPE_WEB_NOTIFY):
|
||||||
return R.mipmap.webhook;
|
return R.mipmap.webhook;
|
||||||
case (TYPE_QYWX_GROUP_ROBOT):
|
case (TYPE_QYWX_GROUP_ROBOT):
|
||||||
return R.mipmap.qywx;
|
return R.mipmap.qywx;
|
||||||
case (TYPE_BARK):
|
case (TYPE_QYWX_APP):
|
||||||
return R.mipmap.bark;
|
return R.mipmap.qywxapp;
|
||||||
|
case (TYPE_MESSAGE):
|
||||||
|
return R.mipmap.sms;
|
||||||
default:
|
default:
|
||||||
return R.mipmap.ic_launcher;
|
return R.mipmap.ic_launcher;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,14 +99,16 @@ public class SenderModel {
|
|||||||
return R.mipmap.dingding;
|
return R.mipmap.dingding;
|
||||||
case (TYPE_EMAIL):
|
case (TYPE_EMAIL):
|
||||||
return R.mipmap.email;
|
return R.mipmap.email;
|
||||||
case (TYPE_MESSAGE):
|
case (TYPE_BARK):
|
||||||
return R.mipmap.sms;
|
return R.mipmap.bark;
|
||||||
case (TYPE_WEB_NOTIFY):
|
case (TYPE_WEB_NOTIFY):
|
||||||
return R.mipmap.webhook;
|
return R.mipmap.webhook;
|
||||||
case (TYPE_QYWX_GROUP_ROBOT):
|
case (TYPE_QYWX_GROUP_ROBOT):
|
||||||
return R.mipmap.qywx;
|
return R.mipmap.qywx;
|
||||||
case (TYPE_BARK):
|
case (TYPE_QYWX_APP):
|
||||||
return R.mipmap.bark;
|
return R.mipmap.qywxapp;
|
||||||
|
case (TYPE_MESSAGE):
|
||||||
|
return R.mipmap.sms;
|
||||||
default:
|
default:
|
||||||
return R.mipmap.ic_launcher;
|
return R.mipmap.ic_launcher;
|
||||||
|
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.idormy.sms.forwarder.model.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class QYWXAppSettingVo implements Serializable {
|
||||||
|
private String corpID;
|
||||||
|
private String agentID;
|
||||||
|
private String secret;
|
||||||
|
private String toUser;
|
||||||
|
private Boolean atAll;
|
||||||
|
|
||||||
|
public QYWXAppSettingVo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public QYWXAppSettingVo(String corpID, String agentID, String secret, String toUser, Boolean atAll) {
|
||||||
|
this.corpID = corpID;
|
||||||
|
this.agentID = agentID;
|
||||||
|
this.secret = secret;
|
||||||
|
this.toUser = toUser;
|
||||||
|
this.atAll = atAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCorpID() {
|
||||||
|
return corpID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCorpID(String corpID) {
|
||||||
|
this.corpID = corpID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAgentID() {
|
||||||
|
return agentID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAgentID(String agentID) {
|
||||||
|
this.agentID = agentID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecret() {
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(String secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToUser() {
|
||||||
|
return toUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToUser(String toUser) {
|
||||||
|
this.toUser = toUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getAtAll() {
|
||||||
|
return atAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAtAll(Boolean atAll) {
|
||||||
|
this.atAll = atAll;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import com.idormy.sms.forwarder.model.SenderModel;
|
|||||||
import com.idormy.sms.forwarder.model.vo.BarkSettingVo;
|
import com.idormy.sms.forwarder.model.vo.BarkSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.DingDingSettingVo;
|
import com.idormy.sms.forwarder.model.vo.DingDingSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.EmailSettingVo;
|
import com.idormy.sms.forwarder.model.vo.EmailSettingVo;
|
||||||
|
import com.idormy.sms.forwarder.model.vo.QYWXAppSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
|
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.SmsVo;
|
import com.idormy.sms.forwarder.model.vo.SmsVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.WebNotifySettingVo;
|
import com.idormy.sms.forwarder.model.vo.WebNotifySettingVo;
|
||||||
@ -20,6 +21,7 @@ import java.util.List;
|
|||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_BARK;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_BARK;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_DINGDING;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_DINGDING;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_EMAIL;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_EMAIL;
|
||||||
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_APP;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_GROUP_ROBOT;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_GROUP_ROBOT;
|
||||||
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_WEB_NOTIFY;
|
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_WEB_NOTIFY;
|
||||||
|
|
||||||
@ -115,8 +117,8 @@ public class SendUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TYPE_EMAIL:
|
case TYPE_EMAIL:
|
||||||
//try phrase json setting
|
//try phrase json setting
|
||||||
if (senderModel.getJsonSetting() != null) {
|
if (senderModel.getJsonSetting() != null) {
|
||||||
@ -131,37 +133,6 @@ public class SendUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
case TYPE_WEB_NOTIFY:
|
|
||||||
//try phrase json setting
|
|
||||||
if (senderModel.getJsonSetting() != null) {
|
|
||||||
WebNotifySettingVo webNotifySettingVo = JSON.parseObject(senderModel.getJsonSetting(), WebNotifySettingVo.class);
|
|
||||||
if (webNotifySettingVo != null) {
|
|
||||||
try {
|
|
||||||
SenderWebNotifyMsg.sendMsg(handError, webNotifySettingVo.getToken(), webNotifySettingVo.getSecret(), smsVo.getMobile(), smsVo.getSmsVoForSend());
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "senderSendMsg: SenderWebNotifyMsg error " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case TYPE_QYWX_GROUP_ROBOT:
|
|
||||||
//try phrase json setting
|
|
||||||
if (senderModel.getJsonSetting() != null) {
|
|
||||||
QYWXGroupRobotSettingVo qywxGroupRobotSettingVo = JSON.parseObject(senderModel.getJsonSetting(), QYWXGroupRobotSettingVo.class);
|
|
||||||
if (qywxGroupRobotSettingVo != null) {
|
|
||||||
try {
|
|
||||||
SenderQyWxGroupRobotMsg.sendMsg(handError, qywxGroupRobotSettingVo.getWebHook(), smsVo.getMobile(), smsVo.getSmsVoForSend());
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "senderSendMsg: SenderQyWxGroupRobotMsg error " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TYPE_BARK:
|
case TYPE_BARK:
|
||||||
@ -177,8 +148,53 @@ public class SendUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TYPE_WEB_NOTIFY:
|
||||||
|
//try phrase json setting
|
||||||
|
if (senderModel.getJsonSetting() != null) {
|
||||||
|
WebNotifySettingVo webNotifySettingVo = JSON.parseObject(senderModel.getJsonSetting(), WebNotifySettingVo.class);
|
||||||
|
if (webNotifySettingVo != null) {
|
||||||
|
try {
|
||||||
|
SenderWebNotifyMsg.sendMsg(handError, webNotifySettingVo.getToken(), webNotifySettingVo.getSecret(), smsVo.getMobile(), smsVo.getSmsVoForSend());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "senderSendMsg: SenderWebNotifyMsg error " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_QYWX_GROUP_ROBOT:
|
||||||
|
//try phrase json setting
|
||||||
|
if (senderModel.getJsonSetting() != null) {
|
||||||
|
QYWXGroupRobotSettingVo qywxGroupRobotSettingVo = JSON.parseObject(senderModel.getJsonSetting(), QYWXGroupRobotSettingVo.class);
|
||||||
|
if (qywxGroupRobotSettingVo != null) {
|
||||||
|
try {
|
||||||
|
SenderQyWxGroupRobotMsg.sendMsg(handError, qywxGroupRobotSettingVo.getWebHook(), smsVo.getMobile(), smsVo.getSmsVoForSend());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "senderSendMsg: SenderQyWxGroupRobotMsg error " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_QYWX_APP:
|
||||||
|
//try phrase json setting
|
||||||
|
if (senderModel.getJsonSetting() != null) {
|
||||||
|
QYWXAppSettingVo qYWXAppSettingVo = JSON.parseObject(senderModel.getJsonSetting(), QYWXAppSettingVo.class);
|
||||||
|
if (qYWXAppSettingVo != null) {
|
||||||
|
try {
|
||||||
|
SenderQyWxAppMsg.sendMsg(handError, qYWXAppSettingVo.getCorpID(), qYWXAppSettingVo.getAgentID(), qYWXAppSettingVo.getSecret(), qYWXAppSettingVo.getToUser(), smsVo.getSmsVoForSend(), false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "senderSendMsg: qywx_app error " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,209 @@
|
|||||||
|
package com.idormy.sms.forwarder.utils;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.util.Base64;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.idormy.sms.forwarder.MyApplication;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
import static com.idormy.sms.forwarder.SenderActivity.NOTIFY;
|
||||||
|
|
||||||
|
public class SenderQyWxAppMsg {
|
||||||
|
|
||||||
|
static String TAG = "SenderQyWxAppMsg";
|
||||||
|
|
||||||
|
public static void sendMsg(String msg) throws Exception {
|
||||||
|
|
||||||
|
String webhook_token = "https://oapi.dingtalk.com/robot/send?access_token=" + SettingUtil.get_using_dingding_token();
|
||||||
|
String webhook_secret = SettingUtil.get_using_dingding_secret();
|
||||||
|
if (webhook_token.equals("")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!webhook_secret.equals("")) {
|
||||||
|
Long timestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
|
String stringToSign = timestamp + "\n" + webhook_secret;
|
||||||
|
Mac mac = Mac.getInstance("HmacSHA256");
|
||||||
|
mac.init(new SecretKeySpec(webhook_secret.getBytes("UTF-8"), "HmacSHA256"));
|
||||||
|
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
|
||||||
|
String sign = URLEncoder.encode(new String(Base64.encode(signData, Base64.NO_WRAP)), "UTF-8");
|
||||||
|
webhook_token += "×tamp=" + timestamp + "&sign=" + sign;
|
||||||
|
Log.i(TAG, "webhook_token:" + webhook_token);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
final String msgf = msg;
|
||||||
|
String textMsg = "{ \"msgtype\": \"text\", \"text\": {\"content\": \"" + msg + "\"}}";
|
||||||
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"),
|
||||||
|
textMsg);
|
||||||
|
|
||||||
|
final Request request = new Request.Builder()
|
||||||
|
.url(webhook_token)
|
||||||
|
.addHeader("Content-Type", "application/json; charset=utf-8")
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
Call call = client.newCall(request);
|
||||||
|
call.enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, IOException e) {
|
||||||
|
Log.d(TAG, "onFailure:" + e.getMessage());
|
||||||
|
SendHistory.addHistory("钉钉转发:" + msgf + "onFailure:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
final String responseStr = response.body().string();
|
||||||
|
Log.d(TAG, "Code:" + String.valueOf(response.code()) + responseStr);
|
||||||
|
SendHistory.addHistory("钉钉转发:" + msgf + "Code:" + String.valueOf(response.code()) + responseStr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendMsg(final Handler handError, String corpID, String agentID, String secret, String toUser, String content, boolean forceRefresh) throws Exception {
|
||||||
|
Log.i(TAG, "sendMsg corpID:" + corpID + " agentID:" + agentID + " secret:" + secret + " toUser:" + toUser + " content:" + content + " forceRefresh:" + forceRefresh);
|
||||||
|
|
||||||
|
if (corpID == null || corpID.isEmpty() || agentID == null || agentID.isEmpty() || secret == null || secret.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO:判断access_token是否失效
|
||||||
|
if (forceRefresh == true
|
||||||
|
|| MyApplication.QyWxAccessToken == null || MyApplication.QyWxAccessToken.isEmpty()
|
||||||
|
|| System.currentTimeMillis() > MyApplication.QyWxAccessTokenExpiresIn) {
|
||||||
|
String gettokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?";
|
||||||
|
gettokenUrl += "corpid=" + corpID;
|
||||||
|
gettokenUrl += "&corpsecret=" + secret;
|
||||||
|
Log.d(TAG, "gettokenUrl:" + gettokenUrl);
|
||||||
|
|
||||||
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
final Request request = new Request.Builder().url(gettokenUrl).get().build();
|
||||||
|
Call call = client.newCall(request);
|
||||||
|
call.enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, final IOException e) {
|
||||||
|
Log.d(TAG, "onFailure:" + e.getMessage());
|
||||||
|
if (handError != null) {
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.what = NOTIFY;
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("DATA", "获取access_token失败:" + e.getMessage());
|
||||||
|
msg.setData(bundle);
|
||||||
|
handError.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
final String json = response.body().string();
|
||||||
|
Log.d(TAG, "Code:" + response.code() + " Response: " + json);
|
||||||
|
JSONObject jsonObject = JSON.parseObject(json);
|
||||||
|
int errcode = jsonObject.getInteger("errcode");
|
||||||
|
if (errcode == 0) {
|
||||||
|
MyApplication.QyWxAccessToken = jsonObject.getString("access_token");
|
||||||
|
MyApplication.QyWxAccessTokenExpiresIn = System.currentTimeMillis() + (jsonObject.getInteger("expires_in") - 120) * 1000; //提前2分钟过期
|
||||||
|
Log.d(TAG, "access_token:" + MyApplication.QyWxAccessToken);
|
||||||
|
Log.d(TAG, "expires_in:" + MyApplication.QyWxAccessTokenExpiresIn);
|
||||||
|
|
||||||
|
sendTextMsg(handError, agentID, toUser, content);
|
||||||
|
} else {
|
||||||
|
String errmsg = jsonObject.getString("errmsg");
|
||||||
|
Log.d(TAG, "onFailure:" + errmsg);
|
||||||
|
if (handError != null) {
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.what = NOTIFY;
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("DATA", "获取access_token失败:" + errmsg);
|
||||||
|
msg.setData(bundle);
|
||||||
|
handError.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sendTextMsg(handError, agentID, toUser, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//发送文本消息
|
||||||
|
public static void sendTextMsg(final Handler handError, String agentID, String toUser, String content) {
|
||||||
|
String sendUrl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + MyApplication.QyWxAccessToken;
|
||||||
|
Log.d(TAG, "sendUrl:" + sendUrl);
|
||||||
|
|
||||||
|
Map textMsgMap = new HashMap();
|
||||||
|
textMsgMap.put("touser", toUser);
|
||||||
|
textMsgMap.put("msgtype", "text");
|
||||||
|
textMsgMap.put("agentid", agentID);
|
||||||
|
|
||||||
|
Map textText = new HashMap();
|
||||||
|
textText.put("content", content);
|
||||||
|
textMsgMap.put("text", textText);
|
||||||
|
|
||||||
|
String textMsg = JSON.toJSONString(textMsgMap);
|
||||||
|
Log.d(TAG, "textMsg:" + textMsg);
|
||||||
|
|
||||||
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), textMsg);
|
||||||
|
|
||||||
|
final Request request = new Request.Builder()
|
||||||
|
.url(sendUrl)
|
||||||
|
.addHeader("Content-Type", "application/json; charset=utf-8")
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
Call call = client.newCall(request);
|
||||||
|
call.enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, final IOException e) {
|
||||||
|
Log.d(TAG, "onFailure:" + e.getMessage());
|
||||||
|
if (handError != null) {
|
||||||
|
android.os.Message msg = new android.os.Message();
|
||||||
|
msg.what = NOTIFY;
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("DATA", "发送失败:" + e.getMessage());
|
||||||
|
msg.setData(bundle);
|
||||||
|
handError.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
final String responseStr = response.body().string();
|
||||||
|
Log.d(TAG, "Code:" + String.valueOf(response.code()) + " Response: " + responseStr);
|
||||||
|
|
||||||
|
if (handError != null) {
|
||||||
|
android.os.Message msg = new android.os.Message();
|
||||||
|
msg.what = NOTIFY;
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("DATA", "发送状态:" + responseStr);
|
||||||
|
msg.setData(bundle);
|
||||||
|
handError.sendMessage(msg);
|
||||||
|
Log.d(TAG, "Code:" + String.valueOf(response.code()) + " Response: " + responseStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,194 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="设置名称"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editTextQYWXAppName"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:inputType=""
|
||||||
|
android:text="" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="企业ID"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editTextQYWXAppCorpID"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:inputType=""
|
||||||
|
android:text="" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="AgentID"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editTextQYWXAppAgentID"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:inputType=""
|
||||||
|
android:text="" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="Secret"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editTextQYWXAppSecret"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:inputType=""
|
||||||
|
android:text="" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="是否@all"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/switchQYWXAppAtAll"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:checked="false" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/linearLayoutQYWXAppToUser"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="指定成员"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editTextQYWXAppToUser"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:inputType=""
|
||||||
|
android:text="" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:text="Tip:指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonQYWXAppOk"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/ok" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonQYWXAppDel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/del" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonQYWXAppTest"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/test" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
BIN
app/src/main/res/mipmap-hdpi/qywxapp.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/qywxapp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/res/mipmap-mdpi/qywxapp.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/qywxapp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-xhdpi/qywxapp.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/qywxapp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/qywxapp.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/qywxapp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/qywxapp.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/qywxapp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
@ -6,6 +6,6 @@
|
|||||||
<item>转发到Bark</item>
|
<item>转发到Bark</item>
|
||||||
<item>转发到Webhook</item>
|
<item>转发到Webhook</item>
|
||||||
<item>转发到企业微信群机器人</item>
|
<item>转发到企业微信群机器人</item>
|
||||||
<!--<item>转发到其他手机(SMS)</item>-->
|
<item>转发到企业微信应用消息</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
@ -10,6 +10,7 @@
|
|||||||
<string name="setemailtitle">设置邮箱</string>
|
<string name="setemailtitle">设置邮箱</string>
|
||||||
<string name="setwebnotifytitle">设置Webhook</string>
|
<string name="setwebnotifytitle">设置Webhook</string>
|
||||||
<string name="setqywxgrouprobottitle">设置企业微信群机器人</string>
|
<string name="setqywxgrouprobottitle">设置企业微信群机器人</string>
|
||||||
|
<string name="setqywxapptitle">设置企业微信应用</string>
|
||||||
<string name="setbarktitle">设置Bark</string>
|
<string name="setbarktitle">设置Bark</string>
|
||||||
<string name="check_new_version">检查更新</string>
|
<string name="check_new_version">检查更新</string>
|
||||||
<string name="to_setting">设置</string>
|
<string name="to_setting">设置</string>
|
||||||
|
BIN
pic/sendersetqywxapp.png
Normal file
BIN
pic/sendersetqywxapp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 206 KiB |
BIN
psd/xxxhdpi.psd
BIN
psd/xxxhdpi.psd
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user