|
|
@ -5,13 +5,16 @@ import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage; |
|
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisKeys; |
|
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.dto.TemplateData; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcDeleteWxFormIdFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.EpdcUserRegisterAuditMsgResultDTO; |
|
|
|
import com.elink.esua.epdc.enums.AppUserAuditStateEnum; |
|
|
|
import com.elink.esua.epdc.feign.AdminFeignClient; |
|
|
|
import com.elink.esua.epdc.feign.MessageFeignClient; |
|
|
|
import com.elink.esua.epdc.feign.UserFeignClient; |
|
|
|
import com.elink.esua.epdc.service.MessageService; |
|
|
|
import com.elink.esua.epdc.utils.WxMaServiceUtils; |
|
|
|
import com.elink.esua.epdc.utils.WxSendMessageUtils; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
@ -19,7 +22,9 @@ import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author yujintao |
|
|
@ -36,6 +41,9 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
@Autowired |
|
|
|
private UserFeignClient userFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AdminFeignClient adminFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMaServiceUtils wxMaServiceUtils; |
|
|
|
|
|
|
@ -141,4 +149,69 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 小程序消息推送 |
|
|
|
* |
|
|
|
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|
|
|
* @author wanggonfeng |
|
|
|
* @date 2020/05/26 14:18 |
|
|
|
*/ |
|
|
|
public Result sendMessage() { |
|
|
|
// 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
|
|
|
String miniprogram_state = "trial"; |
|
|
|
// 模板ID
|
|
|
|
String template_id = "wagGg4eAeHu1N2N0o8Vhyan41Gr3DqFBD81o5Lv7XnQ"; |
|
|
|
// 用户openID
|
|
|
|
String openId = "oZCeb5TZc2oBwT4jHb0kDmQsN0Xw"; |
|
|
|
// 小程序跳转页
|
|
|
|
String page = "pages/index/index"; |
|
|
|
// 进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
|
|
|
|
String lang = "zh_CN"; |
|
|
|
// appid
|
|
|
|
String appId = "wxfa4afaa2b5f9c876"; |
|
|
|
// secret
|
|
|
|
String secret = "7db9f049c78c9a6cafa673deebe8330d"; |
|
|
|
|
|
|
|
|
|
|
|
// 获取access_token
|
|
|
|
//String access_token = getAccess_token(APPID_NORMAL, jwtTokenProperties.getSecret());
|
|
|
|
String access_token = WxSendMessageUtils.getAccess_token(appId, secret); |
|
|
|
// 拼接URL
|
|
|
|
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + access_token; |
|
|
|
|
|
|
|
// 获取openID
|
|
|
|
/* Result<UserWorkAndAnalyOpenIdDTO> userIdsResult = adminFeignClient.userRelationWorkAndAnalyOpenId(); |
|
|
|
if(userIdsResult == null || userIdsResult.getData() == null){ |
|
|
|
return new Result().error("获取openid失败!"); |
|
|
|
} |
|
|
|
// 调用获取openid接口
|
|
|
|
UserWorkAndAnalyOpenIdDTO userWorkAndAnalyOpenIdDTO = userIdsResult.getData(); |
|
|
|
List<String> analyOpenIdList = userWorkAndAnalyOpenIdDTO.getAnalyOpenIds(); |
|
|
|
List<String> workOpenIdList = userWorkAndAnalyOpenIdDTO.getWorkOpenIds(); |
|
|
|
|
|
|
|
for(int i = 0; i < analyOpenIdList.size() ; i++){ |
|
|
|
String analysisOpenId = analyOpenIdList.get(i); |
|
|
|
sendMessageByOpenId(analysisOpenId,url,miniprogram_state); |
|
|
|
} |
|
|
|
for(int j = 0; j < workOpenIdList.size() ; j++){ |
|
|
|
String workOpenId = workOpenIdList.get(j); |
|
|
|
sendMessageByOpenId(workOpenId,url,miniprogram_state); |
|
|
|
}*/ |
|
|
|
|
|
|
|
// 配置模板内容
|
|
|
|
Map<String, TemplateData> m = new HashMap<>(5); |
|
|
|
TemplateData keyword1 = new TemplateData(); |
|
|
|
keyword1.setValue("11111测试11111"); |
|
|
|
m.put("thing1", keyword1); |
|
|
|
TemplateData keyword2 = new TemplateData(); |
|
|
|
keyword2.setValue("2019年10月1日"); |
|
|
|
m.put("time2", keyword2); |
|
|
|
|
|
|
|
WxSendMessageUtils.sendMessageByOpenId(openId,url,miniprogram_state,template_id,m,lang); |
|
|
|
|
|
|
|
return new Result().ok("消息推送成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|