luofl
2025-03-17 daea1642642f20998bfbf1d0c72695a6bae260d7
党员认证、党员上级角色切换
2个文件已修改
2个文件已添加
253 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/SystemUserController.java 134 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/PartyMemberController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/utils/SignatureUtil.java 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/warpper/SignatureVO.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/api/SystemUserController.java
@@ -1,6 +1,10 @@
package com.panzhihua.sangeshenbian.api;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.panzhihua.common.controller.BaseController;
@@ -18,15 +22,14 @@
import com.panzhihua.sangeshenbian.service.ISystemMenuService;
import com.panzhihua.sangeshenbian.service.ISystemRoleMenuService;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
import com.panzhihua.sangeshenbian.warpper.LoginVo;
import com.panzhihua.sangeshenbian.warpper.SystemUserList;
import com.panzhihua.sangeshenbian.warpper.SystemUserListVo;
import com.panzhihua.sangeshenbian.warpper.TokenVo;
import com.panzhihua.sangeshenbian.utils.SignatureUtil;
import com.panzhihua.sangeshenbian.warpper.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
@@ -36,6 +39,7 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.security.MessageDigest;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
@@ -52,28 +56,28 @@
@RestController
@RequestMapping("/systemUser")
public class SystemUserController extends BaseController {
    @Resource
    private ISystemUserService systemUserService;
    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private TokenService tokenService;
    private final Integer max_err = 5;
    @Resource
    private ISystemRoleMenuService systemRoleMenuService;
    @Resource
    private ISystemMenuService systemMenuService;
    @PostMapping("/login")
    @ApiOperation(value = "登录", tags = {"三个身边后台-登录"})
    @OperLog(operModul = "三个身边后台",operType = 0,businessType = "登录")
@@ -107,7 +111,7 @@
        LoginReturnVO loginReturnVO = reult.getData();
        TokenVo tokenVo = new TokenVo();
        BeanUtils.copyProperties(loginReturnVO, tokenVo);
        List<SystemRoleMenu> list = systemRoleMenuService.list(new LambdaQueryWrapper<SystemRoleMenu>().eq(SystemRoleMenu::getSystemRoleId, systemUser.getSystemRoleId()));
        List<Integer> collect = list.stream().map(SystemRoleMenu::getSystemMenuId).collect(Collectors.toList());
        Set<String> collect1 = new HashSet<>();
@@ -178,8 +182,8 @@
        }
        return R.ok(tokenVo);
    }
    @PostMapping("logout")
    @ApiOperation(value = "退出登录", tags = {"三个身边后台-登录"})
    @OperLog(operModul = "三个身边后台",operType = 0,businessType = "退出登录")
@@ -190,8 +194,8 @@
        }
        return tokenService.logout(token);
    }
    @GetMapping("/list")
    @ApiOperation(value = "获取列表数据", tags = {"三个身边管理后台-人员管理"})
    @OperLog(operModul = "三个身边后台",operType = 0,businessType = "获取人员管理列表数据")
@@ -201,9 +205,9 @@
        IPage<SystemUserListVo> list = systemUserService.list(user, query);
        return R.ok(list);
    }
    @PostMapping("/add")
    @ApiOperation(value = "添加人员", tags = {"三个身边管理后台-人员管理"})
    @OperLog(operModul = "三个身边后台",operType = 1,businessType = "添加人员")
@@ -228,8 +232,8 @@
        systemUserService.save(systemUser);
        return R.ok();
    }
    @PostMapping("/edit")
    @ApiOperation(value = "编辑人员", tags = {"三个身边后台-人员管理"})
    @OperLog(operModul = "三个身边后台",operType = 2,businessType = "编辑人员")
@@ -244,8 +248,8 @@
        systemUserService.updateById(systemUser);
        return R.ok();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除人员", tags = {"三个身边后台-人员管理"})
    @OperLog(operModul = "三个身边后台",operType = 3,businessType = "删除人员")
@@ -255,8 +259,8 @@
        systemUserService.updateById(systemUser);
        return R.ok();
    }
    @GetMapping("/getSystemUserInfo/{id}")
    @ApiOperation(value = "查询人员详情", tags = {"三个身边后台-人员管理"})
    @OperLog(operModul = "三个身边后台",operType = 0,businessType = "查询人员详情")
@@ -264,8 +268,8 @@
        SystemUser systemUser = systemUserService.getById(id);
        return R.ok(systemUser);
    }
    @PutMapping("/freeze/{id}")
    @ApiOperation(value = "冻结账号", tags = {"三个身边后台-人员管理"})
    @OperLog(operModul = "三个身边后台",operType = 2,businessType = "冻结账号")
@@ -278,8 +282,8 @@
        systemUserService.updateById(systemUser);
        return R.ok();
    }
    @PutMapping("/unfreeze/{id}")
    @ApiOperation(value = "解冻账号", tags = {"三个身边后台-人员管理"})
    @OperLog(operModul = "三个身边后台",operType = 2,businessType = "解冻账号")
