package com.fzzy.appwx.controller;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.fzzy.appwx.constant.WeChatConst;
|
import com.fzzy.appwx.manager.WeChatManager;
|
import com.fzzy.appwx.param.WeChatBaseParam;
|
import com.fzzy.group.manager.GroupManager;
|
import com.fzzy.igds.data.ConfigData;
|
import com.fzzy.igds.data.PageResponse;
|
import com.fzzy.igds.domain.Dept;
|
import com.fzzy.igds.domain.SnapReply;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.List;
|
|
@Slf4j
|
@Controller
|
@RequestMapping("/wx")
|
public class WeChatController {
|
|
@Resource
|
private ConfigData configData;
|
@Resource
|
private WeChatManager weChatManager;
|
@Resource
|
private GroupManager groupManager;
|
|
|
/**
|
* 微信菜单重定向获取code
|
*
|
* @param tag
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping
|
public String redirect(
|
@RequestParam(value = "tag", required = false) String tag) throws Exception {
|
|
String url = configData.getWxServeUrl() + "/wx/view-gateway";
|
|
if (StringUtils.isEmpty(tag)) {
|
tag = "home";
|
}
|
|
// String newUrl = WeChatConst.USER_AUTH_UPR
|
// .replace("APPID", configData.getWxAppId())
|
// .replace("REDIRECT_URI", URLEncoder.encode(url, "UTF-8"))
|
// .replace("STATE", tag);
|
//
|
// return "redirect:" + newUrl;
|
return "redirect:" + url + "?state=" + tag;
|
}
|
|
|
/**
|
* 页面分发
|
*
|
* @param
|
* @return
|
*/
|
@RequestMapping("/view-gateway")
|
public ModelAndView viewGateway(
|
@RequestParam(value = "code", required = false) String code,
|
@RequestParam(value = "state") String state,
|
@RequestParam(value = "id", required = false) String id,
|
@RequestParam(value = "companyId", required = false) String companyId,
|
@RequestParam(value = "loginType", required = false) String loginType,
|
@RequestParam(value = "userName", required = false) String userName) {
|
|
ModelAndView mv = new ModelAndView();
|
|
//code不为空则获取openid
|
if (StringUtils.isNotEmpty(code)) {
|
String openid = weChatManager.getOpenid(code);
|
mv.addObject("openid", openid);
|
SysUser user = weChatManager.getUser(openid);
|
if (StringUtils.isEmpty(userName)) {
|
if (user != null) {
|
userName = user.getUserName();
|
}
|
}
|
|
}
|
|
if (StringUtils.isNotEmpty(id)) {
|
mv.addObject("id", id);
|
mv.addObject("companyId", companyId);
|
}
|
//判断是公众号还是APP,默认为公众号
|
if (StringUtils.isEmpty(loginType)) {
|
loginType = WeChatConst.LOGIN_TYPE_WECHAT;
|
}
|
mv.addObject("loginType", loginType);
|
|
if (StringUtils.isNotEmpty(userName)) {
|
mv.addObject("userName", userName);
|
}
|
mv.setViewName("/wx/" + state);
|
//验证码类型
|
if("bind".equals( state) || "unbind".equals( state)){
|
mv.addObject("captchaType", "math");
|
}
|
|
|
//查询库区信息
|
List<Dept> deptList = groupManager.getDeptList();
|
mv.addObject("deptList", deptList);
|
|
|
// //测试代码开启
|
String openid = "testOpenId";
|
mv.addObject("openid", openid);
|
SysUser user = weChatManager.getUser(openid);
|
if (StringUtils.isEmpty(userName)) {
|
if (user != null) {
|
userName = user.getUserName();
|
}
|
}
|
|
if (StringUtils.isNotEmpty(userName)) {
|
mv.addObject("userName", userName);
|
}
|
// //测试代码结束
|
|
return mv;
|
}
|
|
|
/**
|
* 获取用户的绑定信息
|
*
|
* @param param
|
* @author sgj
|
* @since 2026/04/11
|
*/
|
@PostMapping(value = "/getUserBindInfo")
|
@ResponseBody
|
public PageResponse<SysUser> getUserBindInfo( @RequestBody WeChatBaseParam param) {
|
return weChatManager.getUserBindInfo(param);
|
}
|
|
|
/**
|
* 绑定openId
|
*
|
* @param param
|
* @author sgj
|
* @since 2026/04/11
|
*/
|
@PostMapping(value = "/bandOpenId")
|
@ResponseBody
|
public PageResponse<String> bandOpenId(HttpServletRequest httpRequest, @RequestBody WeChatBaseParam param) {
|
return weChatManager.bandOpenId(httpRequest,param);
|
}
|
|
/**
|
* 解绑openId
|
*
|
* @param param
|
* @author sgj
|
* @since 2026/04/11
|
*/
|
@PostMapping(value = "/unBandOpenId")
|
@ResponseBody
|
public PageResponse<String> unBandOpenId( HttpServletRequest httpRequest, @RequestBody WeChatBaseParam param) {
|
//在这里调用验证码校验
|
|
return weChatManager.unBandOpenId(httpRequest,param);
|
}
|
|
|
|
/**
|
* 获取出入库告警批复分页数据
|
*
|
* @param param
|
* @author sgj
|
* @since 2026/04/11
|
*/
|
@PostMapping(value = "/getSnapReplyPage")
|
@ResponseBody
|
public PageResponse<Page<SnapReply>> getSnapReplyPage(@RequestBody WeChatBaseParam param) {
|
return weChatManager.getSnapReplyPage(param);
|
}
|
|
/**
|
* 根据id获取告警批复详细内容
|
*
|
* @param param
|
* @author sgj
|
* @since 2026/04/11
|
*/
|
@PostMapping(value = "/getSnapReplyInfoById")
|
@ResponseBody
|
public PageResponse<SnapReply> getSnapReplyInfoById(@RequestBody WeChatBaseParam param) {
|
return weChatManager.getSnapReplyInfoById(param);
|
}
|
|
|
/**
|
* 根据id获取告警批复详细内容
|
*
|
* @param param
|
* @author sgj
|
* @since 2026/04/11
|
*/
|
@PostMapping(value = "/handleSnapReply")
|
@ResponseBody
|
public PageResponse<String> handleSnapReply(@RequestBody WeChatBaseParam param) {
|
return weChatManager.handleSnapReply(param);
|
}
|
|
}
|