1、解决WARN警告: Unable to interpret the implicit parameter configuration

2、修改HttpUtils,sendPostWithRest方法,如果参数为String类型,推送企业微信消息会乱码,因此改为Object类型,直接推送Map<Sring,Object>
3、实现企业微信消息推送
This commit is contained in:
bo.yang 2021-07-30 10:57:11 +08:00
parent e0eac9fe2f
commit 4b229b867a
4 changed files with 16 additions and 48 deletions

View File

@ -1,19 +1,11 @@
package com.ruoyi.web.controller.system;
package com.ruoyi.test.conrtroller;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.shiro.util.CustToken;
import com.ruoyi.system.service.IWechatApiService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletException;
@ -31,42 +23,11 @@ public class WechatApiController extends BaseController {
@Autowired
IWechatApiService wechatApiService;
@RequestMapping("anon/getAccessToken")
/* @RequestMapping("anon/getAccessToken")
public String getAccessToken() {
return wechatApiService.GetAccessToken();
}
@GetMapping("anon/wechatLogin")
@ResponseBody
public AjaxResult WechatLogin(HttpServletRequest request)
{
String code= request.getParameter("code");
String state = request.getParameter("state");
String username=wechatApiService.GetLoginNameWithWechatCode(code);
String password="";
Boolean rememberMe=true;
String loginType=request.getParameter("loginType");
//UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
CustToken token=new CustToken(username,password,rememberMe,loginType);
Subject subject = SecurityUtils.getSubject();
try
{
subject.login(token);
return success();
}
catch (AuthenticationException e)
{
String msg = "用户或密码错误";
if (StringUtils.isNotEmpty(e.getMessage()))
{
msg = e.getMessage();
}
return error(msg);
}
}
*/
@GetMapping("anon/userInfo")
public Map<String, Object> getJSON(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

View File

@ -6,7 +6,13 @@
</head>
<body>
<h1>BPS后台管理系统-测试首页</h1><br><br>
一、Mybaits配置DML测试-Oracle第二数据源
一、集成企业微信测试
<li><a th:href="@{anon/SendTextMessageToWechatUser}">推送文本消息到企业微信</a></li>
<li><a th:href="@{anon/SendTextCardMessageToWechatUser}">推送文本卡片消息到企业微信</a></li>
<p></p>
二、Mybaits配置DML测试-Oracle第二数据源
<li><a th:href="@{/test/selectAll}">查询所有用户</a></li>
<li><a th:href="@{/test/insert?id=1000&name=bo&password=12}">新增ID为1000的用户</a></li>
<li><a th:href="@{/test/selectById/1000}">根据ID查询用户,查询id=1000的用户</a></li>
@ -14,13 +20,13 @@
<li><a th:href="@{/test/deleteById?id=1000}">删除ID为1000的用户</a></li>
<p></p>
、Mybaits配置DDL测试-Oracle
、Mybaits配置DDL测试-Oracle
<li><a th:href="@{/test/getRecordCount}">查询表中的记录数</a></li>
<li><a th:href="@{/test/isTableInDb}">查询tc_user是否存在</a></li>
<p />
<a th:href="@{/test/sendjson}">Ajax发送获取Json配置测试 </a>
<p />
、输入后验证测试
、输入后验证测试
<li><a th:href="@{/test/testVerify}">验证数据表中是否有记录</a></li>
<p />

View File

@ -148,8 +148,8 @@ public class WechatApiServiceImpl implements IWechatApiService {
public String GetUseridByWechatLogin(String code) {
String url="https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
String param = "access_token="+wechatApiService.GetAccessToken()+"&code="+code;
//String userInfo = HttpUtils.sendGet(url,param); //测试已能正常返回UserInfo Json,正式使用时打开
String userInfo = "{\"UserId\":\"359\",\"DeviceId\":\"10000589102865WJ\",\"errcode\":0,\"errmsg\":\"ok\"}"; //为避免去微信获取code麻烦开发调试时打开
String userInfo = HttpUtils.sendGet(url,param); //测试已能正常返回UserInfo Json,正式使用时打开
//String userInfo = "{\"UserId\":\"359\",\"DeviceId\":\"10000589102865WJ\",\"errcode\":0,\"errmsg\":\"ok\"}"; //为避免去微信获取code麻烦开发调试时打开
JSONObject jsonObjectUserInfo = JSONObject.parseObject(userInfo);
//如果返回码不为0则输出错误信息并返回空值
if ( Integer.parseInt(jsonObjectUserInfo.getString("errcode")) != 0){
@ -180,6 +180,7 @@ public class WechatApiServiceImpl implements IWechatApiService {
return wechatUserInfo;
}
//将List转换为企业微信人员格式[359|358]
private String CovertListToWechatTouserFormat(List<String> toUserList){
StringBuilder toUser = new StringBuilder();
for(String user:toUserList){

View File

@ -231,7 +231,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectUserLists" parameterType="SysUser" resultMap="SysUserResult">
select user_id, dept_id, login_name, user_name, user_type, email, avatar, phonenumber, password, sex, salt, status, del_flag, login_ip, login_date, create_by, create_time, remark from sys_user
where del_flag = '0'
<if test="userId != null and useId != ''">
<if test="userId != null and userId != ''">
AND user_id = #{userId}
</if>
<if test="userName != null and userName != ''">