@@ -292,8 +296,8 @@
        systemUserService.updateById(systemUser);
        return R.ok();
    }
    /**
     * 根据用户id获取信息
     * @param id
@@ -314,9 +318,9 @@
        BeanUtils.copyProperties(systemUser, systemUserVo);
        return R.ok(systemUserVo);
    }
    @GetMapping("/getAdministrativeDivision/{id}/{tier}")
    @ApiOperation(value = "获取行政区划层级联动数据", tags = {"三个身边后台-人员管理"})
    @ApiImplicitParams({
@@ -350,38 +354,30 @@
    }
    public static void main(String[] args) {
    @GetMapping("/getSignature")
    @ApiOperation(value = "获取签名",tags = {"三个身边小程序"})
    public R<?> getSignature() throws Exception {
        String APP_ID = "wx118de8a734d269f0";
        String APP_SECRET = "0264342daefde5cd70a6adada09ee5b1";
        String accessToken = SignatureUtil.getAccessToken(APP_ID, APP_SECRET);
        String jsapiTicket = SignatureUtil.getJsApiTicket(accessToken);
        String nonceStr = UUID.randomUUID().toString().replace("-", "");
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        String url = "https://huacheng.psciio.com/web/sangeshenbian/"; // 当前页面的URL,不包含#及其后面部分
    }
        String signature = SignatureUtil.getSignature(jsapiTicket, nonceStr, timestamp, url);
//    private String ACCESS_TOKEN_URL = "GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
//
//    public String getAppAccessToken(String appId, String appSecret) throws Exception {
//        String accessToken = "0";
//        try {
//            log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret);
//            String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + appId + "&secret=" + appSecret;
//            String result = HttpClientUtil.httpGet(accessTokenUrl, null, null);
//            Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
//            StringRedisTemplate redisTemplate = wxXCXTempSend.stringRedisTemplate;
//            if (resultMap.containsKey("access_token")) {
//                accessToken = resultMap.get("access_token").toString();
//                redisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken);
//            }
//            HttpServletRequest request = ServletUtils.getRequest();
//            String requestURI = request.getRequestURI();
//            //加上时间戳
//            String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date());
//            //这里是 Redis key的前缀,如: sys:tabieId:表名  如果不需要去掉表名也可以
//            String key = MessageFormat.format("{0}:{1}:{2}",  "access_token_request_incr",datetime,requestURI);
//            //查询 key 是否存在, 不存在返回 1 ,存在的话则自增加1
//            redisTemplate.opsForValue().increment(key, 1);
//
//        } catch (IOException ioe) {
//            log.error("小程序http请求异常");
//            ioe.printStackTrace();
//        }
//        return accessToken;
//    }
        System.out.println("appId: " + APP_ID);
        System.out.println("timestamp: " + timestamp);
        System.out.println("nonceStr: " + nonceStr);
        System.out.println("signature: " + signature);
        SignatureVO signatureVO = new SignatureVO();
        signatureVO.setTimestamp(timestamp);
        signatureVO.setNonceStr(nonceStr);
        signatureVO.setSignature(signature);
        return R.ok(signatureVO);
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/controller/PartyMemberController.java
@@ -1,16 +1,10 @@
package com.panzhihua.sangeshenbian.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.sangeshenbian.model.entity.BcRegion;
import com.panzhihua.sangeshenbian.model.entity.ComStreet;
import com.panzhihua.sangeshenbian.model.entity.PartyMember;
import com.panzhihua.sangeshenbian.service.IBcRegionService;
import com.panzhihua.sangeshenbian.service.IComActService;
import com.panzhihua.sangeshenbian.service.IComStreetService;
import com.panzhihua.sangeshenbian.service.IPartyMemberService;
import com.panzhihua.sangeshenbian.warpper.PartyMemberApplicationRequest;
import com.panzhihua.sangeshenbian.warpper.PartyMemberAuditRequest;
@@ -20,14 +14,12 @@
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;
@Api(tags = {"小程序-党员管理"})
@@ -36,9 +28,6 @@
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PartyMemberController extends BaseController {
    private final IPartyMemberService partyMemberService;
    private final IBcRegionService bcRegionService;
    private final IComStreetService comStreetService;
    private final IComActService comActService;
    /**
     * 党员申请
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/utils/SignatureUtil.java
New file
@@ -0,0 +1,98 @@
package com.panzhihua.sangeshenbian.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class SignatureUtil {
    private static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
    private static final String JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi";
    public static String getAccessToken(String appId, String appSecret) throws Exception {
        String url = String.format(ACCESS_TOKEN_URL, appId, appSecret);
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        Map<String, String> result = parseJson(response.toString());
        return result.get("access_token");
    }
    public static String getJsApiTicket(String accessToken) throws Exception {
        String url = String.format(JSAPI_TICKET_URL, accessToken);
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        Map<String, String> result = parseJson(response.toString());
        return result.get("ticket");
    }
    private static Map<String, String> parseJson(String json) {
        // 简单的JSON解析,实际项目中可以使用更强大的库如Jackson或Gson
        Map<String, String> map = new HashMap<>();
        String[] keyValuePairs = json.replace("{", "").replace("}", "").split(",");
        for (String pair : keyValuePairs) {
            String[] entry = pair.split(":");
            map.put(entry[0].trim().replace("\"", ""), entry[1].trim().replace("\"", ""));
        }
        return map;
    }
    public static String getSignature(String jsapiTicket, String nonceStr, String timestamp, String url) throws Exception {
        Map<String, String> params = new HashMap<>();
        params.put("jsapi_ticket", jsapiTicket);
        params.put("noncestr", nonceStr);
        params.put("timestamp", timestamp);
        params.put("url", url);
        String[] keys = params.keySet().toArray(new String[0]);
        Arrays.sort(keys);
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            sb.append(key).append("=").append(params.get(key)).append("&");
        }
        sb.deleteCharAt(sb.length() - 1); // Remove the last '&'
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] hashBytes = md.digest(sb.toString().getBytes("UTF-8"));
        StringBuilder hexString = new StringBuilder();
        for (byte b : hashBytes) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/warpper/SignatureVO.java
New file
@@ -0,0 +1,10 @@
package com.panzhihua.sangeshenbian.warpper;
import lombok.Data;
@Data
public class SignatureVO {
    private String timestamp;
    private String nonceStr;
    private String signature;
}