Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beijing-vehicleflow
Project
Project
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
zhangzhenbang
beijing-vehicleflow
Commits
8e33252f
Commit
8e33252f
authored
Feb 24, 2020
by
zhangzhenbang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
试探性写了一两个接口
parent
00b54e79
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
223 additions
and
5 deletions
+223
-5
pom.xml
pom.xml
+7
-0
IdentityInfoController.java
...beijingvehicleflow/controller/IdentityInfoController.java
+98
-0
ReservationController.java
.../beijingvehicleflow/controller/ReservationController.java
+0
-1
IdentityInformationMapper.java
.../beijingvehicleflow/mapper/IdentityInformationMapper.java
+4
-4
IdentityInformationService.java
...eijingvehicleflow/service/IdentityInformationService.java
+6
-0
IdentityInformationServiceImpl.java
...icleflow/service/impl/IdentityInformationServiceImpl.java
+55
-0
AESUtil.java
...ain/java/com/yingxin/beijingvehicleflow/util/AESUtil.java
+53
-0
No files found.
pom.xml
View file @
8e33252f
...
@@ -112,6 +112,13 @@
...
@@ -112,6 +112,13 @@
<artifactId>
lombok
</artifactId>
<artifactId>
lombok
</artifactId>
</dependency>
</dependency>
<!-- AES-128-CBC加解密包 -->
<dependency>
<groupId>
org.bouncycastle
</groupId>
<artifactId>
bcprov-jdk16
</artifactId>
<version>
1.46
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/yingxin/beijingvehicleflow/controller/IdentityInfoController.java
0 → 100644
View file @
8e33252f
package
com
.
yingxin
.
beijingvehicleflow
.
controller
;
import
com.yingxin.beijingvehicleflow.entity.IdentityInformation
;
import
com.yingxin.beijingvehicleflow.response.Response
;
import
com.yingxin.beijingvehicleflow.service.IdentityInformationService
;
import
com.yingxin.beijingvehicleflow.util.AESUtil
;
import
net.sf.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/24
*/
@RestController
@CrossOrigin
@RequestMapping
(
"/api/v1"
)
public
class
IdentityInfoController
{
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IdentityInfoController
.
class
);
@Autowired
private
IdentityInformationService
identityInformationService
;
/**
* 根据tempCode去获取openId,然后在数据库中查看是否有与其相同的openId
*
* @date 2020/2/21
* @param json {"code":""}
* @return com.yingxin.covid19prevention.response.Response
*/
@PostMapping
(
"/resident/exist/state"
)
public
Response
isResidentExist
(
@RequestBody
String
json
)
{
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
json
);
JSONObject
jsonAfterLogin
=
identityInformationService
.
getwechatInfoByTempCode
(
jsonObject
.
getString
(
"code"
));
IdentityInformation
info
=
identityInformationService
.
getAllInfoByOpenid
(
jsonAfterLogin
.
getString
(
"openid"
));
if
(
info
==
null
)
{
return
Response
.
fail
();
}
return
new
Response
<
IdentityInformation
>(
true
,
""
,
""
,
info
);
}
/**
* 将获取到的加密手机号进行解密,将解密的手机号和获取到的openId一起存到用户表中,
*
* @date 2020/2/21
* @param json code、iv、encryptedData
* @return com.yingxin.covid19prevention.response.Response userId
*/
@PostMapping
(
"/resident/wechat"
)
public
Response
getDecryptData
(
@RequestBody
String
json
)
{
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
json
);
String
tempCode
=
jsonObject
.
getString
(
"code"
);
String
iv
=
jsonObject
.
getString
(
"iv"
);
String
encryptedData
=
jsonObject
.
getString
(
"encryptedData"
);
JSONObject
loginJson
=
identityInformationService
.
getwechatInfoByTempCode
(
tempCode
);
String
sessionKey
=
loginJson
.
getString
(
"session_key"
);
String
result
;
try
{
result
=
AESUtil
.
decryptForWeChatApplet
(
encryptedData
,
sessionKey
,
iv
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"获取微信手机号码解密异常:"
,
e
);
return
Response
.
fail
(
"Decrypt-ERROR"
,
"获取微信手机号码解密异常"
);
}
JSONObject
wechatJson
;
String
weChatPhone
;
String
openid
;
try
{
wechatJson
=
JSONObject
.
fromObject
(
result
);
weChatPhone
=
wechatJson
.
getString
(
"phoneNumber"
);
openid
=
loginJson
.
getString
(
"openid"
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"解密结果json解析异常"
,
e
);
return
Response
.
fail
(
"JSON-PARSE-ERROR"
,
"解密结果json解析异常"
);
}
IdentityInformation
info
=
new
IdentityInformation
();
info
.
setWechatPhone
(
weChatPhone
);
info
.
setWechatOpenid
(
openid
);
int
resultAfterInsert
=
identityInformationService
.
insertIdentityInfo
(
info
);
if
(
resultAfterInsert
>
0
)
{
return
new
Response
<
Integer
>(
true
,
""
,
""
,
resultAfterInsert
);
}
return
Response
.
fail
();
}
}
src/main/java/com/yingxin/beijingvehicleflow/controller/ReservationController.java
View file @
8e33252f
...
@@ -23,7 +23,6 @@ public class ReservationController {
...
@@ -23,7 +23,6 @@ public class ReservationController {
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ReservationController
.
class
);
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ReservationController
.
class
);
@Autowired
@Autowired
private
ReservationService
reservationService
;
private
ReservationService
reservationService
;
...
...
src/main/java/com/yingxin/beijingvehicleflow/mapper/IdentityInformationMapper.java
View file @
8e33252f
package
com
.
yingxin
.
beijingvehicleflow
.
mapper
;
package
com
.
yingxin
.
beijingvehicleflow
.
mapper
;
import
com.yingxin.beijingvehicleflow.entity.IdentityInformation
;
import
com.yingxin.beijingvehicleflow.entity.IdentityInformation
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.*
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Options
;
import
org.apache.ibatis.annotations.Update
;
/**
/**
* 数据库表单对应Mapper
* 数据库表单对应Mapper
...
@@ -39,4 +36,7 @@ public interface IdentityInformationMapper {
...
@@ -39,4 +36,7 @@ public interface IdentityInformationMapper {
"phone_number=#{phoneNumber},face_image=#{faceImage},toBeijing_date=#{toBeijingDate},"
+
"phone_number=#{phoneNumber},face_image=#{faceImage},toBeijing_date=#{toBeijingDate},"
+
"is_worker=#{isWorker} where id =#{id}"
)
"is_worker=#{isWorker} where id =#{id}"
)
int
updateIdentityInfo
(
IdentityInformation
identityInformation
);
int
updateIdentityInfo
(
IdentityInformation
identityInformation
);
@Select
(
"select * from identity_information where openid = #{openid}"
)
IdentityInformation
getAllInfoByOpenid
(
String
openid
);
}
}
src/main/java/com/yingxin/beijingvehicleflow/service/IdentityInformationService.java
View file @
8e33252f
package
com
.
yingxin
.
beijingvehicleflow
.
service
;
package
com
.
yingxin
.
beijingvehicleflow
.
service
;
import
com.yingxin.beijingvehicleflow.entity.IdentityInformation
;
import
com.yingxin.beijingvehicleflow.entity.IdentityInformation
;
import
net.sf.json.JSONObject
;
/**
/**
* description //TODO
* description //TODO
...
@@ -28,4 +29,9 @@ public interface IdentityInformationService {
...
@@ -28,4 +29,9 @@ public interface IdentityInformationService {
* @return int 更新数据条数
* @return int 更新数据条数
*/
*/
boolean
isUpdateIdentityInfoSucc
(
IdentityInformation
identityInformation
);
boolean
isUpdateIdentityInfoSucc
(
IdentityInformation
identityInformation
);
JSONObject
getwechatInfoByTempCode
(
String
code
);
IdentityInformation
getAllInfoByOpenid
(
String
openid
);
}
}
src/main/java/com/yingxin/beijingvehicleflow/service/impl/IdentityInformationServiceImpl.java
View file @
8e33252f
...
@@ -5,9 +5,19 @@ import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
...
@@ -5,9 +5,19 @@ import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import
com.yingxin.beijingvehicleflow.mapper.IdentityInformationMapper
;
import
com.yingxin.beijingvehicleflow.mapper.IdentityInformationMapper
;
import
com.yingxin.beijingvehicleflow.service.IdentityInformationService
;
import
com.yingxin.beijingvehicleflow.service.IdentityInformationService
;
import
com.yingxin.beijingvehicleflow.util.PicUtils
;
import
com.yingxin.beijingvehicleflow.util.PicUtils
;
import
net.sf.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLConnection
;
/**
/**
* description //TODO
* description //TODO
*
*
...
@@ -18,6 +28,8 @@ import org.springframework.stereotype.Service;
...
@@ -18,6 +28,8 @@ import org.springframework.stereotype.Service;
@Service
@Service
public
class
IdentityInformationServiceImpl
implements
IdentityInformationService
{
public
class
IdentityInformationServiceImpl
implements
IdentityInformationService
{
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IdentityInformationService
.
class
);
@Autowired
@Autowired
private
IdentityInformationMapper
identityInformationMapper
;
private
IdentityInformationMapper
identityInformationMapper
;
...
@@ -34,4 +46,47 @@ public class IdentityInformationServiceImpl implements IdentityInformationServic
...
@@ -34,4 +46,47 @@ public class IdentityInformationServiceImpl implements IdentityInformationServic
Const
.
FACE_IMG_SIZE
));
Const
.
FACE_IMG_SIZE
));
return
identityInformationMapper
.
updateIdentityInfo
(
identityInformation
)
==
1
;
return
identityInformationMapper
.
updateIdentityInfo
(
identityInformation
)
==
1
;
}
}
@Override
public
JSONObject
getwechatInfoByTempCode
(
String
code
)
{
BufferedReader
in
=
null
;
String
url
=
"https://api.weixin.qq.com/sns/jscode2session?appid=wx8784a1a35b9c76af"
+
"&secret=bbde177fbebb080ad3ad5f57db3db8a2"
+
"&js_code="
+
code
+
"&grant_type=authorization_code"
;
URL
realUrl
;
try
{
realUrl
=
new
URL
(
url
);
}
catch
(
MalformedURLException
e
)
{
LOGGER
.
error
(
"通过tempCode获取openId时,URL错误:"
,
e
);
return
null
;
}
URLConnection
connection
;
JSONObject
jsonObject
;
try
{
connection
=
realUrl
.
openConnection
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
return
JSONObject
.
fromObject
(
in
.
readLine
());
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"通过tempCode获取openId时,打开连接错误:"
,
e
);
return
null
;
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"通过tempCode获取openId时,流关闭异常:"
,
e
);
}
}
// return jsonObject.getString("openid");
}
@Override
public
IdentityInformation
getAllInfoByOpenid
(
String
openid
)
{
return
identityInformationMapper
.
getAllInfoByOpenid
(
openid
);
}
}
}
src/main/java/com/yingxin/beijingvehicleflow/util/AESUtil.java
0 → 100644
View file @
8e33252f
package
com
.
yingxin
.
beijingvehicleflow
.
util
;
import
org.bouncycastle.util.encoders.Base64
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
/**
* AES解密(JAVA版本)
* Add by 成长的小猪(Jason.Song) on 2018/10/26
* http://blog.csdn.net/jasonsong2008
*/
public
class
AESUtil
{
/**
* 微信小程序 开放数据解密
* AES解密(Base64)
* Add by 成长的小猪(Jason.Song) on 2018/10/26
* @param encryptedData 已加密的数据
* @param sessionKey 解密密钥
* @param iv IV偏移量
* @return
* @throws Exception
*/
public
static
String
decryptForWeChatApplet
(
String
encryptedData
,
String
sessionKey
,
String
iv
)
throws
Exception
{
byte
[]
decryptBytes
=
Base64
.
decode
(
encryptedData
);
byte
[]
keyBytes
=
Base64
.
decode
(
sessionKey
);
byte
[]
ivBytes
=
Base64
.
decode
(
iv
);
return
new
String
(
decryptByAesBytes
(
decryptBytes
,
keyBytes
,
ivBytes
));
}
/**
* AES解密
* Add by 成长的小猪(Jason.Song) on 2018/10/26
* @param decryptedBytes 待解密的字节数组
* @param keyBytes 解密密钥字节数组
* @param ivBytes IV初始化向量字节数组
* @return
* @throws Exception
*/
public
static
byte
[]
decryptByAesBytes
(
byte
[]
decryptedBytes
,
byte
[]
keyBytes
,
byte
[]
ivBytes
)
throws
Exception
{
SecretKeySpec
key
=
new
SecretKeySpec
(
keyBytes
,
"AES"
);
IvParameterSpec
iv
=
new
IvParameterSpec
(
ivBytes
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/PKCS5PADDING"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
key
,
iv
);
byte
[]
outputBytes
=
cipher
.
doFinal
(
decryptedBytes
);;
return
outputBytes
;
}
}
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