diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatApiController.java b/box-test/src/main/java/com/ruoyi/test/conrtroller/WechatApiController.java similarity index 51% rename from ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatApiController.java rename to box-test/src/main/java/com/ruoyi/test/conrtroller/WechatApiController.java index 5898a1cfa..8de1ae7a1 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatApiController.java +++ b/box-test/src/main/java/com/ruoyi/test/conrtroller/WechatApiController.java @@ -1,18 +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.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; @@ -21,6 +14,8 @@ import javax.servlet.http.HttpServletResponse; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; import java.util.Map; @Controller @@ -28,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 getJSON(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -78,4 +42,32 @@ public class WechatApiController extends BaseController { } + @GetMapping("anon/SendTextMessageToWechatUser") + @ResponseBody + public Map SendTextMessageToWechatUser() { + List userIdList = new ArrayList<>(); + userIdList.add("2342343243"); + userIdList.add("erqrqwe"); + userIdList.add("359"); + Map resultMap = wechatApiService.SendTextMessageToWechatUser(userIdList,"哈哈哈!"); + return resultMap; + } + + @GetMapping("anon/SendTextCardMessageToWechatUser") + @ResponseBody + public Map SendTextCardMessageToWechatUser() { + List userIdList = new ArrayList<>(); + userIdList.add("23456667"); + userIdList.add("355354354"); + userIdList.add("359"); + userIdList.add("454"); + userIdList.add("408"); + String title="号外:特大优惠!限时抢购"; + String description="今年仅此一次,苹果手机1000元起!欢迎前来购买!走过路过,不要错过!"; + String dtailUrl="https://item.jd.com/100008348530.html"; + + Map resultMap = wechatApiService.SendTextCardMessageToWechatUser(userIdList,title,description,dtailUrl); + return resultMap; + } + } diff --git a/box-test/src/main/resources/templates/test/index.html b/box-test/src/main/resources/templates/test/index.html index 4b05e873e..8579cdc2d 100644 --- a/box-test/src/main/resources/templates/test/index.html +++ b/box-test/src/main/resources/templates/test/index.html @@ -6,7 +6,13 @@

BPS后台管理系统-测试首页



-一、Mybaits配置DML测试-Oracle(第二数据源) + +一、集成企业微信测试 +
  • 推送文本消息到企业微信
  • +
  • 推送文本卡片消息到企业微信
  • +

    + +二、Mybaits配置DML测试-Oracle(第二数据源)
  • 查询所有用户
  • 新增ID为1000的用户
  • 根据ID查询用户,查询id=1000的用户
  • @@ -14,13 +20,13 @@
  • 删除ID为1000的用户
  • -二、Mybaits配置DDL测试-Oracle +三、Mybaits配置DDL测试-Oracle
  • 查询表中的记录数
  • 查询tc_user是否存在
  • Ajax发送获取Json配置测试

    -二、输入后验证测试 +四、输入后验证测试

  • 验证数据表中是否有记录
  • diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TestController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TestController.java index 4588a7a53..b609defb0 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TestController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/TestController.java @@ -47,7 +47,7 @@ public class TestController extends BaseController } @ApiOperation("获取用户详细") - @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path") + @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path",dataTypeClass = Integer.class ) @GetMapping("/{userId}") public AjaxResult getUser(@PathVariable Integer userId) { @@ -63,10 +63,10 @@ public class TestController extends BaseController @ApiOperation("新增用户") @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer"), - @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String"), - @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String"), - @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String") + @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class), + @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class), + @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class), + @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class) }) @PostMapping("/save") public AjaxResult save(UserEntity user) @@ -95,7 +95,7 @@ public class TestController extends BaseController } @ApiOperation("删除用户信息") - @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path") + @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class) @DeleteMapping("/{userId}") public AjaxResult delete(@PathVariable Integer userId) { diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml index cdc620e0a..86ea6e820 100644 --- a/ruoyi-admin/src/main/resources/application-druid.yml +++ b/ruoyi-admin/src/main/resources/application-druid.yml @@ -16,7 +16,7 @@ spring: url: jdbc:oracle:thin:@192.168.2.91:1521/toptest username: ds7 password: ds7 - driverClassName: oracle.jdbc.driver.OracleDriver + driverClassName: oracle.jdbc.OracleDriver #SQlServer数据源 sqlsvr: # 从数据源开关/默认关闭 @@ -33,7 +33,7 @@ spring: url: jdbc:oracle:thin:@192.168.2.91:1521/topprod username: ds_report password: ds_report - driverClassName: oracle.jdbc.driver.OracleDriver + driverClassName: oracle.jdbc.OracleDriver # Toptest_ds_report toptestdsreport: @@ -42,7 +42,7 @@ spring: url: jdbc:oracle:thin:@192.168.2.91:1521/toptest username: ds_report password: ds_report - driverClassName: oracle.jdbc.driver.OracleDriver + driverClassName: oracle.jdbc.OracleDriver # 初始连接数 initialSize: 5 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java index 8093b0a7f..11c8404b7 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java @@ -272,7 +272,9 @@ public class HttpUtils * @param params 请求参数,请求参数为json的形式。例:params="{\"params\":{\"pagesize\":1000}}" * @return 返回Map, Key="statusCode",接口访问返回状态, key="result":接口返回接果 */ - public static Map sendPostWithRest(String url, String params){ + //public static Map sendPostWithRest(String url, String params){ + //如果参数为String类型,推送企业微信消息会乱码,因此改为Object类型,直接推送Map --yangbo 20210729 + public static Map sendPostWithRest(String url, Object params){ RestTemplate restTemplate=new RestTemplate(); ResponseEntity result=null; int statusCode=0; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/WechatSendMessage.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/WechatSendMessage.java new file mode 100644 index 000000000..23d504c9c --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/WechatSendMessage.java @@ -0,0 +1,111 @@ +package com.ruoyi.system.domain; + +public class WechatSendMessage { + public String touser; + public String toparty; + public String totag; + public String msgtype; + public Integer agentid; + public String text; + public Integer safe; + public Integer enable_id_trans; + public Integer enable_duplicate_check; + public Integer duplicate_check_interval; + + public String getTouser() { + return touser; + } + + public void setTouser(String touser) { + this.touser = touser; + } + + public String getToparty() { + return toparty; + } + + public void setToparty(String toparty) { + this.toparty = toparty; + } + + public String getTotag() { + return totag; + } + + public void setTotag(String totag) { + this.totag = totag; + } + + public Integer getAgentid() { + return agentid; + } + + public void setAgentid(Integer agentid) { + this.agentid = agentid; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Integer getSafe() { + return safe; + } + + public void setSafe(Integer safe) { + this.safe = safe; + } + + public Integer getEnable_id_trans() { + return enable_id_trans; + } + + public void setEnable_id_trans(Integer enable_id_trans) { + this.enable_id_trans = enable_id_trans; + } + + public Integer getEnable_duplicate_check() { + return enable_duplicate_check; + } + + public void setEnable_duplicate_check(Integer enable_duplicate_check) { + this.enable_duplicate_check = enable_duplicate_check; + } + + public Integer getDuplicate_check_interval() { + return duplicate_check_interval; + } + + public void setDuplicate_check_interval(Integer duplicate_check_interval) { + this.duplicate_check_interval = duplicate_check_interval; + } + + public String getMsgtype() { + return msgtype; + } + + @Override + public String toString() { + return "WechatSendMessage{" + + "touser='" + touser + '\'' + + ", toparty='" + toparty + '\'' + + ", totag='" + totag + '\'' + + ", msgtype='" + msgtype + '\'' + + ", agentid=" + agentid + + ", text='" + text + '\'' + + ", safe=" + safe + + ", enable_id_trans=" + enable_id_trans + + ", enable_duplicate_check=" + enable_duplicate_check + + ", duplicate_check_interval=" + duplicate_check_interval + + '}'; + } + + public void setMsgtype(String msgtype) { + this.msgtype = msgtype; + } + +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/WechatUserInfo.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/WechatUserInfo.java index b66f361d3..b29cdfdc5 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/WechatUserInfo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/WechatUserInfo.java @@ -3,36 +3,36 @@ package com.ruoyi.system.domain; import java.util.List; public class WechatUserInfo { - String errocode; //返回码 + Integer errcode; //返回码 String errmsg; //返回码描述 String Userid; //成员UserID String name; //成员名称 - String depatrment; //成员所属部门id列表 - String order; //部门内的排序值 + Object department; //成员所属部门id列表 + Object order; //部门内的排序值 String position; //职务信息 String mobile; //手机号码 String gender; //性别,0:未定义,1:男,2:女 String email; //邮箱 - String is_leader_in_dept; //在所在的部门内是否为上级 + Object is_leader_in_dept; //在所在的部门内是否为上级 String avatar; //头像Url String thumb_avatar; //头像缩略图Url String telephone; //座机 String alias; //别名 String address; //地址 String open_userid; //全局唯一id - String main_department; //主部门 - String extattr; //扩展属性 - String Status; //激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。 + Integer main_department; //主部门 + Object extattr; //扩展属性 + Integer Status; //激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。 String qr_code; //员工个人二维码 String external_position; // 对外职务 - String external_profile; //成员对外属性 + Object external_profile; //成员对外属性 - public String getErrocode() { - return errocode; + public Integer getErrcode() { + return errcode; } - public void setErrocode(String errocode) { - this.errocode = errocode; + public void setErrcode(Integer errcode) { + this.errcode = errcode; } public String getErrmsg() { @@ -59,19 +59,19 @@ public class WechatUserInfo { this.name = name; } - public String getDepatrment() { - return depatrment; + public Object getdepartment() { + return department; } - public void setDepatrment(String depatrment) { - this.depatrment = depatrment; + public void setdepartment(Object department) { + this.department = department; } - public String getOrder() { + public Object getOrder() { return order; } - public void setOrder(String order) { + public void setOrder(Object order) { this.order = order; } @@ -107,11 +107,11 @@ public class WechatUserInfo { this.email = email; } - public String getIs_leader_in_dept() { + public Object getIs_leader_in_dept() { return is_leader_in_dept; } - public void setIs_leader_in_dept(String is_leader_in_dept) { + public void setIs_leader_in_dept(Object is_leader_in_dept) { this.is_leader_in_dept = is_leader_in_dept; } @@ -163,27 +163,27 @@ public class WechatUserInfo { this.open_userid = open_userid; } - public String getMain_department() { + public Integer getMain_department() { return main_department; } - public void setMain_department(String main_department) { + public void setMain_department(Integer main_department) { this.main_department = main_department; } - public String getExtattr() { + public Object getExtattr() { return extattr; } - public void setExtattr(String extattr) { + public void setExtattr(Object extattr) { this.extattr = extattr; } - public String getStatus() { + public Integer getStatus() { return Status; } - public void setStatus(String status) { + public void setStatus(Integer status) { Status = status; } @@ -203,13 +203,11 @@ public class WechatUserInfo { this.external_position = external_position; } - public String getExternal_profile() { + public Object getExternal_profile() { return external_profile; } - public void setExternal_profile(String external_profile) { + public void setExternal_profile(Object external_profile) { this.external_profile = external_profile; } - - } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatApiService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatApiService.java index d4968517f..604043ee9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatApiService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IWechatApiService.java @@ -1,9 +1,49 @@ package com.ruoyi.system.service; +import com.ruoyi.system.domain.WechatSendMessage; +import com.ruoyi.system.domain.WechatUserInfo; + +import java.util.List; +import java.util.Map; + public interface IWechatApiService { //获取Access Token public String GetAccessToken(); //根据企业微信登录身份获取本地LoginName public String GetLoginNameWithWechatCode(String code); + + /** + * 根据企业微信登录链接的code用户获取userid; + * @param code + * @return userid + */ + public String GetUseridByWechatLogin(String code); + + /** + * 根据企业微信userid获取用户详细信息 + * @param userId + * @return 用户详细信息 + */ + public WechatUserInfo GetWechatUserInfoDetailByUserId(String userId); + + /** + * 推送text消息到企业微信用户 + * @param toUserList 发送的用户列表 + * @param message 发送的消息内容 + * @return 消息发送结果 + */ + public Map SendTextMessageToWechatUser(List toUserList, String message); + + /** + * 推送文本卡片消息到企业微信用户 + * description参数说明:支持使用br标签或者空格来进行换行处理,也支持使用div标签来使用不同的字体颜色,目前内置了3种文字颜色:灰色(gray)、高亮(highlight)、默认黑色(normal),将其作为div标签的class属性即可 + * 示例:"description" : "

    2016年9月26日
    恭喜你抽中iPhone 7一台,领奖码:xxxx
    请于2016年10月10日前联系行政同事领取
    " + * @param toUserList 发送的用户列表 + * @param title 标题 + * @param description 内容描述 + * @param detailUrl 点击详情的Url地址 + * @return 消息发送结果 + */ + public Map SendTextCardMessageToWechatUser(List toUserList, String title, String description, String detailUrl); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatApiServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatApiServiceImpl.java index cc936330a..d5b91b77c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatApiServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatApiServiceImpl.java @@ -8,15 +8,17 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.system.domain.WechatAccessToken; +import com.ruoyi.system.domain.WechatSendMessage; +import com.ruoyi.system.domain.WechatUserInfo; import com.ruoyi.system.mapper.WechatAccessTokenMapper; import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.IWechatApiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.ResponseBody; -import java.util.Date; -import java.util.List; +import java.util.*; @Service public class WechatApiServiceImpl implements IWechatApiService { @@ -111,38 +113,19 @@ public class WechatApiServiceImpl implements IWechatApiService { public String GetLoginNameWithWechatCode(String code) { //获取访问用户身份ID - 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麻烦,开发调试时打开 - JSONObject jsonObjectUserInfo = JSONObject.parseObject(userInfo); - //如果返回码不为0,则输出错误信息,并返回空值 - if ( Integer.parseInt(jsonObjectUserInfo.getString("errcode")) != 0){ - System.out.println(jsonObjectUserInfo.getString("errmsg")); - return ""; - } - String userId = jsonObjectUserInfo.getString("UserId"); + String userId= GetUseridByWechatLogin(code); //获取用户邮箱与姓名 - url="https://qyapi.weixin.qq.com/cgi-bin/user/get"; - param="access_token="+wechatApiService.GetAccessToken()+"&userid="+userId; - String userInfoDetail=HttpUtils.sendGet(url,param); //获取成员信息 - JSONObject jsonObjectUserInfoDetail=JSONObject.parseObject(userInfoDetail); - //如果返回码不为0,则返回错误信息 - if(Integer.parseInt(jsonObjectUserInfoDetail.getString("errcode")) != 0) - { - System.out.println(jsonObjectUserInfo.getString("errmsg")); - return ""; - } - String userEmail= jsonObjectUserInfoDetail.getString("email"); - String userName= jsonObjectUserInfoDetail.getString("name"); + WechatUserInfo wechatUserInfo = GetWechatUserInfoDetailByUserId(userId); - //根据邮箱名+用户名匹配本地用户对应的邮箱名与用户名 - SysUser sysUser=new SysUser(); - sysUser.setUserName(userName); - sysUser.setEmail(userEmail); - sysUser.setUserType("02"); //只获取从OA同步的用户,保持与企业微信一致。 - List userList= userService.selectUserLists(sysUser); + //根据用户id+邮箱名+用户名匹配本地用户对应的userId+邮箱名与用户名 + SysUser sysUserWechat=new SysUser(); + sysUserWechat.setUserId(Long.parseLong(wechatUserInfo.getUserid())); + sysUserWechat.setUserName(wechatUserInfo.getName()); + sysUserWechat.setEmail(wechatUserInfo.getEmail()); + sysUserWechat.setUserType("02"); //只获取从OA同步的用户,保持与企业微信一致。 + + List userList= userService.selectUserLists(sysUserWechat); int count= userList.size(); if(count <= 0){ return ""; //系统里没有用户,没有从OA同步? 处理逻辑待定 @@ -155,4 +138,115 @@ public class WechatApiServiceImpl implements IWechatApiService { } + /** + * 根据企业微信登录链接的code用户获取userid; + * + * @param code + * @return userid + */ + @Override + 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麻烦,开发调试时打开 + JSONObject jsonObjectUserInfo = JSONObject.parseObject(userInfo); + //如果返回码不为0,则输出错误信息,并返回空值 + if ( Integer.parseInt(jsonObjectUserInfo.getString("errcode")) != 0){ + System.out.println(jsonObjectUserInfo.getString("errmsg")); + return ""; + } + return jsonObjectUserInfo.getString("UserId"); + } + + /** + * 根据企业微信userid获取用户详细信息 + * + * @param userId + * @return 用户详细信息 + */ + @Override + public WechatUserInfo GetWechatUserInfoDetailByUserId(String userId) { + String url="https://qyapi.weixin.qq.com/cgi-bin/user/get"; + String param="access_token="+wechatApiService.GetAccessToken()+"&userid="+userId; + String userInfoDetail=HttpUtils.sendGet(url,param); //获取成员信息 + WechatUserInfo wechatUserInfo = JSONObject.parseObject(userInfoDetail,WechatUserInfo.class); + //如果返回码不为0,则返回空,显示错误信息 + if (wechatUserInfo.getErrcode() !=0) + { + System.out.println(wechatUserInfo.getErrmsg()); + return null; + } + return wechatUserInfo; + } + + //将List转换为企业微信人员格式,例[359|358] + private String CovertListToWechatTouserFormat(List toUserList){ + StringBuilder toUser = new StringBuilder(); + for(String user:toUserList){ + toUser.append(user); + if(toUserList.indexOf(user) < toUserList.size()-1){ + toUser.append("|"); + } + } + return toUser.toString(); + } + + /** + * 推送text消息到企业微信用户 + * @param toUserList 发送的用户列表 + * @param message 发送的消息内容 + * @return 消息发送结果 + */ + @Override + public Map SendTextMessageToWechatUser(List toUserList,String message) { + Map resultMap; + Map param = new HashMap<>(16); + param.put("touser", CovertListToWechatTouserFormat(toUserList)); + param.put("msgtype", "text"); + param.put("agentid", agentId); + + Map text = new HashMap<>(16); + text.put("content", message); + param.put("text", text); + + String url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+wechatApiService.GetAccessToken(); + + //param参数需要直接使用对象,而不能转换成json字符串,否则推送到企业微信中文消息乱码。 + resultMap =HttpUtils.sendPostWithRest(url,param); + return resultMap; + } + + /** + * 推送文本卡片消息到企业微信用户 + * description参数说明:支持使用br标签或者空格来进行换行处理,也支持使用div标签来使用不同的字体颜色,目前内置了3种文字颜色:灰色(gray)、高亮(highlight)、默认黑色(normal),将其作为div标签的class属性即可 + * 示例:"description" : "
    2016年9月26日
    恭喜你抽中iPhone 7一台,领奖码:xxxx
    请于2016年10月10日前联系行政同事领取
    " + * + * @param toUserList 发送的用户列表 + * @param title 标题 + * @param description 内容描述 + * @param detailUrl 点击详情的Url地址 + * @return 消息发送结果 + */ + @Override + public Map SendTextCardMessageToWechatUser(List toUserList, String title, String description, String detailUrl) { + Map resultMap; + Map param = new HashMap<>(16); + param.put("touser", CovertListToWechatTouserFormat(toUserList)); + param.put("msgtype", "textcard"); + param.put("agentid", agentId); + + Map textcard=new HashMap<>(); + textcard.put("title",title); + textcard.put("description",description); + textcard.put("url",detailUrl); + param.put("textcard",textcard); + + String url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+wechatApiService.GetAccessToken(); + + //param参数需要直接使用对象,而不能转换成json字符串,否则推送到企业微信中文消息乱码。 + resultMap =HttpUtils.sendPostWithRest(url,param); + return resultMap; + } + } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index 827c417b5..f78713eac 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -231,6 +231,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"