|
@@ -1,13 +1,11 @@
|
|
package com.management.platform.controller;
|
|
package com.management.platform.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
-import com.management.platform.entity.Custom;
|
|
|
|
-import com.management.platform.entity.User;
|
|
|
|
-import com.management.platform.entity.WechatQrcodeScan;
|
|
|
|
-import com.management.platform.entity.WechatUserFollow;
|
|
|
|
|
|
+import com.management.platform.entity.*;
|
|
import com.management.platform.mapper.WechatQrcodeScanMapper;
|
|
import com.management.platform.mapper.WechatQrcodeScanMapper;
|
|
import com.management.platform.mapper.WechatUserFollowMapper;
|
|
import com.management.platform.mapper.WechatUserFollowMapper;
|
|
import com.management.platform.service.CustomService;
|
|
import com.management.platform.service.CustomService;
|
|
|
|
+import com.management.platform.service.MiniBindUserService;
|
|
import com.management.platform.service.UserService;
|
|
import com.management.platform.service.UserService;
|
|
import com.management.platform.service.impl.WechatApiService;
|
|
import com.management.platform.service.impl.WechatApiService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -26,6 +24,7 @@ import java.time.Instant;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@@ -51,6 +50,9 @@ public class WechatCallbackController {
|
|
@Resource
|
|
@Resource
|
|
private CustomService customService;
|
|
private CustomService customService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private MiniBindUserService miniBindUserService;
|
|
|
|
+
|
|
// 微信配置验证接口(GET请求)
|
|
// 微信配置验证接口(GET请求)
|
|
@GetMapping("/callback")
|
|
@GetMapping("/callback")
|
|
public String validate(@RequestParam("signature") String signature,
|
|
public String validate(@RequestParam("signature") String signature,
|
|
@@ -90,9 +92,9 @@ public class WechatCallbackController {
|
|
|
|
|
|
String event = root.elementText("Event");
|
|
String event = root.elementText("Event");
|
|
String openId = root.elementText("FromUserName");
|
|
String openId = root.elementText("FromUserName");
|
|
- String eventKey = root.elementText("EventKey");
|
|
|
|
|
|
+ String eventKey = StringUtils.isEmpty(root.elementText("EventKey")) ? "" : root.elementText("EventKey");
|
|
log.info("场景值ID==>"+(StringUtils.isEmpty(eventKey)?"空":eventKey));
|
|
log.info("场景值ID==>"+(StringUtils.isEmpty(eventKey)?"空":eventKey));
|
|
- String ticket = root.elementText("Ticket");
|
|
|
|
|
|
+ String ticket = StringUtils.isEmpty(root.elementText("Ticket"))?"":root.elementText("Ticket");
|
|
log.info("ticket==>"+(StringUtils.isEmpty(ticket)?"空":ticket));
|
|
log.info("ticket==>"+(StringUtils.isEmpty(ticket)?"空":ticket));
|
|
String createTime = root.elementText("CreateTime");
|
|
String createTime = root.elementText("CreateTime");
|
|
|
|
|
|
@@ -118,13 +120,16 @@ public class WechatCallbackController {
|
|
private void handleSubscribeOrScan(String event, String openId, String eventKey,
|
|
private void handleSubscribeOrScan(String event, String openId, String eventKey,
|
|
String ticket, String createTime,
|
|
String ticket, String createTime,
|
|
HttpServletRequest request) {
|
|
HttpServletRequest request) {
|
|
- // 提取销售人员ID
|
|
|
|
- String salesmanId = eventKey.startsWith("qrscene_") ?
|
|
|
|
- eventKey.substring(8) : eventKey;
|
|
|
|
-
|
|
|
|
|
|
+ String salesmanId="";
|
|
|
|
+ if (StringUtils.isNotEmpty(eventKey)&&StringUtils.isNotEmpty(ticket)) {
|
|
|
|
+ // 提取销售人员ID
|
|
|
|
+ salesmanId = eventKey.startsWith("qrscene_") ?
|
|
|
|
+ eventKey.substring(8) : eventKey;
|
|
|
|
+ }
|
|
|
|
+
|
|
// 获取用户IP
|
|
// 获取用户IP
|
|
String ipAddress = getClientIp(request);
|
|
String ipAddress = getClientIp(request);
|
|
-
|
|
|
|
|
|
+
|
|
// 获取用户信息
|
|
// 获取用户信息
|
|
Map<String, Object> userInfo = wechatApiService.getUserInfo(openId,salesmanId);//用户的openId,员工的userId
|
|
Map<String, Object> userInfo = wechatApiService.getUserInfo(openId,salesmanId);//用户的openId,员工的userId
|
|
|
|
|
|
@@ -145,6 +150,7 @@ public class WechatCallbackController {
|
|
scanRecord.setProvince((String) userInfo.get("province"));
|
|
scanRecord.setProvince((String) userInfo.get("province"));
|
|
scanRecord.setCountry((String) userInfo.get("country"));
|
|
scanRecord.setCountry((String) userInfo.get("country"));
|
|
scanRecord.setAvatarUrl((String) userInfo.get("headimgurl"));
|
|
scanRecord.setAvatarUrl((String) userInfo.get("headimgurl"));
|
|
|
|
+ scanRecord.setUnionid((String) userInfo.get("unionid"));
|
|
}
|
|
}
|
|
|
|
|
|
scanMapper.insert(scanRecord);
|
|
scanMapper.insert(scanRecord);
|
|
@@ -161,17 +167,27 @@ public class WechatCallbackController {
|
|
followRecord.setSalesmanId(salesmanId);
|
|
followRecord.setSalesmanId(salesmanId);
|
|
followMapper.insert(followRecord);
|
|
followMapper.insert(followRecord);
|
|
|
|
|
|
- Custom serviceOne = customService.getOne(new QueryWrapper<Custom>().eq("plate4", openId));
|
|
|
|
- if(serviceOne==null) {
|
|
|
|
- Custom custom = new Custom();
|
|
|
|
- custom.setCustomName(openId);//用户的openId
|
|
|
|
- custom.setIsDelete(0);
|
|
|
|
- custom.setInchargerId(salesmanId);
|
|
|
|
- if (StringUtils.isNotEmpty(salesmanId)) {
|
|
|
|
- User user = userService.getById(salesmanId);
|
|
|
|
- custom.setCompanyId(user != null ? user.getCompanyId() : null);
|
|
|
|
|
|
+ List<MiniBindUser> miniBindUserList = miniBindUserService.list(new QueryWrapper<MiniBindUser>()
|
|
|
|
+ .eq("unionid", scanRecord.getUnionid())
|
|
|
|
+ .orderByDesc("create_time")
|
|
|
|
+ .last("limit 1"));
|
|
|
|
+
|
|
|
|
+ if (!miniBindUserList.isEmpty()){
|
|
|
|
+ int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
|
|
|
|
+ if(count==0) {
|
|
|
|
+ Custom custom = new Custom();
|
|
|
|
+ custom.setCustomName(openId);//用户的openId
|
|
|
|
+ custom.setIsDelete(0);
|
|
|
|
+ custom.setInchargerId(miniBindUserList.get(0).getUserId());
|
|
|
|
+ if (StringUtils.isNotEmpty(miniBindUserList.get(0).getUserId())) {
|
|
|
|
+ User user = userService.getById(miniBindUserList.get(0).getUserId());
|
|
|
|
+ custom.setCompanyId(user != null ? user.getCompanyId() : null);
|
|
|
|
+ customService.save(custom);
|
|
|
|
+ log.info("新增客户成功");
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ log.info("已存在custom_name为"+openId+"的客户");
|
|
}
|
|
}
|
|
- customService.save(custom);
|
|
|
|
}
|
|
}
|
|
log.info("用户新关注成功");
|
|
log.info("用户新关注成功");
|
|
} else {
|
|
} else {
|