为系统用户添加代理组织
This commit is contained in:
parent
15cbce2cc2
commit
83a0563f66
@ -1,20 +0,0 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.AgentCompanyEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public interface AgentCompanyDao extends JpaRepository<AgentCompanyEntity, Long>, JpaSpecificationExecutor<AgentCompanyEntity> {
|
||||
|
||||
@Query(value = "SELECT * FROM agent_company WHERE company_name = ?1 LIMIT 1", nativeQuery = true)
|
||||
AgentCompanyEntity selectCompanyNameEquals(String companyName);
|
||||
|
||||
@Query(value = "SELECT * FROM agent_company WHERE company_name != ?1", nativeQuery = true)
|
||||
List<AgentCompanyEntity> selectCompanyNameNotEquals(String companyName);
|
||||
|
||||
}
|
11
src/main/java/com/xkrs/dao/AgentOrgDao.java
Normal file
11
src/main/java/com/xkrs/dao/AgentOrgDao.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.AgentOrgEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public interface AgentOrgDao extends JpaRepository<AgentOrgEntity, Long>, JpaSpecificationExecutor<AgentOrgEntity> {
|
||||
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "agent_company")
|
||||
public class AgentCompanyEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "agent_company_seq_gen")
|
||||
@SequenceGenerator(name = "agent_company_seq_gen", sequenceName = "agent_company_id_seq", allocationSize = 1)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司名称
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String companyName;
|
||||
|
||||
/**
|
||||
* 省市区编码
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String countyCode;
|
||||
|
||||
/**
|
||||
* 签约截止日期
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String signDeadLine;
|
||||
|
||||
/**
|
||||
* 密钥ID
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String secretId;
|
||||
|
||||
/**
|
||||
* 密钥KEY
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* APPID
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 签名信息
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 短信模板ID
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String templateId;
|
||||
|
||||
public AgentCompanyEntity() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCompanyName() {
|
||||
return companyName;
|
||||
}
|
||||
|
||||
public void setCompanyName(String companyName) {
|
||||
this.companyName = companyName;
|
||||
}
|
||||
|
||||
public String getCountyCode() {
|
||||
return countyCode;
|
||||
}
|
||||
|
||||
public void setCountyCode(String countyCode) {
|
||||
this.countyCode = countyCode;
|
||||
}
|
||||
|
||||
public String getSignDeadLine() {
|
||||
return signDeadLine;
|
||||
}
|
||||
|
||||
public void setSignDeadLine(String signDeadLine) {
|
||||
this.signDeadLine = signDeadLine;
|
||||
}
|
||||
|
||||
public String getSecretId() {
|
||||
return secretId;
|
||||
}
|
||||
|
||||
public void setSecretId(String secretId) {
|
||||
this.secretId = secretId;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public String getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
public void setTemplateId(String templateId) {
|
||||
this.templateId = templateId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AgentCompanyEntity{" +
|
||||
"id=" + id +
|
||||
", companyName='" + companyName + '\'' +
|
||||
", countyCode='" + countyCode + '\'' +
|
||||
", signDeadLine='" + signDeadLine + '\'' +
|
||||
", secretId='" + secretId + '\'' +
|
||||
", secretKey='" + secretKey + '\'' +
|
||||
", appId='" + appId + '\'' +
|
||||
", sign='" + sign + '\'' +
|
||||
", templateId='" + templateId + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
56
src/main/java/com/xkrs/model/entity/AgentOrgEntity.java
Normal file
56
src/main/java/com/xkrs/model/entity/AgentOrgEntity.java
Normal file
@ -0,0 +1,56 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "agent_org")
|
||||
public class AgentOrgEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "agent_org_seq_gen")
|
||||
@SequenceGenerator(name = "agent_org_seq_gen", sequenceName = "agent_org_id_seq", allocationSize = 1)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 代理名称
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String orgName;
|
||||
|
||||
/**
|
||||
* 截止日期
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String deadLine;
|
||||
|
||||
public AgentOrgEntity() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getOrgName() {
|
||||
return orgName;
|
||||
}
|
||||
|
||||
public void setOrgName(String orgName) {
|
||||
this.orgName = orgName;
|
||||
}
|
||||
|
||||
public String getDeadLine() {
|
||||
return deadLine;
|
||||
}
|
||||
|
||||
public void setDeadLine(String deadLine) {
|
||||
this.deadLine = deadLine;
|
||||
}
|
||||
}
|
@ -119,6 +119,11 @@ public class SysUserEntity implements Serializable {
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 代理组织的ID
|
||||
*/
|
||||
private Long agentOrgId;
|
||||
|
||||
public SysUserEntity() {
|
||||
}
|
||||
|
||||
@ -314,8 +319,42 @@ public class SysUserEntity implements Serializable {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Long getAgentOrgId() {
|
||||
return agentOrgId;
|
||||
}
|
||||
|
||||
public void setAgentOrgId(Long agentOrgId) {
|
||||
this.agentOrgId = agentOrgId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUserEntity{" + "id=" + id + ", userName='" + userName + '\'' + ", reallyName='" + reallyName + '\'' + ", password='" + password + '\'' + ", salt='" + salt + '\'' + ", telephone='" + telephone + '\'' + ", countyCode='" + countyCode + '\'' + ", signature='" + signature + '\'' + ", activeFlag=" + activeFlag + ", statusCode=" + statusCode + ", addTime='" + addTime + '\'' + ", lastEntryTime=" + lastEntryTime + ", deleteFlag=" + deleteFlag + ", lastEntryIp='" + lastEntryIp + '\'' + ", dayNum=" + dayNum + ", overTime='" + overTime + '\'' + ", accountType='" + accountType + '\'' + ", countyName='" + countyName + '\'' + ", loginNum=" + loginNum + ", loginLastTime='" + loginLastTime + '\'' + ", userAgent='" + userAgent + '\'' + ", vipLevel=" + vipLevel + ", receiveSms=" + receiveSms + ", remark='" + remark + '\'' + '}';
|
||||
return "SysUserEntity{" +
|
||||
"id=" + id +
|
||||
", userName='" + userName + '\'' +
|
||||
", reallyName='" + reallyName + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", salt='" + salt + '\'' +
|
||||
", telephone='" + telephone + '\'' +
|
||||
", countyCode='" + countyCode + '\'' +
|
||||
", signature='" + signature + '\'' +
|
||||
", activeFlag=" + activeFlag +
|
||||
", statusCode=" + statusCode +
|
||||
", addTime='" + addTime + '\'' +
|
||||
", lastEntryTime=" + lastEntryTime +
|
||||
", deleteFlag=" + deleteFlag +
|
||||
", lastEntryIp='" + lastEntryIp + '\'' +
|
||||
", dayNum=" + dayNum +
|
||||
", overTime='" + overTime + '\'' +
|
||||
", accountType='" + accountType + '\'' +
|
||||
", countyName='" + countyName + '\'' +
|
||||
", loginNum=" + loginNum +
|
||||
", loginLastTime='" + loginLastTime + '\'' +
|
||||
", userAgent='" + userAgent + '\'' +
|
||||
", vipLevel=" + vipLevel +
|
||||
", receiveSms=" + receiveSms +
|
||||
", remark='" + remark + '\'' +
|
||||
", agentOrgId=" + agentOrgId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.xkrs.model.vo.AppTaskBodyVo;
|
||||
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
||||
import com.xkrs.service.FirePointService;
|
||||
import com.xkrs.service.GlobalConfigService;
|
||||
import com.xkrs.sms.SMSHelper;
|
||||
import com.xkrs.utils.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -87,7 +88,10 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
private GlobalConfigService globalConfigService;
|
||||
|
||||
@Resource
|
||||
private AgentCompanyDao agentCompanyDao;
|
||||
private AgentOrgDao agentOrgDao;
|
||||
|
||||
@Resource
|
||||
private SMSHelper smsHelper;
|
||||
|
||||
/**
|
||||
* 添加火点信息
|
||||
@ -410,34 +414,17 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
* 发送短信消息
|
||||
*/
|
||||
private void sendSMSMessage(FirePointEntity firePointEntity) {
|
||||
//过滤短信通知收件人
|
||||
List<SysUserEntity> sysUserList = sysUserDao.findAll();
|
||||
List<RelRoleAuthorityEntity> adminList = relRoleAuthorityDao.selectByAuthorityId(1);
|
||||
boolean normalSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(9L);
|
||||
boolean vipSmsEnable = 1L == globalConfigService.selectGlobalConfigValue(10L);
|
||||
List<SysUserEntity> smsReceiverList = FirePointCodeUtils.filterSmsReceiver(firePointEntity.getStreetCode(), sysUserList, adminList, normalSmsEnable, vipSmsEnable);
|
||||
//对收信人进行分组
|
||||
AgentCompanyEntity master = agentCompanyDao.selectCompanyNameEquals("青岛星科瑞升信息科技有限公司");
|
||||
List<AgentCompanyEntity> agentCompanyList = agentCompanyDao.selectCompanyNameNotEquals("青岛星科瑞升信息科技有限公司");
|
||||
Map<AgentCompanyEntity, List<SysUserEntity>> agentCompanyGroupMap = FirePointCodeUtils.groupSmsReceiver(smsReceiverList, master, agentCompanyList);
|
||||
//批量发送短信通知
|
||||
for (Map.Entry<AgentCompanyEntity, List<SysUserEntity>> entry : agentCompanyGroupMap.entrySet()) {
|
||||
AgentCompanyEntity groupAgentCompany = entry.getKey();
|
||||
List<SysUserEntity> groupSysUserList = entry.getValue();
|
||||
if (groupAgentCompany != null && groupSysUserList != null && groupSysUserList.size() > 0) {
|
||||
String[] telephoneArray = new String[groupSysUserList.size()];
|
||||
for (int i = 0; i < groupSysUserList.size(); i++) {
|
||||
telephoneArray[i] = "86" + groupSysUserList.get(i).getUserName();
|
||||
}
|
||||
SMSUtils.sendSmsToUser(groupAgentCompany, telephoneArray, new String[]{firePointEntity.getFirePointAddress()});
|
||||
//记录短信通知日志
|
||||
StringBuilder stringBuilder = new StringBuilder("发送短信消息通知:\n");
|
||||
for (String telephone : telephoneArray) {
|
||||
stringBuilder.append("telephone:").append(telephone).append("\n");
|
||||
}
|
||||
stringBuilder.append(groupAgentCompany.toString()).append("短信内容:").append(firePointEntity.getFirePointAddress());
|
||||
log.info(stringBuilder.toString());
|
||||
}
|
||||
}
|
||||
//对短信通知收件人进行分组
|
||||
List<AgentOrgEntity> agentOrgList = agentOrgDao.findAll();
|
||||
Map<String, List<SysUserEntity>> agentOrgNameGroupMap = FirePointCodeUtils.groupSmsReceiver(smsReceiverList, agentOrgList);
|
||||
//分发短信通知
|
||||
smsHelper.dispatchSMSMessage(agentOrgNameGroupMap, new String[]{firePointEntity.getFirePointAddress()});
|
||||
}
|
||||
|
||||
/**
|
||||
|
97
src/main/java/com/xkrs/sms/SMSHelper.java
Normal file
97
src/main/java/com/xkrs/sms/SMSHelper.java
Normal file
@ -0,0 +1,97 @@
|
||||
package com.xkrs.sms;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.utils.HttpClientUtils;
|
||||
import com.xkrs.utils.SMSUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class SMSHelper {
|
||||
|
||||
public static Logger log = LoggerFactory.getLogger(SMSHelper.class);
|
||||
|
||||
public SMSHelper() {
|
||||
}
|
||||
|
||||
public void dispatchSMSMessage(Map<String, List<SysUserEntity>> agentOrgNameGroupMap, String[] templateParamArray) {
|
||||
for (Map.Entry<String, List<SysUserEntity>> entry : agentOrgNameGroupMap.entrySet()) {
|
||||
String targetAgentOrgName = entry.getKey();
|
||||
List<SysUserEntity> groupSmsReceiverList = entry.getValue();
|
||||
if (groupSmsReceiverList != null && groupSmsReceiverList.size() > 0) {
|
||||
String[] telephoneArray = new String[groupSmsReceiverList.size()];
|
||||
for (int i = 0; i < groupSmsReceiverList.size(); i++) {
|
||||
telephoneArray[i] = "86" + groupSmsReceiverList.get(i).getUserName();
|
||||
}
|
||||
if ("青岛星科瑞升信息科技有限公司".equals(targetAgentOrgName)) {
|
||||
|
||||
xkrsSendSmsToUser(telephoneArray, templateParamArray);
|
||||
|
||||
} else if ("青岛华正信息技术股份有限公司".equals(targetAgentOrgName)) {
|
||||
|
||||
try {
|
||||
huaZhengXinXi(telephoneArray, templateParamArray);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 星科瑞升向用户发送短信
|
||||
*/
|
||||
private void xkrsSendSmsToUser(String[] telephoneArray, String[] templateParamArray) {
|
||||
SMSUtils.sendSmsToUser(telephoneArray, "1425995", templateParamArray);
|
||||
//记录短信通知日志
|
||||
StringBuilder stringBuilder = new StringBuilder("发送人:青岛星科瑞升信息科技有限公司\n");
|
||||
for (String telephone : telephoneArray) {
|
||||
stringBuilder.append("接收人:").append(telephone).append("\n");
|
||||
}
|
||||
for (String templateParam : templateParamArray) {
|
||||
stringBuilder.append("模板参数:").append(templateParam).append("\n");
|
||||
}
|
||||
log.info(stringBuilder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 华正信息向用户发送短信
|
||||
*/
|
||||
private void huaZhengXinXi(String[] telephoneArray, String[] templateParamArray) throws Exception {
|
||||
StringBuilder telephoneBuilder = new StringBuilder();
|
||||
for (int i = 0; i < telephoneArray.length; i++) {
|
||||
telephoneBuilder.append(telephoneArray[i]);
|
||||
if (i < telephoneArray.length - 1) {
|
||||
telephoneBuilder.append(",");
|
||||
}
|
||||
}
|
||||
String telephoneContent = telephoneBuilder.toString();
|
||||
String url = "http://58.56.128.186:10144/msg/msgReceive";
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("receiver", telephoneContent);
|
||||
map.put("msgContent", "{\"content\":\"{'address':'" + templateParamArray[0] + "'}\"}");
|
||||
map.put("idType", "30");
|
||||
map.put("sendChannel", "30");
|
||||
map.put("sendAccount", "12");
|
||||
HttpClientUtils.sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
|
||||
|
||||
//记录短信通知日志
|
||||
StringBuilder stringBuilder = new StringBuilder("发送人:青岛华正信息技术股份有限公司\n");
|
||||
for (String telephone : telephoneArray) {
|
||||
stringBuilder.append("接收人:").append(telephone).append("\n");
|
||||
}
|
||||
for (String templateParam : templateParamArray) {
|
||||
stringBuilder.append("模板参数:").append(templateParam).append("\n");
|
||||
}
|
||||
log.info(stringBuilder.toString());
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import com.xkrs.model.entity.AgentCompanyEntity;
|
||||
import com.xkrs.model.entity.AgentOrgEntity;
|
||||
import com.xkrs.model.entity.RelRoleAuthorityEntity;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@ -91,49 +90,43 @@ public class FirePointCodeUtils {
|
||||
|
||||
/**
|
||||
* 对短信通知收信人进行分组
|
||||
*
|
||||
* @param smsReceiverList 短信通知收信人列表
|
||||
* @param master 星科瑞升
|
||||
* @param agentCompanyList 代理公司列表
|
||||
* @return 分组后的短信通知收信人列表
|
||||
*/
|
||||
public static Map<AgentCompanyEntity, List<SysUserEntity>> groupSmsReceiver(List<SysUserEntity> smsReceiverList, AgentCompanyEntity master, List<AgentCompanyEntity> agentCompanyList) {
|
||||
//数据仓库
|
||||
Map<AgentCompanyEntity, List<SysUserEntity>> groupMap = new HashMap<>();
|
||||
//填充代理公司数据
|
||||
if (agentCompanyList != null && agentCompanyList.size() > 0) {
|
||||
for (AgentCompanyEntity agentCompany : agentCompanyList) {
|
||||
try {
|
||||
if (TextUtils.isEmpty(agentCompany.getCountyCode())) {//区划编码为空的不发短信
|
||||
continue;
|
||||
}
|
||||
String codeNotZeroEnd = FirePointCodeUtils.getCodeNotZeroEnd(agentCompany.getCountyCode());
|
||||
if (TextUtils.isEmpty(codeNotZeroEnd)) {//区划编码后切完0为空的不发短信
|
||||
continue;
|
||||
}
|
||||
List<SysUserEntity> receiverList = new ArrayList<>();
|
||||
for (SysUserEntity smsReceiver : smsReceiverList) {
|
||||
if (smsReceiver.getCountyCode().startsWith(codeNotZeroEnd)) {
|
||||
receiverList.add(smsReceiver);
|
||||
}
|
||||
}
|
||||
groupMap.put(agentCompany, receiverList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static Map<String, List<SysUserEntity>> groupSmsReceiver(List<SysUserEntity> smsReceiverList, List<AgentOrgEntity> agentOrgList) {
|
||||
Map<String, List<SysUserEntity>> groupMap = new HashMap<>();
|
||||
if (smsReceiverList == null || smsReceiverList.isEmpty()) {
|
||||
return groupMap;
|
||||
}
|
||||
if (agentOrgList == null || agentOrgList.isEmpty()) {
|
||||
return groupMap;
|
||||
}
|
||||
for (SysUserEntity smsReceiver : smsReceiverList) {
|
||||
String targetAgentOrgName = getTargetAgentOrgName(smsReceiver, agentOrgList);
|
||||
if (groupMap.containsKey(targetAgentOrgName)) {
|
||||
List<SysUserEntity> groupSmsReceiverList = groupMap.get(targetAgentOrgName);
|
||||
groupSmsReceiverList.add(smsReceiver);
|
||||
} else {
|
||||
List<SysUserEntity> groupSmsReceiverList = new ArrayList<>();
|
||||
groupSmsReceiverList.add(smsReceiver);
|
||||
groupMap.put(targetAgentOrgName, groupSmsReceiverList);
|
||||
}
|
||||
}
|
||||
//填充星科瑞升数据
|
||||
List<SysUserEntity> masterReceiverList = new ArrayList<>();
|
||||
for (Map.Entry<AgentCompanyEntity, List<SysUserEntity>> entry : groupMap.entrySet()) {
|
||||
for (SysUserEntity smsReceiver : entry.getValue()) {
|
||||
if (!smsReceiverList.contains(smsReceiver)) {
|
||||
masterReceiverList.add(smsReceiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
groupMap.put(master, masterReceiverList);
|
||||
return groupMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统用户的代理组织名称
|
||||
*/
|
||||
private static String getTargetAgentOrgName(SysUserEntity smsReceiver, List<AgentOrgEntity> agentOrgList) {
|
||||
for (AgentOrgEntity agentOrg : agentOrgList) {
|
||||
try {
|
||||
if (smsReceiver.getAgentOrgId().longValue() == agentOrg.getId().longValue()) {
|
||||
return agentOrg.getOrgName();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return "青岛星科瑞升信息科技有限公司";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,116 +5,14 @@ import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.sms.v20190711.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20190711.models.PullSmsReplyStatusByPhoneNumberRequest;
|
||||
import com.tencentcloudapi.sms.v20190711.models.PullSmsReplyStatusByPhoneNumberResponse;
|
||||
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
|
||||
import com.xkrs.model.entity.AgentCompanyEntity;
|
||||
|
||||
/**
|
||||
* 短信工具
|
||||
*/
|
||||
public class SMSUtils {
|
||||
|
||||
public static int sendSmsToUser(AgentCompanyEntity agentCompanyEntity, String[] phoneNumbers, String[] templateParams) {
|
||||
|
||||
int resValue = 0;
|
||||
try {
|
||||
/* 必要步骤:
|
||||
* 实例化一个认证对象,入参需要传入腾讯云账户密钥对 secretId 和 secretKey
|
||||
* 可以直接在代码中写入密钥对,但需谨防泄露,不要将代码复制、上传或者分享给他人
|
||||
* CAM 密钥查询:https://console.cloud.tencent.com/cam/capi*/
|
||||
String secretId = agentCompanyEntity.getSecretId();
|
||||
String secretKey = agentCompanyEntity.getSecretKey();
|
||||
Credential cred = new Credential(secretId, secretKey);
|
||||
|
||||
// 实例化一个 http 选项,可选,无特殊需求时可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
// 设置代理
|
||||
// httpProfile.setProxyHost("host");
|
||||
// httpProfile.setProxyPort(6000);
|
||||
httpProfile.setReqMethod("POST");
|
||||
/* SDK 有默认的超时时间,非必要请不要进行调整
|
||||
* 如有需要请在代码中查阅以获取最新的默认值 */
|
||||
httpProfile.setConnTimeout(60);
|
||||
/* SDK 会自动指定域名,通常无需指定域名,但访问金融区的服务时必须手动指定域名
|
||||
* 例如 SMS 的上海金融区域名为 sms.ap-shanghai-fsi.tencentcloudapi.com */
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
|
||||
/* 非必要步骤:
|
||||
* 实例化一个客户端配置对象,可以指定超时时间等配置 */
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
/* SDK 默认用 TC3-HMAC-SHA256 进行签名
|
||||
* 非必要请不要修改该字段 */
|
||||
clientProfile.setSignMethod("HmacSHA256");
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
/* 实例化 SMS 的 client 对象
|
||||
* 第二个参数是地域信息,可以直接填写字符串 ap-guangzhou,或者引用预设的常量 */
|
||||
SmsClient client = new SmsClient(cred, "", clientProfile);
|
||||
/* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数
|
||||
* 您可以直接查询 SDK 源码确定接口有哪些属性可以设置
|
||||
* 属性可能是基本类型,也可能引用了另一个数据结构
|
||||
* 推荐使用 IDE 进行开发,可以方便地跳转查阅各个接口和数据结构的文档说明 */
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
|
||||
/* 填充请求参数,这里 request 对象的成员变量即对应接口的入参
|
||||
* 您可以通过官网接口文档或跳转到 request 对象的定义处查看请求参数的定义
|
||||
* 基本类型的设置:
|
||||
* 帮助链接:
|
||||
* 短信控制台:https://console.cloud.tencent.com/smsv2
|
||||
* sms helper:https://cloud.tencent.com/document/product/382/3773 */
|
||||
|
||||
/* 短信应用 ID: 在 [短信控制台] 添加应用后生成的实际 SDKAppID,例如1400006666 */
|
||||
String appid = agentCompanyEntity.getAppId();
|
||||
req.setSmsSdkAppid(appid);
|
||||
|
||||
/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名,可登录 [短信控制台] 查看签名信息 */
|
||||
String sign = agentCompanyEntity.getSign();
|
||||
req.setSign(sign);
|
||||
|
||||
/* 国际/港澳台短信 senderid: 国内短信填空,默认未开通,如需开通请联系 [sms helper] */
|
||||
// String senderid = "xxx";
|
||||
String senderid = "";
|
||||
req.setSenderId(senderid);
|
||||
|
||||
/* 用户的 session 内容: 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
|
||||
String session = "";
|
||||
req.setSessionContext(session);
|
||||
|
||||
/* 短信码号扩展号: 默认未开通,如需开通请联系 [sms helper] */
|
||||
String extendcode = "";
|
||||
req.setExtendCode(extendcode);
|
||||
|
||||
/* 模板 ID: 必须填写已审核通过的模板 ID,可登录 [短信控制台] 查看模板 ID */
|
||||
// String templateID = "730983";
|
||||
req.setTemplateID(agentCompanyEntity.getTemplateId());
|
||||
|
||||
/* 下发手机号码,采用 e.164 标准,+[国家或地区码][手机号]
|
||||
* 例如+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
|
||||
// String[] phoneNumbers = { "+8615726240251", "+8617854119839", "+8615269088338"};
|
||||
req.setPhoneNumberSet(phoneNumbers);
|
||||
|
||||
/* 模板参数: 若无模板参数,则设置为空*/
|
||||
// String[] templateParams = {"test","100"};
|
||||
req.setTemplateParamSet(templateParams);
|
||||
|
||||
/* 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的
|
||||
* 返回的 res 是一个 SendSmsResponse 类的实例,与请求对象对应 */
|
||||
SendSmsResponse res = client.SendSms(req);
|
||||
|
||||
// 输出 JSON 格式的字符串回包
|
||||
System.out.println(SendSmsResponse.toJsonString(res));
|
||||
|
||||
// 可以取出单个值,您可以通过官网接口文档或跳转到 response 对象的定义处查看返回字段的定义
|
||||
System.out.println(res.getRequestId());
|
||||
} catch (TencentCloudSDKException e) {
|
||||
e.printStackTrace();
|
||||
resValue = 2;
|
||||
}
|
||||
return resValue;
|
||||
}
|
||||
|
||||
|
||||
public static int sendSmsToUser(String[] phoneNumbers, String templateId, String[] templateParams) {
|
||||
int resValue = 0;
|
||||
try {
|
||||
@ -212,41 +110,4 @@ public class SMSUtils {
|
||||
return resValue;
|
||||
}
|
||||
|
||||
|
||||
public static int receiveSms() {
|
||||
int resValue = 0;
|
||||
try {
|
||||
|
||||
Credential cred = new Credential("AKIDFNOAxu0u3pRvFunvD7DE8srs46CDLlJx", "jJjzwkT4PirqgRqCOMH2f8m051Mdlk4c");
|
||||
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
|
||||
SmsClient client = new SmsClient(cred, "", clientProfile);
|
||||
|
||||
PullSmsReplyStatusByPhoneNumberRequest req = new PullSmsReplyStatusByPhoneNumberRequest();
|
||||
Long ss = 1600939153L;
|
||||
req.setSendDateTime(ss);
|
||||
req.setOffset(0L);
|
||||
req.setLimit(10L);
|
||||
req.setPhoneNumber("+8617854119839");
|
||||
req.setSmsSdkAppid("1400430088");
|
||||
|
||||
PullSmsReplyStatusByPhoneNumberResponse resp = client.PullSmsReplyStatusByPhoneNumber(req);
|
||||
|
||||
System.out.println(PullSmsReplyStatusByPhoneNumberResponse.toJsonString(resp));
|
||||
} catch (TencentCloudSDKException e) {
|
||||
System.out.println(e.toString());
|
||||
resValue = 2;
|
||||
}
|
||||
return resValue;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
receiveSms();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user