|
@@ -491,9 +491,49 @@ public class WeiXinCorpController {
|
|
org.json.JSONObject jsonObject = XML.toJSONObject(sMsg);
|
|
org.json.JSONObject jsonObject = XML.toJSONObject(sMsg);
|
|
log.info("json=="+jsonObject.toString());
|
|
log.info("json=="+jsonObject.toString());
|
|
jsonObject = jsonObject.getJSONObject("xml");
|
|
jsonObject = jsonObject.getJSONObject("xml");
|
|
- if(jsonObject.has("Event") && ("open_approval_change".equals(jsonObject.getString("Event")))){
|
|
|
|
- //审批状态回调通知
|
|
|
|
- System.out.println("审批状态回调通知!");
|
|
|
|
|
|
+ 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")) {
|
|
if (jsonObject.has("AuthCode")) {
|
|
//企业授权通知
|
|
//企业授权通知
|