-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from rememberber/develop
新增支持云片网短信
- Loading branch information
Showing
15 changed files
with
537 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/main/java/com/fangxuele/tool/wechat/push/logic/YunpianSmsMsgServiceThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.fangxuele.tool.wechat.push.logic; | ||
|
||
import com.fangxuele.tool.wechat.push.ui.Init; | ||
import com.fangxuele.tool.wechat.push.ui.MainWindow; | ||
import com.github.qcloudsms.SmsSingleSender; | ||
import com.github.qcloudsms.SmsSingleSenderResult; | ||
import com.yunpian.sdk.YunpianClient; | ||
import com.yunpian.sdk.model.Result; | ||
import com.yunpian.sdk.model.SmsSingleSend; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.swing.*; | ||
import java.util.Map; | ||
|
||
/** | ||
* 云片网短信发送服务线程 | ||
* Created by rememberber(https://github.com/rememberber) on 2018/7/13. | ||
*/ | ||
public class YunpianSmsMsgServiceThread extends BaseMsgServiceThread { | ||
|
||
/** | ||
* 构造函数 | ||
* | ||
* @param pageFrom 起始页 | ||
* @param pageTo 截止页 | ||
* @param pageSize 页大小 | ||
*/ | ||
public YunpianSmsMsgServiceThread(int pageFrom, int pageTo, int pageSize) { | ||
super(pageFrom, pageTo, pageSize); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
|
||
// 初始化当前线程 | ||
initCurrentThread(); | ||
|
||
String yunpianApiKey = Init.configer.getYunpianApiKey(); | ||
|
||
if (StringUtils.isEmpty(yunpianApiKey)) { | ||
JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), | ||
"请先在设置中填写并保存云片网短信相关配置!", "提示", | ||
JOptionPane.INFORMATION_MESSAGE); | ||
} | ||
|
||
YunpianClient clnt = new YunpianClient(yunpianApiKey).init(); | ||
|
||
for (int i = 0; i < list.size(); i++) { | ||
if (!PushData.running) { | ||
// 停止 | ||
PushData.increaseStopedThread(); | ||
return; | ||
} | ||
|
||
// 本条消息所需的数据 | ||
String[] msgData = list.get(i); | ||
String telNum = msgData[0]; | ||
try { | ||
Map<String, String> params = PushManage.makeYunpianMessage(msgData); | ||
params.put(YunpianClient.MOBILE, telNum); | ||
|
||
// 空跑控制 | ||
if (!MainWindow.mainWindow.getDryRunCheckBox().isSelected()) { | ||
Result<SmsSingleSend> result = clnt.sms().single_send(params); | ||
|
||
if (result.getCode() == 0) { | ||
// 总发送成功+1 | ||
PushData.increaseSuccess(); | ||
MainWindow.mainWindow.getPushSuccessCount().setText(String.valueOf(PushData.successRecords)); | ||
|
||
// 当前线程发送成功+1 | ||
currentThreadSuccessCount++; | ||
tableModel.setValueAt(currentThreadSuccessCount, tableRow, 2); | ||
|
||
// 保存发送成功 | ||
PushData.sendSuccessList.add(msgData); | ||
} else { | ||
// 总发送失败+1 | ||
PushData.increaseFail(); | ||
MainWindow.mainWindow.getPushFailCount().setText(String.valueOf(PushData.failRecords)); | ||
|
||
// 保存发送失败 | ||
PushData.sendFailList.add(msgData); | ||
|
||
// 失败异常信息输出控制台 | ||
PushManage.console(new StringBuffer().append("发送失败:").append(result.toString()) | ||
.append(";telNum:").append(telNum).toString()); | ||
|
||
// 当前线程发送失败+1 | ||
currentThreadFailCount++; | ||
tableModel.setValueAt(currentThreadFailCount, tableRow, 3); | ||
} | ||
} else { | ||
// 总发送成功+1 | ||
PushData.increaseSuccess(); | ||
MainWindow.mainWindow.getPushSuccessCount().setText(String.valueOf(PushData.successRecords)); | ||
|
||
// 当前线程发送成功+1 | ||
currentThreadSuccessCount++; | ||
tableModel.setValueAt(currentThreadSuccessCount, tableRow, 2); | ||
|
||
// 保存发送成功 | ||
PushData.sendSuccessList.add(msgData); | ||
} | ||
|
||
} catch (Exception e) { | ||
// 总发送失败+1 | ||
PushData.increaseFail(); | ||
MainWindow.mainWindow.getPushFailCount().setText(String.valueOf(PushData.failRecords)); | ||
|
||
// 保存发送失败 | ||
PushData.sendFailList.add(msgData); | ||
|
||
// 失败异常信息输出控制台 | ||
PushManage.console(new StringBuffer().append("发送失败:").append(e.getMessage()).append(";telNum:").append(telNum).toString()); | ||
|
||
// 当前线程发送失败+1 | ||
currentThreadFailCount++; | ||
tableModel.setValueAt(currentThreadFailCount, tableRow, 3); | ||
} | ||
// 当前线程进度条 | ||
tableModel.setValueAt((int) ((double) (i + 1) / list.size() * 100), tableRow, 5); | ||
|
||
// 总进度条 | ||
MainWindow.mainWindow.getPushTotalProgressBar().setValue((int) (PushData.successRecords + PushData.failRecords)); | ||
} | ||
|
||
// 当前线程结束 | ||
clnt.close(); | ||
currentThreadFinish(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.