Browse Source

公众号消息推送接口添加注释,小程序授权完成添加发送钉钉消息

dev_shibei_match
sunyuchao 5 years ago
parent
commit
57755e68d3
  1. 37
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/CustomerAndUserResultDTO.java
  2. 7
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PublicAccountCallBackController.java
  3. 7
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java
  4. 61
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  5. 24
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml

37
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/CustomerAndUserResultDTO.java

@ -0,0 +1,37 @@
package com.epmet.dto.result;
import com.epmet.dto.PaCustomerDTO;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.PaUserWechatDTO;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @Description 查询授权客户及管理员信息-接口返参
* @Author sun
*/
@Data
public class CustomerAndUserResultDTO implements Serializable {
private static final long serialVersionUID = 5214475907074876716L;
/**
* 客户Id
*/
private String customerId;
/**
* 客户Id
*/
private String customerName;
/**
* 管理员称谓
*/
private String appellation;
/**
* 管理员手机号
*/
private String phone;
}

7
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PublicAccountCallBackController.java

@ -55,6 +55,13 @@ public class PublicAccountCallBackController {
} }
} }
/**
* @return java.lang.String
* @author sun
* @description 此请求url是公众号后台设置的消息url首次创建公众号时微信会发送get请求调用接口
* 后边公众号所有的消息都是通过该url发送post请求目前对于公众号的消息全部回复空字符串
* 后续可以回复各种格式的消息具体可参考 https://www.cnblogs.com/xdp-gacl/p/5161206.html
*/
@PostMapping(value = "/callback") @PostMapping(value = "/callback")
public String wxServerValdation() { public String wxServerValdation() {
return ""; return "";

7
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java

@ -22,6 +22,7 @@ import com.epmet.dto.PaCustomerDTO;
import com.epmet.dto.form.ModifyCustomerFormDTO; import com.epmet.dto.form.ModifyCustomerFormDTO;
import com.epmet.dto.form.RegisterByAuthFormDTO; import com.epmet.dto.form.RegisterByAuthFormDTO;
import com.epmet.dto.result.CustomerAgencyResultDTO; import com.epmet.dto.result.CustomerAgencyResultDTO;
import com.epmet.dto.result.CustomerAndUserResultDTO;
import com.epmet.dto.result.RegisterByAuthResultDTO; import com.epmet.dto.result.RegisterByAuthResultDTO;
import com.epmet.entity.PaCustomerEntity; import com.epmet.entity.PaCustomerEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -84,4 +85,10 @@ public interface PaCustomerDao extends BaseDao<PaCustomerEntity> {
* @date 2020/8/5 3:23 下午 * @date 2020/8/5 3:23 下午
*/ */
String selectCustomerName(@Param("customerId") String customerId); String selectCustomerName(@Param("customerId") String customerId);
/**
* @author sun
* @Description 查询客户及管理员信息
*/
CustomerAndUserResultDTO selectCustomerAndUser(@Param("customerId") String customerId);
} }

61
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java

@ -3,6 +3,10 @@ package com.epmet.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.client.config.utils.IOUtils; import com.alibaba.nacos.client.config.utils.IOUtils;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.dto.TokenDto;
@ -12,6 +16,7 @@ import com.epmet.constant.ModuleConstant;
import com.epmet.constant.ThirdRedisKeyConstant; import com.epmet.constant.ThirdRedisKeyConstant;
import com.epmet.constant.ThirdRunTimeInfoConstant; import com.epmet.constant.ThirdRunTimeInfoConstant;
import com.epmet.dao.*; import com.epmet.dao.*;
import com.epmet.dto.CustomerMpDTO;
import com.epmet.dto.PaCustomerUserAgencyDTO; import com.epmet.dto.PaCustomerUserAgencyDTO;
import com.epmet.dto.form.*; import com.epmet.dto.form.*;
import com.epmet.dto.result.*; import com.epmet.dto.result.*;
@ -21,6 +26,7 @@ import com.epmet.mpaes.WXXmlToMapUtil;
import com.epmet.redis.RedisThird; import com.epmet.redis.RedisThird;
import com.epmet.service.ComponentVerifyTicketService; import com.epmet.service.ComponentVerifyTicketService;
import com.epmet.wxapi.constant.WxMaCodeConstant; import com.epmet.wxapi.constant.WxMaCodeConstant;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -34,6 +40,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.epmet.constant.ModuleConstant.COMPONENT_ACCESS_TOKEN; import static com.epmet.constant.ModuleConstant.COMPONENT_ACCESS_TOKEN;
import static com.epmet.constant.ThirdRunTimeInfoConstant.*; import static com.epmet.constant.ThirdRunTimeInfoConstant.*;
@ -88,6 +95,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
private PaUserDao paUserDao; private PaUserDao paUserDao;
@Autowired @Autowired
private PaCustomerServiceImpl paCustomerServiceImpl; private PaCustomerServiceImpl paCustomerServiceImpl;
@Autowired
private PaCustomerDao paCustomerDao;
@Value("${third.platform.appId}") @Value("${third.platform.appId}")
private String componentAppId; private String componentAppId;
@ -448,6 +457,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
authCodeDao.updateAppId(customerId,clientType,authAppId); authCodeDao.updateAppId(customerId,clientType,authAppId);
// 4. 保存授权方账户信息 // 4. 保存授权方账户信息
this.saveAuthAccountInfo(customerId,authAppId,clientType); this.saveAuthAccountInfo(customerId,authAppId,clientType);
// 5. 校验客户居民端、工作端小程序是否全部授权,全部授权完成的推送钉钉消息 sun
this.checkAuthorization(customerId);
log.info("回调结束"); log.info("回调结束");
} }
@ -689,4 +700,54 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
date.setTime(aLong); date.setTime(aLong);
return date; return date;
} }
/**
* @author sun
* @Description 校验客户两哥小程序是否完成授权
*/
private void checkAuthorization(String customerId){
List<CustomerMpDTO> list = customerMpDao.selectByCustomerId(customerId);
AtomicBoolean bl = new AtomicBoolean(false);
list.forEach(mp->{
if(mp.getAuthorizationFlag()!=NumConstant.ONE){
bl.set(true);
}
});
if(!bl.get()){
dDingNews(customerId);
}
}
/**
* @author sun
* @Description 发送钉钉消息通知运营人员有新客户完成授权
*/
private String dDingNews(String customerId) {
//1.查询客户及管理员信息,用于发送消息使用
CustomerAndUserResultDTO result = paCustomerDao.selectCustomerAndUser(customerId);
if (null == result || null == result.getCustomerId()) {
log.error("授权完成发送钉钉消息失败,原因:未查询到客户信息,客户Id->" + customerId);
return null;
}
//2.拼接钉钉消息内容并发送
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=b4e47783ad72ba643278598ff8af90e745890c13538b2a4dc139635a71289dfd");
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle("授权客户信息");
//"新客户通知"几个字是设置机器人时自定义的关键字,要保持代码与机器人设置的一致
markdown.setText("新客户通知: \n" +
"> 客户名称: " + result.getCustomerName() + "\n\n" +
"> 管理员称谓: " + result.getAppellation() + "\n\n" +
"> 联系方式: " + result.getPhone() + "\n");
request.setMarkdown(markdown);
try {
OapiRobotSendResponse response = client.execute(request);
} catch (ApiException e) {
log.error("机器人生病了......");
e.printStackTrace();
}
return null;
}
} }

24
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml

@ -82,6 +82,30 @@
AND id = #{customerId} AND id = #{customerId}
</select> </select>
<select id="selectCustomerAndUser" resultType="com.epmet.dto.result.CustomerAndUserResultDTO">
SELECT
pc.id AS "customerId",
pc.customer_name AS "customerName",
CONCAT(
pu.real_name,
IF (
pu.gender = 1,
'先生',
IF (pu.gender = 2, '女士', '')
)
) AS "appellation",
pu.phone AS "phone"
FROM
pa_customer pc
INNER JOIN pa_customer_user_agency pcua ON pc.id = pcua.customer_id
INNER JOIN pa_user pu ON pcua.user_id = pu.id
WHERE
pc.del_flag = '0'
AND pcua.del_flag = '0'
AND pu.del_flag = '0'
AND pc.id = #{customerId}
</select>
<update id="updateCustomerById"> <update id="updateCustomerById">
UPDATE pa_customer UPDATE pa_customer
SET is_initialize = #{isInitialize} SET is_initialize = #{isInitialize}

Loading…
Cancel
Save