| | |
| | | package com.ruoyi.web.controller.evaluation; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | |
| | | private String wechatAppSecret; |
| | | |
| | | /** |
| | | * 生成微信授权URL |
| | | */ |
| | | @Anonymous |
| | | @GetMapping("/wechat/authurl") |
| | | public AjaxResult getWechatAuthUrl(String redirectUri, String state) { |
| | | try { |
| | | if (StringUtils.isEmpty(redirectUri)) { |
| | | return error("回调地址不能为空"); |
| | | } |
| | | |
| | | logger.info("生成微信授权URL - 原始redirectUri: {}", redirectUri); |
| | | |
| | | // 生成微信授权URL,使用snsapi_userinfo获取用户信息 |
| | | String authUrl = WechatUtils.generateAuthUrl(wechatAppId, redirectUri, "snsapi_userinfo", state); |
| | | if (authUrl == null) { |
| | | return error("生成微信授权URL失败"); |
| | | } |
| | | |
| | | logger.info("生成微信授权URL成功: {}", authUrl); |
| | | |
| | | Map<String, String> result = new HashMap<>(); |
| | | result.put("authUrl", authUrl); |
| | | result.put("originalRedirectUri", redirectUri); |
| | | result.put("appId", wechatAppId); |
| | | return success(result); |
| | | } catch (Exception e) { |
| | | logger.error("生成微信授权URL失败", e); |
| | | return error("生成微信授权URL失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取微信用户信息 |
| | | */ |
| | | @Anonymous |
| | |
| | | public AjaxResult getWechatUserInfo(String code, HttpServletRequest request) { |
| | | try { |
| | | |
| | | if (StringUtils.isEmpty(code)) { |
| | | if (code.isEmpty()) { |
| | | return error("授权码不能为空"); |
| | | } |
| | | |
| | |
| | | return error("获取微信用户信息失败"); |
| | | } |
| | | |
| | | return success(userInfo); |
| | | // 处理用户信息,确保字段名称一致 |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("openid", userInfo.getString("openid")); |
| | | result.put("nickname", userInfo.getString("nickname")); |
| | | result.put("headimgurl", userInfo.getString("headimgurl")); |
| | | result.put("sex", userInfo.getInteger("sex")); |
| | | result.put("province", userInfo.getString("province")); |
| | | result.put("city", userInfo.getString("city")); |
| | | result.put("country", userInfo.getString("country")); |
| | | result.put("unionid", userInfo.getString("unionid")); |
| | | // 注意:微信网页授权无法直接获取手机号,需要通过其他方式 |
| | | // 如需获取手机号,需要使用微信小程序的getPhoneNumber接口或微信开放平台的手机号快速验证组件 |
| | | result.put("phone", ""); |
| | | result.put("phoneNote", "微信网页授权无法直接获取手机号,请手动输入"); |
| | | |
| | | return success(result); |
| | | } catch (Exception e) { |
| | | logger.error("获取微信用户信息失败", e); |
| | | return error("获取微信用户信息失败"); |
| | |
| | | |
| | | |
| | | /** |
| | | * 获取评价统计数据 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('evaluation:statistics')") |
| | | @GetMapping("/evaluation/statistics") |
| | | public AjaxResult getStatistics(CustomerEvaluation customerEvaluation) { |
| | | try { |
| | | // 获取统计数据 |
| | | Map<String, Object> statistics = customerEvaluationService.getEvaluationStatistics(customerEvaluation); |
| | | return success(statistics); |
| | | } catch (Exception e) { |
| | | logger.error("获取评价统计数据失败", e); |
| | | return error("获取统计数据失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取客户端IP地址 |
| | | */ |
| | | private String getClientIP(HttpServletRequest request) { |