短信发送增加字段

This commit is contained in:
wanggeng 2022-03-21 11:26:39 +08:00
parent b5c761b810
commit 55283b2ce5
3 changed files with 58 additions and 39 deletions

View File

@ -1,5 +1,7 @@
package ink.wgink.properties.sms; package ink.wgink.properties.sms;
import org.springframework.util.StringUtils;
/** /**
* When you feel like quitting. Think about why you started * When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始 * 当你想要放弃的时候想想当初你为何开始
@ -12,11 +14,20 @@ package ink.wgink.properties.sms;
**/ **/
public class SmsDefaultProperties { public class SmsDefaultProperties {
private String url;
private String account; private String account;
private String password; private String password;
private String sign; private String sign;
private SmsDefaultTemplateProperties template; private SmsDefaultTemplateProperties template;
public String getUrl() {
return StringUtils.isEmpty(url) ? "https://dx.ipyy.net/sms.aspx" : url;
}
public void setUrl(String url) {
this.url = url;
}
public String getAccount() { public String getAccount() {
return account == null ? "" : account.trim(); return account == null ? "" : account.trim();
} }

View File

@ -10,6 +10,7 @@ import ink.wgink.pojo.pos.DepartmentPO;
import ink.wgink.pojo.pos.GroupPO; import ink.wgink.pojo.pos.GroupPO;
import ink.wgink.pojo.pos.PositionPO; import ink.wgink.pojo.pos.PositionPO;
import ink.wgink.pojo.pos.RolePO; import ink.wgink.pojo.pos.RolePO;
import ink.wgink.properties.app.AppTokenProperties;
import ink.wgink.service.department.service.IDepartmentUserService; import ink.wgink.service.department.service.IDepartmentUserService;
import ink.wgink.service.user.pojo.pos.UserPO; import ink.wgink.service.user.pojo.pos.UserPO;
import ink.wgink.util.AesUtil; import ink.wgink.util.AesUtil;
@ -44,6 +45,8 @@ public class BaseAppSignService extends DefaultBaseService {
private IPositionUserBaseService positionUserBaseService; private IPositionUserBaseService positionUserBaseService;
@Autowired(required = false) @Autowired(required = false)
private IGroupUserBaseService groupUserBaseService; private IGroupUserBaseService groupUserBaseService;
@Autowired
private AppTokenProperties appTokenProperties;
/** /**
* 获取token * 获取token
@ -53,17 +56,21 @@ public class BaseAppSignService extends DefaultBaseService {
* @throws Exception * @throws Exception
*/ */
protected String getToken(UserPO userPO) throws UnsupportedEncodingException { protected String getToken(UserPO userPO) throws UnsupportedEncodingException {
return getToken(userPO, false); return getToken(userPO, appTokenProperties.getHasDepartment(), appTokenProperties.getHasRole(), appTokenProperties.getHasPosition(), appTokenProperties.getHasGroup());
} }
/** /**
* 获取token * 获取token
* *
* @param userPO 用户信息 * @param userPO 用户信息
* @param isFull 是否包含全部信息部门角色职位 * @param hasDepartment 包含部门
* @param hasRole 包含角色
* @param hasPosition 包含职位
* @param hasGroup 包含组
* @return * @return
* @throws UnsupportedEncodingException
*/ */
protected String getToken(UserPO userPO, boolean isFull) throws UnsupportedEncodingException { protected String getToken(UserPO userPO, boolean hasDepartment, boolean hasRole, boolean hasPosition, boolean hasGroup) throws UnsupportedEncodingException {
Map<String, Object> userInfo = new HashMap<>(8); Map<String, Object> userInfo = new HashMap<>(8);
// 这个参数是token认证标识 // 这个参数是token认证标识
userInfo.put(ISystemConstant.APP_TOKEN_SIGN, ISystemConstant.APP_TOKEN_VERIFY + System.currentTimeMillis()); userInfo.put(ISystemConstant.APP_TOKEN_SIGN, ISystemConstant.APP_TOKEN_VERIFY + System.currentTimeMillis());
@ -74,7 +81,7 @@ public class BaseAppSignService extends DefaultBaseService {
userInfo.put("phone", userPO.getUserPhone()); userInfo.put("phone", userPO.getUserPhone());
userInfo.put("email", userPO.getUserEmail()); userInfo.put("email", userPO.getUserEmail());
if (isFull) { if (hasDepartment) {
LOG.debug("人员部门列表"); LOG.debug("人员部门列表");
List<DepartmentPO> departmentPOs = departmentUserService.listDepartmentPOByUserId(userPO.getUserId()); List<DepartmentPO> departmentPOs = departmentUserService.listDepartmentPOByUserId(userPO.getUserId());
List<Map<String, Object>> departments = new ArrayList<>(); List<Map<String, Object>> departments = new ArrayList<>();
@ -85,42 +92,42 @@ public class BaseAppSignService extends DefaultBaseService {
departments.add(departmentMap); departments.add(departmentMap);
} }
userInfo.put("departments", departments); userInfo.put("departments", departments);
if (roleUserBaseService != null) { }
LOG.debug("人员角色列表"); if (hasRole && roleUserBaseService != null) {
List<RolePO> rolePOs = roleUserBaseService.listRolePOByUserId(userPO.getUserId()); LOG.debug("人员角色列表");
List<Map<String, Object>> roles = new ArrayList<>(); List<RolePO> rolePOs = roleUserBaseService.listRolePOByUserId(userPO.getUserId());
for (RolePO rolePO : rolePOs) { List<Map<String, Object>> roles = new ArrayList<>();
Map<String, Object> roleMap = new HashMap<>(4); for (RolePO rolePO : rolePOs) {
roleMap.put("roleId", rolePO.getRoleId()); Map<String, Object> roleMap = new HashMap<>(4);
roleMap.put("roleName", rolePO.getRoleName()); roleMap.put("roleId", rolePO.getRoleId());
roles.add(roleMap); roleMap.put("roleName", rolePO.getRoleName());
} roles.add(roleMap);
userInfo.put("roles", roles);
} }
if (positionUserBaseService != null) { userInfo.put("roles", roles);
LOG.debug("人员职位列表"); }
List<PositionPO> positionPOs = positionUserBaseService.listPositionPOByUserId(userPO.getUserId()); if (hasPosition && positionUserBaseService != null) {
List<Map<String, Object>> positions = new ArrayList<>(); LOG.debug("人员职位列表");
for (PositionPO positionPO : positionPOs) { List<PositionPO> positionPOs = positionUserBaseService.listPositionPOByUserId(userPO.getUserId());
Map<String, Object> positionMap = new HashMap<>(2); List<Map<String, Object>> positions = new ArrayList<>();
positionMap.put("positionId", positionPO.getPositionId()); for (PositionPO positionPO : positionPOs) {
positionMap.put("positionName", positionPO.getPositionName()); Map<String, Object> positionMap = new HashMap<>(2);
positions.add(positionMap); positionMap.put("positionId", positionPO.getPositionId());
} positionMap.put("positionName", positionPO.getPositionName());
userInfo.put("positions", positions); positions.add(positionMap);
} }
if (groupUserBaseService != null) { userInfo.put("positions", positions);
LOG.debug("人员组列表"); }
List<GroupPO> groupPOs = groupUserBaseService.listGroupPOByUserId(userPO.getUserId()); if (hasGroup && groupUserBaseService != null) {
List<Map<String, Object>> groups = new ArrayList<>(); LOG.debug("人员组列表");
for (GroupPO groupPO : groupPOs) { List<GroupPO> groupPOs = groupUserBaseService.listGroupPOByUserId(userPO.getUserId());
Map<String, Object> groupMap = new HashMap<>(2); List<Map<String, Object>> groups = new ArrayList<>();
groupMap.put("groupId", groupPO.getGroupId()); for (GroupPO groupPO : groupPOs) {
groupMap.put("groupName", groupPO.getGroupName()); Map<String, Object> groupMap = new HashMap<>(2);
groups.add(groupMap); groupMap.put("groupId", groupPO.getGroupId());
} groupMap.put("groupName", groupPO.getGroupName());
userInfo.put("groups", groups); groups.add(groupMap);
} }
userInfo.put("groups", groups);
} }
LOG.debug("userInfo: " + userInfo); LOG.debug("userInfo: " + userInfo);
return Base64.encodeBase64String(AesUtil.aesCommonEncoder(ISystemConstant.APP_TOKEN_AES_KEY, JSONObject.toJSONString(userInfo)).getBytes("UTF-8")); return Base64.encodeBase64String(AesUtil.aesCommonEncoder(ISystemConstant.APP_TOKEN_AES_KEY, JSONObject.toJSONString(userInfo)).getBytes("UTF-8"));

View File

@ -23,7 +23,7 @@ import org.springframework.web.client.RestTemplate;
public class DefaultSmsSendImpl implements ISmsSend { public class DefaultSmsSendImpl implements ISmsSend {
private static final Logger LOG = LoggerFactory.getLogger(DefaultSmsSendImpl.class); private static final Logger LOG = LoggerFactory.getLogger(DefaultSmsSendImpl.class);
private static final String URL_SMS = "https://dx.ipyy.net/sms.aspx?action=send&userid=&account={account}&password={password}&mobile={mobile}&content={content}&sendTime=&extno={extno}"; private static final String URL_SMS = "{url}?action=send&userid=&account={account}&password={password}&mobile={mobile}&content={content}&sendTime=&extno={extno}";
private SmsDefaultProperties smsDefaultProperties; private SmsDefaultProperties smsDefaultProperties;
public DefaultSmsSendImpl(SmsDefaultProperties smsDefaultProperties) { public DefaultSmsSendImpl(SmsDefaultProperties smsDefaultProperties) {
@ -50,6 +50,7 @@ public class DefaultSmsSendImpl implements ISmsSend {
*/ */
private void send(String phone, String content) { private void send(String phone, String content) {
String[] paramArray = new String[]{ String[] paramArray = new String[]{
smsDefaultProperties.getUrl(),
smsDefaultProperties.getAccount(), smsDefaultProperties.getAccount(),
smsDefaultProperties.getPassword(), smsDefaultProperties.getPassword(),
phone, phone,