|
@@ -23,6 +23,7 @@ import java.io.PrintWriter;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static com.tzld.piaoquan.growth.common.common.enums.CorpEnum.HNWQ;
|
|
|
+import static com.tzld.piaoquan.growth.common.common.enums.CorpEnum.YLQ;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -127,4 +128,95 @@ public class TencentWeComController {
|
|
|
String success = "success";
|
|
|
return success;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //优量圈验证接口
|
|
|
+ @GetMapping("/ylq/verify")
|
|
|
+ public void ylqVerifyGet(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ // 微信加密签名
|
|
|
+ String msgSignature = request.getParameter("msg_signature");
|
|
|
+ // 时间戳
|
|
|
+ String timestamp = request.getParameter("timestamp");
|
|
|
+ // 随机数
|
|
|
+ String nonce = request.getParameter("nonce");
|
|
|
+ // 随机字符串
|
|
|
+ // 如果是刷新,需返回原echostr
|
|
|
+ String echoStr = request.getParameter("echostr");
|
|
|
+ // 微信加密签名
|
|
|
+ WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(WeComServerConstant.TOKEN,
|
|
|
+ WeComServerConstant.ENCODING_AES_KEY,
|
|
|
+ WeComServerConstant.CORP_ID);
|
|
|
+
|
|
|
+ String sEchoStr = ""; //需要返回的明文
|
|
|
+ PrintWriter out;
|
|
|
+
|
|
|
+ sEchoStr = wxcpt.VerifyURL(msgSignature, timestamp,
|
|
|
+ nonce, echoStr);
|
|
|
+ log.info("verifyurl echostr: " + sEchoStr);
|
|
|
+
|
|
|
+ // 验证URL成功,将sEchoStr返回
|
|
|
+ out = response.getWriter();
|
|
|
+ out.print(sEchoStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ //验证URL失败,错误原因请查看异常
|
|
|
+ log.error("verifyGet error", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //优量圈回调消息接口
|
|
|
+ @PostMapping(value = "/ylq/verify")
|
|
|
+ public String ylqVerifyPost(HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ // 微信加密签名
|
|
|
+ String msg_signature = request.getParameter("msg_signature");
|
|
|
+ // 时间戳
|
|
|
+ String timestamp = request.getParameter("timestamp");
|
|
|
+ // 随机数
|
|
|
+ String nonce = request.getParameter("nonce");
|
|
|
+
|
|
|
+ String id = WeComServerConstant.CORP_ID;
|
|
|
+
|
|
|
+ WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(WeComServerConstant.TOKEN, WeComServerConstant.ENCODING_AES_KEY, id);
|
|
|
+
|
|
|
+ StringBuilder postData = new StringBuilder(); // 密文,对应POST请求的数据
|
|
|
+ //1.获取加密的请求消息:使用输入流获得加密请求消息postData
|
|
|
+ ServletInputStream in = request.getInputStream();
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
|
|
+
|
|
|
+ String tempStr = ""; //作为输出字符串的临时串,用于判断是否读取完毕
|
|
|
+ while (null != (tempStr = reader.readLine())) {
|
|
|
+ postData.append(tempStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ String suiteXml = wxcpt.DecryptMsg(msg_signature, timestamp, nonce, postData.toString());
|
|
|
+ log.info("suiteXml: " + suiteXml);
|
|
|
+
|
|
|
+ Map suiteMap = WxUtil.transferXmlToMap(suiteXml);
|
|
|
+ log.info("suiteMap = {}", JSONObject.toJSONString(suiteMap));
|
|
|
+ if (suiteMap != null) {
|
|
|
+ String changeType = (String) suiteMap.get("ChangeType");
|
|
|
+ if (StringUtils.isNotEmpty(changeType) && changeType.equals("add_external_contact")) {
|
|
|
+ String userId = (String) suiteMap.get("UserID");
|
|
|
+ String externalUserId = (String) suiteMap.get("ExternalUserID");
|
|
|
+ String welcomeCode = (String) suiteMap.get("WelcomeCode");
|
|
|
+ log.info("addStaffWithUser userId={} externalUserId={}", userId, externalUserId);
|
|
|
+ weComUserService.addStaffWithUser(externalUserId, userId, YLQ.getId());
|
|
|
+ weComAutoReply.AutoReplyMessage(welcomeCode, externalUserId, userId, YLQ.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(changeType) && changeType.equals("del_follow_user")) {
|
|
|
+ String userId = (String) suiteMap.get("UserID");
|
|
|
+ String externalUserId = (String) suiteMap.get("ExternalUserID");
|
|
|
+ log.info("delStaffWithUser userId={} externalUserId={}", userId, externalUserId);
|
|
|
+ weComUserService.delStaffWithUser(externalUserId, userId, YLQ.getId(), System.currentTimeMillis());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("verifyPost error", e);
|
|
|
+ }
|
|
|
+ String success = "success";
|
|
|
+ return success;
|
|
|
+ }
|
|
|
}
|