|
|
@ -1,26 +1,30 @@ |
|
|
|
package com.elink.esua.epdc.service.impl; |
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaMsgService; |
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.dto.UserDTO; |
|
|
|
import com.elink.esua.epdc.dto.UserWxFormIdDTO; |
|
|
|
import com.elink.esua.epdc.dto.form.EpdcRegisterResultSmsFormDTO; |
|
|
|
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.MessageFeignClient; |
|
|
|
import com.elink.esua.epdc.feign.UserFeignClient; |
|
|
|
import com.elink.esua.epdc.service.MessageService; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author yujintao |
|
|
|
* @email yujintao@elink-cn.com |
|
|
|
* @date 2019/9/11 21:03 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class MessageServiceImpl implements MessageService { |
|
|
|
|
|
|
@ -33,6 +37,21 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
@Autowired |
|
|
|
private WxMaService wxMaService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 注册审核失败服务消息模版 |
|
|
|
*/ |
|
|
|
private static String FAILURE_TEMPLATE_ID = "jL6UPR2ZBcZT8Qu2UijcApvUI2xa3K68paDl8ZZV7as"; |
|
|
|
|
|
|
|
/** |
|
|
|
* 注册审核成功服务消息模版 |
|
|
|
*/ |
|
|
|
private static String SUCCESS_TEMPLATE_ID = "jL6UPR2ZBcZT8Qu2UijcAoGddYg70BGAyFZXyr4XBSY"; |
|
|
|
|
|
|
|
/** |
|
|
|
* 服务消息跳转小程序页面 |
|
|
|
*/ |
|
|
|
private static String MA_PAGE = "pages/index/index"; |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送六位短信验证码 |
|
|
|
* |
|
|
@ -55,22 +74,147 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
if (null == userAuditStateEnum || userAuditStateEnum.equals(AppUserAuditStateEnum.UNDER_AUDIT)) { |
|
|
|
return new Result().error("审核状态无效"); |
|
|
|
} |
|
|
|
Result<UserDTO> userResult = userFeignClient.getUserById(userId); |
|
|
|
Result<EpdcUserRegisterAuditMsgResultDTO> userResult = userFeignClient.getUserRegisterAuditResult(userId); |
|
|
|
if (!userResult.success() || null == userResult.getData()) { |
|
|
|
return new Result().error("查询用户信息失败"); |
|
|
|
} |
|
|
|
UserDTO userDto = userResult.getData(); |
|
|
|
|
|
|
|
switch (userAuditStateEnum) { |
|
|
|
case AUDIT_FAILURE: |
|
|
|
EpdcRegisterResultSmsFormDTO form = new EpdcRegisterResultSmsFormDTO(); |
|
|
|
form.setMobile(userDto.getMobile()); |
|
|
|
form.setReason(userDto.getRemark()); |
|
|
|
return this.messageFeignClient.registerFailure(form); |
|
|
|
case AUDIT_SUCCESS: |
|
|
|
return this.messageFeignClient.registerSuccess(userDto.getMobile()); |
|
|
|
default: |
|
|
|
return new Result().error("短信发送失败"); |
|
|
|
// 用户审核结果
|
|
|
|
EpdcUserRegisterAuditMsgResultDTO registerAuditResultDto = userResult.getData(); |
|
|
|
if (StringUtils.isBlank(registerAuditResultDto.getWxFormId())) { |
|
|
|
return new Result().error("没有可用的wxFormId"); |
|
|
|
} |
|
|
|
|
|
|
|
if (state.equals(AppUserAuditStateEnum.AUDIT_SUCCESS.value())) { |
|
|
|
this.sendRegisterSuccessMaMsg(registerAuditResultDto); |
|
|
|
} else { |
|
|
|
this.sendRegisterFailureMaMsg(registerAuditResultDto); |
|
|
|
} |
|
|
|
this.deleteWxFormId(registerAuditResultDto.getWxFormIdId()); |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除用过的wxFormId |
|
|
|
* |
|
|
|
* @param id 存放formId的数据库表主键 |
|
|
|
* @return void |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/9/27 09:33 |
|
|
|
*/ |
|
|
|
private void deleteWxFormId(String id) { |
|
|
|
EpdcDeleteWxFormIdFormDTO dto = new EpdcDeleteWxFormIdFormDTO(); |
|
|
|
dto.setId(id); |
|
|
|
userFeignClient.deleteWxFormIdById(dto); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 注册失败的小程序服务消息 |
|
|
|
* |
|
|
|
* @param registerAuditResultDto |
|
|
|
* @return void |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/9/26 17:26 |
|
|
|
*/ |
|
|
|
private void sendRegisterFailureMaMsg(EpdcUserRegisterAuditMsgResultDTO registerAuditResultDto) { |
|
|
|
/*姓名,手机号,申请时间,审核时间,不通过原因,审核结果 jL6UPR2ZBcZT8Qu2UijcApvUI2xa3K68paDl8ZZV7as*/ |
|
|
|
|
|
|
|
List<WxMaTemplateData> dataList = this.getWxMaTemplateData(registerAuditResultDto); |
|
|
|
|
|
|
|
WxMaTemplateData templateData = new WxMaTemplateData(); |
|
|
|
templateData.setName("keyword5"); |
|
|
|
templateData.setValue(registerAuditResultDto.getRemark()); |
|
|
|
templateData.setColor("#FF4500"); |
|
|
|
dataList.add(templateData); |
|
|
|
|
|
|
|
templateData = new WxMaTemplateData(); |
|
|
|
templateData.setName("keyword6"); |
|
|
|
templateData.setValue("注册失败"); |
|
|
|
dataList.add(templateData); |
|
|
|
|
|
|
|
WxMaUniformMessage message = WxMaUniformMessage.builder() |
|
|
|
.isMpTemplateMsg(false) |
|
|
|
.toUser(registerAuditResultDto.getWxOpenId()) |
|
|
|
.formId(registerAuditResultDto.getWxFormId()) |
|
|
|
.templateId(FAILURE_TEMPLATE_ID) |
|
|
|
.page(MA_PAGE) |
|
|
|
.data(dataList) |
|
|
|
.emphasisKeyword("keyword6.DATA") |
|
|
|
.build(); |
|
|
|
try { |
|
|
|
wxMaService.getMsgService().sendUniformMsg(message); |
|
|
|
} catch (WxErrorException e) { |
|
|
|
log.error("->sendRegisterFailureMaMsg::发送小程序服务通知失败::userId:::{}::errorMsg::{}", |
|
|
|
registerAuditResultDto.getUserId(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 注册成功的小程序服务消息 |
|
|
|
* |
|
|
|
* @param registerAuditResultDto |
|
|
|
* @return void |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/9/26 17:26 |
|
|
|
*/ |
|
|
|
private void sendRegisterSuccessMaMsg(EpdcUserRegisterAuditMsgResultDTO registerAuditResultDto) { |
|
|
|
/*姓名,手机号,申请时间,审核时间,审核结果 jL6UPR2ZBcZT8Qu2UijcAoGddYg70BGAyFZXyr4XBSY*/ |
|
|
|
|
|
|
|
List<WxMaTemplateData> dataList = this.getWxMaTemplateData(registerAuditResultDto); |
|
|
|
|
|
|
|
WxMaTemplateData templateData = new WxMaTemplateData(); |
|
|
|
templateData.setName("keyword5"); |
|
|
|
templateData.setValue("注册成功"); |
|
|
|
dataList.add(templateData); |
|
|
|
|
|
|
|
WxMaUniformMessage message = WxMaUniformMessage.builder() |
|
|
|
.isMpTemplateMsg(false) |
|
|
|
.toUser(registerAuditResultDto.getWxOpenId()) |
|
|
|
.formId(registerAuditResultDto.getWxFormId()) |
|
|
|
.templateId(SUCCESS_TEMPLATE_ID) |
|
|
|
.page(MA_PAGE) |
|
|
|
.data(dataList) |
|
|
|
.emphasisKeyword("keyword5.DATA") |
|
|
|
.build(); |
|
|
|
try { |
|
|
|
wxMaService.getMsgService().sendUniformMsg(message); |
|
|
|
} catch (WxErrorException e) { |
|
|
|
log.error("->sendRegisterSuccessMaMsg::发送小程序服务通知失败::userId:::{}::errorMsg::{}", |
|
|
|
registerAuditResultDto.getUserId(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 因为注册审核的两个模版消息的前四项关键词是一样的,所以抽出了方法 |
|
|
|
* |
|
|
|
* @param registerAuditResultDto |
|
|
|
* @return java.util.List<cn.binarywang.wx.miniapp.bean.WxMaTemplateData> |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/9/26 17:24 |
|
|
|
*/ |
|
|
|
private List<WxMaTemplateData> getWxMaTemplateData(EpdcUserRegisterAuditMsgResultDTO registerAuditResultDto) { |
|
|
|
List<WxMaTemplateData> dataList = Lists.newArrayList(); |
|
|
|
|
|
|
|
WxMaTemplateData templateData = new WxMaTemplateData(); |
|
|
|
templateData.setName("keyword1"); |
|
|
|
templateData.setValue(registerAuditResultDto.getRealName()); |
|
|
|
dataList.add(templateData); |
|
|
|
|
|
|
|
templateData = new WxMaTemplateData(); |
|
|
|
templateData.setName("keyword2"); |
|
|
|
templateData.setValue(registerAuditResultDto.getMobile()); |
|
|
|
dataList.add(templateData); |
|
|
|
|
|
|
|
templateData = new WxMaTemplateData(); |
|
|
|
templateData.setName("keyword3"); |
|
|
|
templateData.setValue(registerAuditResultDto.getCreatedTime()); |
|
|
|
dataList.add(templateData); |
|
|
|
|
|
|
|
templateData = new WxMaTemplateData(); |
|
|
|
templateData.setName("keyword4"); |
|
|
|
templateData.setValue(registerAuditResultDto.getRegisterTime()); |
|
|
|
dataList.add(templateData); |
|
|
|
|
|
|
|
return dataList; |
|
|
|
} |
|
|
|
} |
|
|
|