package cn.flightfeather.supervision.lightshare.service.Impl
|
|
import cn.flightfeather.supervision.common.net.WXHttpService
|
import cn.flightfeather.supervision.domain.entity.UserInfoWx
|
import cn.flightfeather.supervision.domain.entity.Userinfo
|
import cn.flightfeather.supervision.domain.entity.Version
|
import cn.flightfeather.supervision.domain.enumeration.UserType
|
import cn.flightfeather.supervision.domain.mapper.UserInfoWxMapper
|
import cn.flightfeather.supervision.domain.mapper.UserinfoMapper
|
import cn.flightfeather.supervision.domain.mapper.VersionMapper
|
import cn.flightfeather.supervision.infrastructure.utils.FileUtil
|
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
|
import cn.flightfeather.supervision.lightshare.service.VersionService
|
import cn.flightfeather.supervision.lightshare.service.WxUserService
|
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.lightshare.vo.VersionVo
|
import com.alibaba.fastjson.JSONObject
|
import org.springframework.stereotype.Service
|
import org.springframework.web.multipart.MultipartFile
|
import tk.mybatis.mapper.entity.Example
|
|
@Service
|
class WxUserServiceImpl(val userinfoMapper: UserinfoMapper, val userInfoWxMapper: UserInfoWxMapper): WxUserService {
|
|
override fun loginWx(accessTokenWX: AccessTokenWX): BaseResponse<Userinfo> {
|
accessTokenWX.code ?: return BaseResponse(false, "登录凭证不能为空")
|
|
val res = WXHttpService.code2Session(accessTokenWX.code!!)
|
|
// return BaseResponse(false)
|
if (res.success) {
|
val json = JSONObject.parseObject(res.m.responseBodyAsString)
|
if (json["errcode"] == 0 || json["errcode"] == null) {
|
val openid = json["openid"] as String
|
val unionid = json["unionid"] as String
|
val user = userInfoWxMapper.selectByPrimaryKey(openid)
|
return if (user.uiOpenId == null) {
|
val newUserWx = UserInfoWx().apply {
|
// uiGuid = UUIDGenerator.generate16ShortUUID()
|
uiOpenId = openid
|
uiNickName = accessTokenWX.nickName
|
uiGender
|
uiCountry
|
uiProvince
|
uiCity
|
uiAvatarUrl = accessTokenWX.avatarUrl
|
uiUnionid = unionid
|
}
|
// val newUser = Userinfo().apply {
|
// guid = newUserWx.uiGuid
|
// headIconUrl = newUserWx.uiAvatarUrl
|
// acountname
|
// realname = newUserWx.uiNickName
|
// password
|
// usertypeid = UserType.Enterprise.value.toByte()
|
// usertype = UserType.Enterprise.des
|
// isenable = true
|
// wechatid = newUserWx.uiOpenId
|
// }
|
var r = userInfoWxMapper.insert(newUserWx)
|
// r += userinfoMapper.insert(newUser)
|
return if (r == 1) {
|
BaseResponse(true, "微信用户注册成功")
|
} else {
|
BaseResponse(false, "微信用户注册失败")
|
}
|
} else {
|
if (user.uiGuid != null) {
|
val userinfo = userinfoMapper.selectByPrimaryKey(user.uiGuid)
|
BaseResponse(true, "微信用户登录成功", data = userinfo)
|
} else {
|
BaseResponse(true, "微信用户未绑定企业")
|
}
|
}
|
} else {
|
return BaseResponse(false, "请求失败:errcode=${json["errcode"]}")
|
}
|
} else {
|
return BaseResponse(false, "请求失败, 无法访问微信接口")
|
}
|
}
|
|
override fun loginPw(accessTokenPW: AccessTokenPW): BaseResponse<Userinfo> {
|
TODO("Not yet implemented")
|
}
|
}
|