Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
appApi
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
antaile
appApi
Commits
12ac5402
Commit
12ac5402
authored
Aug 17, 2021
by
XiaHou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
云应用相关的业务代码
parent
a912e556
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
272 additions
and
25 deletions
+272
-25
AppleController.java
...java/com/hwstudio/antaile/controller/AppleController.java
+38
-0
AppleInsertUserParam.java
...n/java/com/hwstudio/antaile/dto/AppleInsertUserParam.java
+25
-0
AppleLoginDTO.java
src/main/java/com/hwstudio/antaile/dto/AppleLoginDTO.java
+32
-0
LoginUserDto.java
src/main/java/com/hwstudio/antaile/dto/LoginUserDto.java
+2
-0
AtlUser.java
src/main/java/com/hwstudio/antaile/entity/AtlUser.java
+4
-1
AtlUserMapper.java
src/main/java/com/hwstudio/antaile/mapper/AtlUserMapper.java
+2
-0
AtlAppleService.java
...in/java/com/hwstudio/antaile/service/AtlAppleService.java
+142
-0
AtlTimeOwnerService.java
...ava/com/hwstudio/antaile/service/AtlTimeOwnerService.java
+5
-6
AppleUtil.java
src/main/java/com/hwstudio/antaile/utils/AppleUtil.java
+17
-18
LoginUserVo.java
src/main/java/com/hwstudio/antaile/vo/LoginUserVo.java
+1
-0
AtlUserMapper.xml
src/main/resources/mapping/AtlUserMapper.xml
+4
-0
No files found.
src/main/java/com/hwstudio/antaile/controller/AppleController.java
0 → 100644
View file @
12ac5402
package
com
.
hwstudio
.
antaile
.
controller
;
import
com.hwstudio.antaile.dto.AppleInsertUserParam
;
import
com.hwstudio.antaile.service.AtlAppleService
;
import
com.hwstudio.antaile.utils.JsonResult
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* @Name:
* @Author: Lijc
* @Date: 2019/8/19 15:26
* @Version 1.0
*/
@RestController
@RequestMapping
(
"/apple"
)
@Api
(
tags
=
"苹果三方相关接口"
)
public
class
AppleController
extends
BaseController
{
@Autowired
private
AtlAppleService
atlAppleService
;
@ApiOperation
(
"苹果identityToken登录"
)
@RequestMapping
(
value
=
"/parseIdentityToken"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
JsonResult
parseIdentityToken
(
@ApiParam
(
value
=
"苹果identityToken"
,
required
=
true
)
@RequestParam
(
value
=
"identityToken"
,
required
=
true
)
String
identityToken
)
{
return
atlAppleService
.
identityTokenLogin
(
identityToken
);
}
@RequestMapping
(
value
=
"appleInsertUserParam"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
" 苹果绑定sub 和手机号登录"
)
public
JsonResult
appleInsertUserParam
(
@ApiParam
(
value
=
"传入对象"
)
@RequestBody
AppleInsertUserParam
appleInsertUserParam
)
{
return
this
.
atlAppleService
.
appleInsertUserParam
(
appleInsertUserParam
);
}
}
src/main/java/com/hwstudio/antaile/dto/AppleInsertUserParam.java
0 → 100644
View file @
12ac5402
package
com
.
hwstudio
.
antaile
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @Author xh
* @Date 2021/8/17
* description:
*/
@Data
public
class
AppleInsertUserParam
implements
Serializable
{
@ApiModelProperty
(
value
=
"苹果sub"
)
private
String
appleSub
;
@ApiModelProperty
(
value
=
"用户手机号"
)
private
String
mobilePhone
;
@ApiModelProperty
(
value
=
"登录密码"
)
private
String
loginPassword
;
@ApiModelProperty
(
value
=
"验证码"
)
private
String
verifyCode
;
}
src/main/java/com/hwstudio/antaile/dto/AppleLoginDTO.java
0 → 100644
View file @
12ac5402
package
com
.
hwstudio
.
antaile
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @Author xh
* @Date 2021/8/17
* description:
*/
@Data
public
class
AppleLoginDTO
implements
Serializable
{
@ApiModelProperty
(
value
=
"签发机构网址"
)
private
String
iss
;
@ApiModelProperty
(
value
=
"bundle id"
)
private
String
aud
;
@ApiModelProperty
(
value
=
"过期时间戳"
)
private
Long
exp
;
@ApiModelProperty
(
value
=
"签发时间"
)
private
Long
iat
;
@ApiModelProperty
(
value
=
"苹果userId 类似于微信Openid"
)
private
String
sub
;
@ApiModelProperty
(
value
=
"客户端发出请求时携带的随机串,用于对照"
)
private
String
nonce
;
@ApiModelProperty
(
value
=
"邮箱"
)
private
String
email
;
}
src/main/java/com/hwstudio/antaile/dto/LoginUserDto.java
View file @
12ac5402
...
...
@@ -46,4 +46,6 @@ public class LoginUserDto {
private
String
officeOpenId
;
@ApiModelProperty
(
value
=
"微信unionid"
)
private
String
unionid
;
@ApiModelProperty
(
value
=
"苹果sub"
)
private
String
appleSub
;
}
src/main/java/com/hwstudio/antaile/entity/AtlUser.java
View file @
12ac5402
...
...
@@ -7,7 +7,7 @@ import java.io.Serializable;
import
java.util.Date
;
@Data
public
class
AtlUser
implements
Serializable
{
public
class
AtlUser
implements
Serializable
{
@ApiModelProperty
(
value
=
"用户id"
)
private
Long
id
;
@ApiModelProperty
(
value
=
"昵称"
)
...
...
@@ -70,4 +70,6 @@ public class AtlUser implements Serializable{
private
Long
fromTimeid
;
@ApiModelProperty
(
value
=
"推荐人ID(用于用户邀请注册使用)"
)
private
Long
fromUserid
;
@ApiModelProperty
(
value
=
"苹果sub 类似于微信登录OpenId"
)
private
String
appleSub
;
}
\ No newline at end of file
src/main/java/com/hwstudio/antaile/mapper/AtlUserMapper.java
View file @
12ac5402
...
...
@@ -36,6 +36,8 @@ public interface AtlUserMapper {
AtlUser
getByUnionid
(
String
unionid
);
AtlUser
getByAppleSub
(
String
appleSub
);
void
updatePwd
(
@Param
(
"pwd"
)
String
pwd
,
@Param
(
"userId"
)
Long
userId
);
void
insert
(
AtlUser
atlUser
);
...
...
src/main/java/com/hwstudio/antaile/service/AtlAppleService.java
0 → 100644
View file @
12ac5402
package
com
.
hwstudio
.
antaile
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.hwstudio.antaile.common.BeanUtils
;
import
com.hwstudio.antaile.common.Constants
;
import
com.hwstudio.antaile.dto.AppleInsertUserParam
;
import
com.hwstudio.antaile.dto.AppleLoginDTO
;
import
com.hwstudio.antaile.dto.LoginUserDto
;
import
com.hwstudio.antaile.dto.WxInsertUserParam
;
import
com.hwstudio.antaile.entity.AtlUser
;
import
com.hwstudio.antaile.entity.Sms
;
import
com.hwstudio.antaile.exception.BusinessException
;
import
com.hwstudio.antaile.mapper.AtlUserMapper
;
import
com.hwstudio.antaile.mapper.SmsMapper
;
import
com.hwstudio.antaile.utils.AppleUtil
;
import
com.hwstudio.antaile.utils.JsonResult
;
import
com.hwstudio.antaile.utils.RedisUtil
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.UUID
;
/**
* @Author xh
* @Date 2021/8/17
* description:
*/
@Service
public
class
AtlAppleService
{
@Resource
private
AtlUserMapper
atlUserMapper
;
@Resource
private
RedisUtil
redisUtil
;
@Resource
private
SmsMapper
smsMapper
;
/**
* 通过identityToken解析 查询登录
*
* @param identityToken
* @return
*/
public
JsonResult
identityTokenLogin
(
String
identityToken
)
{
JSONObject
object
=
AppleUtil
.
parserIdentityToken
(
identityToken
);
AppleLoginDTO
appleLoginDTO
=
object
.
toJavaObject
(
AppleLoginDTO
.
class
);
if
(
appleLoginDTO
==
null
)
{
return
JsonResult
.
failed
(
"获取apple Sub异常"
);
}
if
(
appleLoginDTO
.
getSub
()
==
null
||
appleLoginDTO
.
getSub
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入苹果token有误,获取sub失败"
);
}
AtlUser
atlUser
=
atlUserMapper
.
getByAppleSub
(
appleLoginDTO
.
getSub
());
if
(
atlUser
==
null
)
{
return
JsonResult
.
failed
(
"需要绑定手机号"
,
appleLoginDTO
);
}
else
{
//否则有查询到 就登录成功
LoginUserDto
loginUserDto
=
new
LoginUserDto
();
String
token
=
UUID
.
randomUUID
().
toString
();
redisUtil
.
set
(
token
,
atlUser
,
Long
.
valueOf
(
604800
));
loginUserDto
.
setToken
(
token
);
loginUserDto
.
setAvatarUrl
(
atlUser
.
getAvaterImageUrl
());
loginUserDto
.
setNickName
(
atlUser
.
getNickName
());
loginUserDto
.
setPhone
(
atlUser
.
getMobilePhone
());
loginUserDto
.
setUserId
(
atlUser
.
getId
());
loginUserDto
.
setAppleSub
(
atlUser
.
getAppleSub
());
return
JsonResult
.
success
(
"登录成功"
,
loginUserDto
);
}
}
/**
* 苹果绑定sub 和手机号登录
*
* @param appleInsertUserParam
* @return
*/
public
JsonResult
appleInsertUserParam
(
AppleInsertUserParam
appleInsertUserParam
)
{
JsonResult
res
=
this
.
checkAppleInsertUserParam
(
appleInsertUserParam
);
if
(
res
.
getStatus
().
equals
(
Constants
.
RESPONSE_STATUS_500
))
{
return
res
;
}
AtlUser
atlUser
=
atlUserMapper
.
getByAppleSub
(
appleInsertUserParam
.
getAppleSub
());
AtlUser
insertAtlUser
=
new
AtlUser
();
if
(
atlUser
!=
null
)
{
atlUser
.
setState
(
1
);
atlUser
.
setMobilePhone
(
appleInsertUserParam
.
getMobilePhone
());
atlUser
.
setLoginPassword
(
DigestUtils
.
md5Hex
(
appleInsertUserParam
.
getLoginPassword
()));
atlUser
.
setAppleSub
(
appleInsertUserParam
.
getAppleSub
());
this
.
atlUserMapper
.
updateUser
(
atlUser
);
//赋值给insertAtlUser对象
BeanUtils
.
copyProperties
(
atlUser
,
insertAtlUser
);
}
else
{
String
nickName
=
appleInsertUserParam
.
getMobilePhone
().
substring
(
0
,
3
)
+
"****"
+
appleInsertUserParam
.
getMobilePhone
().
substring
(
7
,
appleInsertUserParam
.
getMobilePhone
().
length
());;
insertAtlUser
.
setAvaterImageUrl
(
nickName
);
insertAtlUser
.
setState
(
1
);
insertAtlUser
.
setMobilePhone
(
appleInsertUserParam
.
getMobilePhone
());
insertAtlUser
.
setLoginPassword
(
DigestUtils
.
md5Hex
(
appleInsertUserParam
.
getLoginPassword
()));
insertAtlUser
.
setAppleSub
(
appleInsertUserParam
.
getAppleSub
());
insertAtlUser
.
setLoginDate
(
new
Date
());
this
.
atlUserMapper
.
insert
(
insertAtlUser
);
}
//返回对象数据
LoginUserDto
loginUserDto
=
new
LoginUserDto
();
String
token
=
UUID
.
randomUUID
().
toString
();
redisUtil
.
set
(
token
,
insertAtlUser
,
Long
.
valueOf
(
604800
));
loginUserDto
.
setToken
(
token
);
loginUserDto
.
setAvatarUrl
(
insertAtlUser
.
getAvaterImageUrl
());
loginUserDto
.
setNickName
(
insertAtlUser
.
getNickName
());
loginUserDto
.
setPhone
(
insertAtlUser
.
getMobilePhone
());
loginUserDto
.
setWebappOpenId
(
insertAtlUser
.
getOpenId
());
loginUserDto
.
setUserId
(
insertAtlUser
.
getId
());
loginUserDto
.
setAppleSub
(
appleInsertUserParam
.
getAppleSub
());
return
JsonResult
.
success
(
"绑定手机号登录成功"
,
loginUserDto
);
}
/**
* 校验传入参数
*
* @param appleInsertUserParam
* @return
*/
private
JsonResult
checkAppleInsertUserParam
(
AppleInsertUserParam
appleInsertUserParam
)
{
if
(
appleInsertUserParam
.
getAppleSub
()
==
null
||
appleInsertUserParam
.
getAppleSub
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入苹果sub为空"
);
}
if
(
appleInsertUserParam
.
getMobilePhone
()
==
null
||
appleInsertUserParam
.
getMobilePhone
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入mobilePhone为空"
);
}
if
(
appleInsertUserParam
.
getVerifyCode
()
==
null
||
appleInsertUserParam
.
getVerifyCode
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入验证码为空"
);
}
else
{
Sms
sms
=
smsMapper
.
getSmsVerifyCode
(
appleInsertUserParam
.
getMobilePhone
(),
appleInsertUserParam
.
getVerifyCode
(),
5
);
if
(
sms
==
null
)
{
throw
new
BusinessException
(
"验证码错误"
);
}
}
return
JsonResult
.
success
(
"校验通过"
);
}
}
src/main/java/com/hwstudio/antaile/service/AtlTimeOwnerService.java
View file @
12ac5402
...
...
@@ -14,7 +14,6 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -94,8 +93,8 @@ public class AtlTimeOwnerService {
map
.
put
(
"identity"
,
"隐私"
);
}
boolean
birthDate
=
false
;
if
(
jsonObject
.
get
(
"birthDate"
)
!=
null
)
{
birthDate
=
(
boolean
)
jsonObject
.
get
(
"birthDate"
)
;
if
(
jsonObject
.
get
(
"birthDate"
)
!=
null
)
{
birthDate
=
(
boolean
)
jsonObject
.
get
(
"birthDate"
)
;
}
if
(
birthDate
)
{
map
.
put
(
"birthDate"
,
atlTimeOwnerDto
.
getBirthdate
());
...
...
@@ -149,7 +148,7 @@ public class AtlTimeOwnerService {
map
.
put
(
"profile"
,
atlTimeOwnerDto
.
getProfile
());
}
map
.
put
(
"livingState"
,
atlTimeOwnerDto
.
getLivingState
());
if
(
"1"
.
equals
(
atlTimeOwnerDto
.
getLivingState
()+
""
))
{
if
(
"1"
.
equals
(
atlTimeOwnerDto
.
getLivingState
()
+
""
))
{
map
.
put
(
"deathdate"
,
atlTimeOwnerDto
.
getDeathdate
());
map
.
put
(
"deathDateEnd"
,
atlTimeOwnerDto
.
getDeathDateEnd
());
}
...
...
@@ -247,10 +246,10 @@ public class AtlTimeOwnerService {
for
(
AtlTimeTimemark
atlTimeTimemark
:
atlTimeTimemarks
)
{
Map
<
String
,
Object
>
timemark
=
new
HashMap
<>();
timemark
.
put
(
"id"
,
atlTimeTimemark
.
getId
());
if
(
1
==
type
)
{
if
(
1
==
type
)
{
timemark
.
put
(
"startTime"
,
atlTimeTimemark
.
getStartTimeStr
());
timemark
.
put
(
"endTime"
,
atlTimeTimemark
.
getEndTimeStr
());
}
else
{
}
else
{
timemark
.
put
(
"startTime"
,
atlTimeTimemark
.
getStartTime
());
timemark
.
put
(
"endTime"
,
atlTimeTimemark
.
getEndTime
());
}
...
...
src/main/java/com/hwstudio/antaile/utils/AppleUtil.java
View file @
12ac5402
...
...
@@ -7,12 +7,10 @@ import com.auth0.jwk.Jwk;
import
io.jsonwebtoken.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.tomcat.util.codec.binary.Base64
;
import
org.junit.Test
;
import
org.springframework.web.client.RestTemplate
;
import
java.nio.charset.StandardCharsets
;
import
java.security.PublicKey
;
import
java.util.stream.Collectors
;
/**
* @Author xh
...
...
@@ -35,19 +33,20 @@ public class AppleUtil {
return
arr
;
}
@Test
public
void
test1
()
{
String
identityToken
=
"eyJraWQiOiJlWGF1bm1MIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLmRpeWl5aW4ub25saW5lNTMiLCJleHAiOjE1OTc2NTAxNzQsImlhdCI6MTU5NzY0OTU3NCwic3ViIjoiMDAxMzc3LmQ0ZDVmMTAwODQ0ZTQzZjdiMWM1OWRiMzUyZWZkZmI4LjAyNTkiLCJjX2hhc2giOiJkTDVRdld2VTNjVHBxczNSazlUTnRBIiwiZW1haWwiOiI0OTk4OTY1MDdAcXEuY29tIiwiZW1haWxfdmVyaWZpZWQiOiJ0cnVlIiwiYXV0aF90aW1lIjoxNTk3NjQ5NTc0LCJub25jZV9zdXBwb3J0ZWQiOnRydWV9.hM9HjNsMJW2PjYP7SfbzF-GqOt0VnMjYGq4BoU68rkQ-K2lPp_ae5ziX6Bbr3WHg6cc3Z8OzGO63OfExvSj9gQTR596CZLvNGXhbI3piTK6597-cYsPCTbY7xHxgdHLuL8XhD-9dXPn9rouVYu4QA18JBQG1Q4sGsRzLEJ5DjOM9x1bkBz4Vu_5LEOefHFHkWN_RPCh_AOJGviDzm81kTkCTWn8jpm0tGdevMR93MOf44f7bjP2T8yezl0Vbv09TrnkdAqG0BsihCD0VN9JV7X2eagyumoxTdFfoRiOflFKAaQqohVzcqy9tHOGm_6w5h8bsRCmtBC4PnqIFqNy_AQ"
;
/**
* 解析苹果token
*
* @param identityToken
* @return 返回解析对象
*/
public
JSONObject
parseIdentityToken
(
String
identityToken
)
{
boolean
flag
=
this
.
verify
(
identityToken
);
String
str1
=
new
String
(
Base64
.
decodeBase64
(
identityToken
),
StandardCharsets
.
UTF_8
);
String
objStr
=
str1
.
substring
(
str1
.
indexOf
(
"{"
)+
1
,
str1
.
indexOf
(
"}"
));
str1
=
"{"
+
objStr
+
"}"
;
String
objStr
=
str1
.
substring
(
str1
.
indexOf
(
"{"
)
+
1
,
str1
.
indexOf
(
"}"
));
str1
=
"{"
+
objStr
+
"}"
;
JSONObject
str1Json
=
JSON
.
parseObject
(
str1
);
String
kid
=
str1Json
.
get
(
"kid"
)
+
""
;
String
kid
=
str1Json
.
get
(
"kid"
)
+
""
;
System
.
out
.
println
(
str1
);
String
url
=
"https://appleid.apple.com/auth/keys"
;
...
...
@@ -56,23 +55,23 @@ public class AppleUtil {
JSONArray
arrKeys
=
json
.
getJSONArray
(
"keys"
);
String
authKey
=
""
;
Object
choose
=
null
;
for
(
Object
item
:
arrKeys
){
JSONObject
str2Json
=
JSON
.
parseObject
(
item
+
""
);
String
kidKey
=
str2Json
.
get
(
"kid"
)
+
""
;
if
(
kid
.
equals
(
kidKey
))
{
authKey
=
str2Json
.
get
(
"n"
)
+
""
;
for
(
Object
item
:
arrKeys
)
{
JSONObject
str2Json
=
JSON
.
parseObject
(
item
+
""
);
String
kidKey
=
str2Json
.
get
(
"kid"
)
+
""
;
if
(
kid
.
equals
(
kidKey
))
{
authKey
=
str2Json
.
get
(
"n"
)
+
""
;
choose
=
item
;
}
}
boolean
flag2
=
this
.
verifyExc
(
identityToken
,
JSON
.
parseObject
(
choose
+
""
)
);
boolean
flag2
=
this
.
verifyExc
(
identityToken
,
JSON
.
parseObject
(
choose
+
""
)
);
String
[]
arr
=
identityToken
.
split
(
"\\."
);
String
decode
=
new
String
(
Base64
.
decodeBase64
(
arr
[
1
]));
String
substring
=
decode
.
substring
(
0
,
decode
.
indexOf
(
"}"
)
+
1
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
substring
);
System
.
out
.
println
(
jsonObject
);
return
jsonObject
;
}
public
Boolean
verify
(
String
jwt
)
{
...
...
src/main/java/com/hwstudio/antaile/vo/LoginUserVo.java
View file @
12ac5402
...
...
@@ -52,4 +52,5 @@ public class LoginUserVo {
@ApiModelProperty
(
value
=
"是否小程序登陆"
)
private
String
isApplet
;
}
src/main/resources/mapping/AtlUserMapper.xml
View file @
12ac5402
...
...
@@ -156,6 +156,10 @@
SELECT * FROM atl_user WHERE unionid = #{unionid}
</select>
<select
id=
"getByAppleSub"
resultType=
"com.hwstudio.antaile.entity.AtlUser"
parameterType=
"java.lang.String"
>
SELECT * FROM atl_user WHERE apple_sub = #{appleSub}
</select>
<update
id=
"updatePwd"
>
UPDATE atl_user SET
login_password = #{pwd}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment