| | |
| | | import cn.flightfeather.supervision.domain.entity.UserInfoWx |
| | | import cn.flightfeather.supervision.domain.entity.Userinfo |
| | | import cn.flightfeather.supervision.domain.mapper.* |
| | | import cn.flightfeather.supervision.domain.repository.UserInfoRep |
| | | import cn.flightfeather.supervision.lightshare.service.WxUserService |
| | | import cn.flightfeather.supervision.lightshare.vo.AccessToken |
| | | import cn.flightfeather.supervision.lightshare.vo.AccessTokenPW |
| | | import cn.flightfeather.supervision.lightshare.vo.AccessTokenWX |
| | | import cn.flightfeather.supervision.lightshare.vo.BaseResponse |
| | | import cn.flightfeather.supervision.bgtask.sysnotice.SysNoticeManager |
| | | import com.alibaba.fastjson.JSON |
| | | import com.alibaba.fastjson.JSONArray |
| | | import com.alibaba.fastjson.JSONObject |
| | |
| | | val userMapMapper: UserMapMapper, |
| | | val baseInfoMapper: BaseInfoMapper, |
| | | private val msgSubscribeWxMapper: MsgSubscribeWxMapper, |
| | | private val logMsgSubscribeWxMapper: LogMsgSubscribeWxMapper |
| | | private val logMsgSubscribeWxMapper: LogMsgSubscribeWxMapper, |
| | | private val sysNoticeManager: SysNoticeManager, |
| | | private val userInfoRep: UserInfoRep |
| | | ): WxUserService { |
| | | |
| | | private val LOGGER = LoggerFactory.getLogger(WxUserServiceImpl::class.java) |
| | |
| | | } |
| | | } else { |
| | | if (user.uiGuid != null) { |
| | | userInfoRep.loginLog(user.uiGuid) |
| | | val userinfo = userinfoMapper.selectByPrimaryKey(user.uiGuid) |
| | | BaseResponse(true, "微信用户登录成功", data = userinfo) |
| | | } else { |
| | |
| | | val result = AccessToken() |
| | | //1.1 微信id为空,直接登录; 微信id不为空,绑定至账号 |
| | | if (!accessTokenPW.code.isNullOrBlank()) { |
| | | val baseInfo = baseInfoMapper.selectByPrimaryKey(user[0].guid) |
| | | val baseInfo = baseInfoMapper.selectByPrimaryKey(user[0]?.guid) |
| | | WXHttpService.code2Session(accessTokenPW.code!!)?.let { |
| | | val openid = it.first |
| | | val unionid = it.second |
| | |
| | | result.openId = openid |
| | | return@let if (userWx == null || userWx.uiOpenId == null) { |
| | | val newUserWx = UserInfoWx().apply { |
| | | uiGuid = user[0].guid |
| | | uiGuid = user[0]?.guid |
| | | ciGuid = baseInfo?.ciGuid |
| | | uiOpenId = openid |
| | | uiNickName = accessTokenPW.nickName |
| | |
| | | uiUnionid = unionid |
| | | } |
| | | userInfoWxMapper.insert(newUserWx) |
| | | } else if (userWx.uiGuid != user[0].guid) { |
| | | userWx.uiGuid = user[0].guid |
| | | } else if (userWx.uiGuid != user[0]?.guid) { |
| | | userWx.uiGuid = user[0]?.guid |
| | | userWx.ciGuid = baseInfo?.ciGuid |
| | | userInfoWxMapper.updateByPrimaryKey(userWx) |
| | | } else { |
| | |
| | | } |
| | | } |
| | | } |
| | | val u = user[0] |
| | | u?.uiLoginTime = Date() |
| | | userinfoMapper.updateByPrimaryKeySelective(u) |
| | | userInfoRep.loginLog(u?.guid) |
| | | return result.apply { |
| | | userId = user[0].guid |
| | | userId = user[0]?.guid |
| | | val sUser = userMapMapper.selectByPrimaryKey(userId) |
| | | sUserId = sUser?.svUserId |
| | | success = true |
| | |
| | | AccessToken() |
| | | } else { |
| | | val user = userinfoMapper.selectByPrimaryKey(userWx.uiGuid) |
| | | user?.uiLoginTime = Date() |
| | | userinfoMapper.updateByPrimaryKeySelective(user) |
| | | userInfoRep.loginLog(user?.guid) |
| | | AccessToken().apply { |
| | | if (user?.guid == null) { |
| | | success = false |
| | |
| | | //用户openid |
| | | val openId = (json["FromUserName"] as String?) ?: throw NullPointerException("微信服务器发送的订阅返回消息FromUserName字段为null") |
| | | //时间戳 |
| | | val createTime = (json["CreateTime"] as Int?) ?: throw NullPointerException("微信服务器发送的订阅返回消息CreateTime字段为null") |
| | | var createTime = (json["CreateTime"] as Int?)?.toLong() ?: throw NullPointerException("微信服务器发送的订阅返回消息CreateTime字段为null") |
| | | createTime = createTime.times(1000)//此处传过来的时间戳只精确到秒,转换为毫秒 |
| | | //事件类型,此处应该都是event |
| | | val msgType = json["MsgType"] as String? |
| | | |
| | |
| | | val templateId = it["TemplateId"] as String? |
| | | val sStatus = it["SubscribeStatusString"] as String? |
| | | //根据时间和用户openId,判断此次操作是否重复 |
| | | val time = Date(createTime.toLong() * 1000) |
| | | val time = Date(createTime.toLong()) |
| | | val records = msgSubscribeWxMapper.selectByExample(Example(MsgSubscribeWx::class.java).apply { |
| | | createCriteria().andEqualTo("msOpenId", openId) |
| | | .andEqualTo("msTemplateId", templateId) |