|
|
|
@ -5,6 +5,7 @@ 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.dto.WxMessageDTO; |
|
|
|
|
import com.hnac.hzims.message.entity.MessagePushRecordEntity; |
|
|
|
|
import com.hnac.hzims.message.log.aspect.SaveLog; |
|
|
|
|
import com.hnac.hzims.message.service.IMessageService; |
|
|
|
@ -16,6 +17,7 @@ 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.apache.poi.ss.formula.functions.T; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.log.logger.BladeLogger; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
@ -24,6 +26,9 @@ 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.springblade.system.entity.PushTemplate; |
|
|
|
|
import org.springblade.system.feign.IWxPushClient; |
|
|
|
|
import org.springblade.system.vo.WxPushFeignVO; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
@ -38,6 +43,7 @@ import java.util.Map;
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
import java.util.concurrent.FutureTask; |
|
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author hx |
|
|
|
@ -48,6 +54,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
public class WxMessageServiceImpl implements IMessageService { |
|
|
|
|
|
|
|
|
|
private final IPushClient pushClient; |
|
|
|
|
private final IWxPushClient wxPushClient; |
|
|
|
|
private final BladeLogger logger; |
|
|
|
|
private final ExecutorService appMessagePushExecutor; |
|
|
|
|
|
|
|
|
@ -75,50 +82,13 @@ public class WxMessageServiceImpl implements IMessageService {
|
|
|
|
|
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(); |
|
|
|
|
public boolean send(WxMessageDTO message) { |
|
|
|
|
PushTemplate template = new PushTemplate(); |
|
|
|
|
template.setTemplateId(message.getTemplateId()); |
|
|
|
|
template.setSkipUrl(message.getSkipUrl()); |
|
|
|
|
template.setMap(message.getMap()); |
|
|
|
|
template.setUserIds(Arrays.stream(message.getUserIds().split(",")).collect(Collectors.toList())); |
|
|
|
|
R<WxPushFeignVO> result = wxPushClient.sendPushTemplateByUserId(template); |
|
|
|
|
return result.isSuccess(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|