yang_shj
1 year ago
9 changed files with 252 additions and 8 deletions
@ -0,0 +1,67 @@ |
|||||||
|
package com.hnac.hzims.message.dto; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.support.QueryField; |
||||||
|
import org.springblade.core.mp.support.SqlCondition; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull; |
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ysj |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ApiModel("事务消息") |
||||||
|
@EqualsAndHashCode |
||||||
|
public class WxMessageDTO implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty(value = "微信消息模板ID",required = true) |
||||||
|
@NotNull(message = "微信消息模板ID不能为空") |
||||||
|
private String templateId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "微信消息详情H5跳转Url",required = true) |
||||||
|
@NotNull(message = "微信消息详情H5跳转Url") |
||||||
|
private String skipUrl; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "机构ID",required = true) |
||||||
|
@NotNull(message = "机构ID不能为空") |
||||||
|
private Long deptId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "业务关键字",required = true) |
||||||
|
@NotNull(message = "业务关键字不能为空") |
||||||
|
private String businessKey; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect",required = true) |
||||||
|
@NotNull(message = "业务分类不能为空") |
||||||
|
private String businessClassify; |
||||||
|
|
||||||
|
@ApiModelProperty("业务任务ID") |
||||||
|
@QueryField(condition = SqlCondition.EQUAL) |
||||||
|
private Long taskId; |
||||||
|
|
||||||
|
@NotNull |
||||||
|
@ApiModelProperty(value = "推送消息键值对") |
||||||
|
private Map<String,String> map; |
||||||
|
|
||||||
|
@NotNull |
||||||
|
@ApiModelProperty(value = "内容") |
||||||
|
private String content; |
||||||
|
|
||||||
|
@NotNull |
||||||
|
@ApiModelProperty(value = "主题") |
||||||
|
private String subject; |
||||||
|
|
||||||
|
@NotNull |
||||||
|
@ApiModelProperty(value = "推送用户") |
||||||
|
private String userIds; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建用户") |
||||||
|
private Long createUser; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "租户ID") |
||||||
|
private String tenantId; |
||||||
|
} |
@ -0,0 +1,124 @@ |
|||||||
|
package com.hnac.hzims.message.service.impl; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hnac.hzims.message.MessageConstants; |
||||||
|
import com.hnac.hzims.message.dto.AppPushDto; |
||||||
|
import com.hnac.hzims.message.dto.PushDto; |
||||||
|
import com.hnac.hzims.message.entity.MessagePushRecordEntity; |
||||||
|
import com.hnac.hzims.message.log.aspect.SaveLog; |
||||||
|
import com.hnac.hzims.message.service.IMessageService; |
||||||
|
import com.hnac.hzinfo.core.push.enums.PlatformType; |
||||||
|
import com.hnac.hzinfo.core.push.enums.PushAudienceType; |
||||||
|
import com.hnac.hzinfo.core.push.model.PushAudience; |
||||||
|
import com.hnac.hzinfo.core.push.model.PushInfo; |
||||||
|
import com.hnac.hzinfo.core.push.model.PushPlatform; |
||||||
|
import com.hnac.hzinfo.core.push.model.PushResponse; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.log.exception.ServiceException; |
||||||
|
import org.springblade.core.log.logger.BladeLogger; |
||||||
|
import org.springblade.core.secure.utils.AuthUtil; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springblade.resource.feign.IPushClient; |
||||||
|
import org.springblade.resource.vo.PushInfoVO; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.io.*; |
||||||
|
import java.net.HttpURLConnection; |
||||||
|
import java.net.MalformedURLException; |
||||||
|
import java.net.ProtocolException; |
||||||
|
import java.net.URL; |
||||||
|
import java.nio.charset.StandardCharsets; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.ExecutorService; |
||||||
|
import java.util.concurrent.FutureTask; |
||||||
|
import java.util.concurrent.atomic.AtomicReference; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author hx |
||||||
|
*/ |
||||||
|
@Service("pushMessageService") |
||||||
|
@Slf4j |
||||||
|
@AllArgsConstructor |
||||||
|
public class WxMessageServiceImpl implements IMessageService { |
||||||
|
|
||||||
|
private final IPushClient pushClient; |
||||||
|
private final BladeLogger logger; |
||||||
|
private final ExecutorService appMessagePushExecutor; |
||||||
|
|
||||||
|
@Override |
||||||
|
@SaveLog(type = MessageConstants.APP_NAME) |
||||||
|
public <T extends PushDto> R send(T pushObject) { |
||||||
|
|
||||||
|
return R.success("推送成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean send(MessagePushRecordEntity request) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 发送APP消息(多人) |
||||||
|
* @param subject 消息主题 |
||||||
|
* @param content 消息内容 |
||||||
|
* @param userIds 用户ID列表 |
||||||
|
* @param tenantId 租户ID |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public boolean sendByUsers(String subject, String content, List<String> userIds,String tenantId) throws Exception { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean send(Map<String, Object> param) { |
||||||
|
OutputStream out = null; |
||||||
|
try{ |
||||||
|
URL serverUrl = new URL("https://3d.hnaccloud.com/api/blade-system/wxPush/sendPush"); |
||||||
|
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); |
||||||
|
conn.setRequestMethod("GET"); |
||||||
|
conn.setRequestProperty("Content-type", "application/json"); |
||||||
|
//必须设置false,否则会自动redirect到重定向后的地址
|
||||||
|
conn.setInstanceFollowRedirects(false); |
||||||
|
conn.connect(); |
||||||
|
String result = responseFormat(conn); |
||||||
|
//获取输出流
|
||||||
|
out = conn.getOutputStream(); |
||||||
|
log.error("send_wx_message_param: {}",param.toString()); |
||||||
|
//输出流里写入POST参数
|
||||||
|
out.write(param.toString().getBytes()); |
||||||
|
out.flush(); |
||||||
|
out.close(); |
||||||
|
}catch (Exception ex){ |
||||||
|
log.error("send_wx_message_error: {} ", ex.getMessage()); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/*** |
||||||
|
* 获取返回的内容 |
||||||
|
* @param connection |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private String responseFormat(HttpURLConnection connection) { |
||||||
|
StringBuilder stringBuilder = new StringBuilder(); |
||||||
|
//将返回的输入流转换成字符串
|
||||||
|
try ( |
||||||
|
InputStream inputStream = connection.getInputStream(); |
||||||
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); |
||||||
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader) |
||||||
|
) { |
||||||
|
String str; |
||||||
|
while ((str = bufferedReader.readLine()) != null) { |
||||||
|
stringBuilder.append(str); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return stringBuilder.toString(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue