|
@@ -364,7 +364,50 @@ public class WeiXinCorpController {
|
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAesKey, corpId);
|
|
|
String sMsg = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, requestBody);
|
|
|
log.info("解密后===msg: " + sMsg);
|
|
|
+ org.json.JSONObject jsonObject = XML.toJSONObject(sMsg);
|
|
|
+ if(jsonObject.has("Event") && ("subscribe".equals(jsonObject.getString("Event")))){
|
|
|
+ //成员关注应用事件,发生在该企业已经开通应用的情况下。
|
|
|
+ System.out.println("成员关注应用事件!");
|
|
|
+ String corpWxUserId = jsonObject.getString("FromUserName");
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
+ if (wxCorpInfo != null) {
|
|
|
+ //企业存在,生成对应的用户
|
|
|
+ Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
+ JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), corpWxUserId);
|
|
|
+ SysRole defaultRole = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
|
|
+ //成功获取到通讯录的个人详情
|
|
|
+ Long id = SnowFlake.nextId();
|
|
|
+ //通过getUserInfo接口获取到的json key是小写的
|
|
|
+ JSONArray department = userObj.getJSONArray("department");
|
|
|
+ Integer curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
+ Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
+ String userId = userObj.getString("userid");
|
|
|
+ String openUserId = userObj.getString("open_userid");
|
|
|
+ int cnt = userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", openUserId));
|
|
|
+ if (cnt == 0) {
|
|
|
+ //用户不存在
|
|
|
+ User user = new User()
|
|
|
+ .setId(id.toString())
|
|
|
+ .setRoleId(defaultRole.getId())
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
+ .setName(userObj.getString("name"))
|
|
|
+ .setPhone(userObj.getString("mobile"))
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
+ .setCorpwxUserid(openUserId)
|
|
|
+ .setCorpwxRealUserid(corpWxUserId)
|
|
|
+ .setJobNumber(openUserId.equals(userId)?null:userId)
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
+ .setCompanyId(companyId);
|
|
|
+ if (sysDept != null) {
|
|
|
+ user.setDepartmentId(sysDept.getDepartmentId());
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
+ user.setDepartmentCascade(convertDepartmentIdToCascade(user.getDepartmentId(), allDeptList));
|
|
|
+ }
|
|
|
+ userMapper.insert(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
// TODO
|
|
|
// 解密失败,失败原因请查看异常
|
|
@@ -492,7 +535,6 @@ public class WeiXinCorpController {
|
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAesKey, suitId);
|
|
|
String sMsg = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, requestBody);
|
|
|
log.info("解密后===msg: " + sMsg);
|
|
|
- // TODO: 解析出明文xml标签的内容进行处理
|
|
|
org.json.JSONObject jsonObject = XML.toJSONObject(sMsg);
|
|
|
log.info("json=="+jsonObject.toString());
|
|
|
jsonObject = jsonObject.getJSONObject("xml");
|
|
@@ -506,50 +548,7 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(jsonObject.has("Event") && ("subscribe".equals(jsonObject.getString("Event")))){
|
|
|
- //成员关注应用事件,发生在该企业已经开通应用的情况下。
|
|
|
- System.out.println("成员关注应用事件!");
|
|
|
- String corpId = jsonObject.getString("ToUserName");
|
|
|
- String corpWxUserId = jsonObject.getString("FromUserName");
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
- if (wxCorpInfo != null) {
|
|
|
- //企业存在,生成对应的用户
|
|
|
- Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
- JSONObject userObj = getUserInfo(getCorpAccessToken(wxCorpInfo), corpWxUserId);
|
|
|
- SysRole defaultRole = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
|
|
- //成功获取到通讯录的个人详情
|
|
|
- Long id = SnowFlake.nextId();
|
|
|
- //通过getUserInfo接口获取到的json key是小写的
|
|
|
- JSONArray department = userObj.getJSONArray("department");
|
|
|
- Integer curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
- Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
- String userId = userObj.getString("userid");
|
|
|
- String openUserId = userObj.getString("open_userid");
|
|
|
- int cnt = userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", openUserId));
|
|
|
- if (cnt == 0) {
|
|
|
- //用户不存在
|
|
|
- User user = new User()
|
|
|
- .setId(id.toString())
|
|
|
- .setRoleId(defaultRole.getId())
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
- .setName(userObj.getString("name"))
|
|
|
- .setPhone(userObj.getString("mobile"))
|
|
|
- .setPassword(MD5Util.getPassword("000000"))
|
|
|
- .setCorpwxUserid(openUserId)
|
|
|
- .setCorpwxRealUserid(corpWxUserId)
|
|
|
- .setJobNumber(openUserId.equals(userId)?null:userId)
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
- .setCompanyId(companyId);
|
|
|
- if (sysDept != null) {
|
|
|
- user.setDepartmentId(sysDept.getDepartmentId());
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
- user.setDepartmentCascade(convertDepartmentIdToCascade(user.getDepartmentId(), allDeptList));
|
|
|
- userMapper.insert(user);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
if (jsonObject.has("AuthCode")) {
|
|
|
//企业授权通知
|
|
|
String authCode = jsonObject.getString("AuthCode");
|
|
@@ -629,8 +628,8 @@ public class WeiXinCorpController {
|
|
|
user.setDepartmentId(sysDept.getDepartmentId());
|
|
|
List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
user.setDepartmentCascade(convertDepartmentIdToCascade(user.getDepartmentId(), allDeptList));
|
|
|
- userMapper.insert(user);
|
|
|
}
|
|
|
+ userMapper.insert(user);
|
|
|
} else if (!StringUtils.isEmpty(wxCorpInfo.getContactSecret()) && !StringUtils.isEmpty(wxCorpInfo.getContactServer())) {
|
|
|
//通过通讯录secret获取到员工姓名;这是从内部通讯录的
|
|
|
String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
@@ -2879,4 +2878,11 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping("/testMsg")
|
|
|
+ public HttpRespMsg testMsg() {
|
|
|
+ String str = "<xml><ToUserName><![CDATA[wpy9TkCAAAFDNLcpmWNM2fMegkAbjr5Q]]></ToUserName><FromUserName><![CDATA[woy9TkCAAA2g_nfDHQxJ_ipomMs9rMCQ]]></FromUserName><CreateTime>1667874192</CreateTime><MsgType><![CDATA[event]]></MsgType><AgentID>1000057</AgentID><Event><![CDATA[subscribe]]></Event></xml>";
|
|
|
+
|
|
|
+ return new HttpRespMsg();
|
|
|
+ }
|
|
|
}
|