|
|
@@ -1,25 +1,27 @@
|
|
|
package com.cyksj.web.controller.user;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
+import com.cyksj.mapper.UserTransferLogMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponUserMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindPhoneMapper;
|
|
|
+import com.cyksj.model.dto.GzhUnionidUserinfo;
|
|
|
import com.cyksj.model.dto.UserWhoami;
|
|
|
-import com.cyksj.model.entity.CouponUser;
|
|
|
-import com.cyksj.model.entity.OrderDon;
|
|
|
-import com.cyksj.model.entity.User;
|
|
|
-import com.cyksj.model.entity.UserBindPhone;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.ExchangeCodeTicket;
|
|
|
import com.cyksj.model.views.RenewalView;
|
|
|
import com.cyksj.model.views.UserPersonalView;
|
|
|
import com.cyksj.service.exchange.ExchangeCodeService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.user.UserService;
|
|
|
+import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -31,6 +33,7 @@ import java.util.List;
|
|
|
@RequestMapping("/applets/user")
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class UserController {
|
|
|
|
|
|
private final UserService userService;
|
|
|
@@ -98,4 +101,49 @@ public class UserController {
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(personalView);
|
|
|
}
|
|
|
+
|
|
|
+ private final WeChatService weChatService;
|
|
|
+
|
|
|
+ private final UserTransferLogMapper userTransferLogMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取微信用户信息
|
|
|
+ */
|
|
|
+ @GetMapping("/get/wx/user")
|
|
|
+ public void syncUser() {
|
|
|
+ List<User> users = userService.list(Wrappers.lambdaQuery(User.class)
|
|
|
+ .ne(User::getUnionid, ""));
|
|
|
+ String appId = "wxd58016eee53b6558";
|
|
|
+ users.forEach(user->{
|
|
|
+ try {
|
|
|
+ String accessToken = weChatService.getAccessToken();
|
|
|
+ GzhUnionidUserinfo userInfo2 = weChatService.getUserInfo2(accessToken, user.getOpenId());
|
|
|
+ if (userInfo2 == null) {
|
|
|
+ log.info(user.getOpenId() + "失联");
|
|
|
+ }
|
|
|
+ if (StrUtil.isEmpty(userInfo2.getUnionid())) {
|
|
|
+ log.info(user.getOpenId() + "未关注新公众号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (user.getUnionid().equals(userInfo2.getUnionid())) {
|
|
|
+ log.info("新旧公众号unionid相同");
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ user.setUnionid(userInfo2.getUnionid());
|
|
|
+ userService.updateById(user);
|
|
|
+
|
|
|
+ UserTransferLog log = new UserTransferLog();
|
|
|
+ log.setAppId(appId);
|
|
|
+ log.setUserId(user.getId());
|
|
|
+ log.setOldUnionid(user.getUnionid());
|
|
|
+ log.setType("手动同步");
|
|
|
+ log.setNewUnionid(userInfo2.getUnionid());
|
|
|
+
|
|
|
+ userTransferLogMapper.insert(log);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("获取accesstoken错误");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|