|
@@ -1,10 +1,13 @@
|
|
|
package user
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "encoding/hex"
|
|
|
|
|
+ "fmt"
|
|
|
"mtp2_if/global/app"
|
|
"mtp2_if/global/app"
|
|
|
"mtp2_if/global/e"
|
|
"mtp2_if/global/e"
|
|
|
"mtp2_if/logger"
|
|
"mtp2_if/logger"
|
|
|
"mtp2_if/models"
|
|
"mtp2_if/models"
|
|
|
|
|
+ "mtp2_if/utils"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
@@ -52,7 +55,8 @@ func QueryUserReferNum(c *gin.Context) {
|
|
|
|
|
|
|
|
// QueryUserInfoReq 获取用户信息请求参数
|
|
// QueryUserInfoReq 获取用户信息请求参数
|
|
|
type QueryUserInfoReq struct {
|
|
type QueryUserInfoReq struct {
|
|
|
- UserID int `form:"userID" binding:"required"`
|
|
|
|
|
|
|
+ UserID int `form:"userID" binding:"required"`
|
|
|
|
|
+ IsDecrypt bool `form:"isDecrypt"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// QueryUserInfo 获取用户信息
|
|
// QueryUserInfo 获取用户信息
|
|
@@ -60,6 +64,7 @@ type QueryUserInfoReq struct {
|
|
|
// @Produce json
|
|
// @Produce json
|
|
|
// @Security ApiKeyAuth
|
|
// @Security ApiKeyAuth
|
|
|
// @Param userID query int true "用户ID"
|
|
// @Param userID query int true "用户ID"
|
|
|
|
|
+// @Param isDecrypt query bool false "是否解密"
|
|
|
// @Success 200 {object} models.Userinfo
|
|
// @Success 200 {object} models.Userinfo
|
|
|
// @Failure 500 {object} app.Response
|
|
// @Failure 500 {object} app.Response
|
|
|
// @Router /User/QueryUserInfo [get]
|
|
// @Router /User/QueryUserInfo [get]
|
|
@@ -68,7 +73,7 @@ func QueryUserInfo(c *gin.Context) {
|
|
|
appG := app.Gin{C: c}
|
|
appG := app.Gin{C: c}
|
|
|
|
|
|
|
|
// 获取请求参数
|
|
// 获取请求参数
|
|
|
- var req QueryUserReferNumReq
|
|
|
|
|
|
|
+ var req QueryUserInfoReq
|
|
|
if err := appG.C.ShouldBindQuery(&req); err != nil {
|
|
if err := appG.C.ShouldBindQuery(&req); err != nil {
|
|
|
logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
|
|
logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
|
|
|
appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
@@ -87,6 +92,43 @@ func QueryUserInfo(c *gin.Context) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 解密
|
|
|
|
|
+ if req.IsDecrypt {
|
|
|
|
|
+ key, _ := hex.DecodeString(utils.AESSecretKey)
|
|
|
|
|
+ // 手机号码解密
|
|
|
|
|
+ if len(data.Mobile) > 0 {
|
|
|
|
|
+ if phonenum, err := hex.DecodeString(data.Mobile); err == nil { // hex -> []byte
|
|
|
|
|
+ if mobile, err := utils.AESDecrypt(phonenum, key); err == nil {
|
|
|
|
|
+ // 脱敏
|
|
|
|
|
+ tmp := string(mobile)
|
|
|
|
|
+ l := len(tmp)
|
|
|
|
|
+ if l > 7 {
|
|
|
|
|
+ tmp = fmt.Sprintf("%s****%s", tmp[:3], tmp[l-4:])
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tmp = fmt.Sprintf("%s****", tmp[:3])
|
|
|
|
|
+ }
|
|
|
|
|
+ data.Mobile = tmp
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 证件号码解密
|
|
|
|
|
+ if len(data.Cardnum) > 0 {
|
|
|
|
|
+ if cardnum, err := hex.DecodeString(data.Cardnum); err == nil { // hex -> []byte
|
|
|
|
|
+ if c, err := utils.AESDecrypt(cardnum, key); err == nil {
|
|
|
|
|
+ // 脱敏
|
|
|
|
|
+ tmp := string(c)
|
|
|
|
|
+ l := len(tmp)
|
|
|
|
|
+ if l > 7 {
|
|
|
|
|
+ tmp = fmt.Sprintf("%s****%s", tmp[:3], tmp[l-4:])
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tmp = fmt.Sprintf("%s****", tmp[:3])
|
|
|
|
|
+ }
|
|
|
|
|
+ data.Cardnum = tmp
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 查询成功
|
|
// 查询成功
|
|
|
logger.GetLogger().Debugln("QueryUserInfo successed: %v", data)
|
|
logger.GetLogger().Debugln("QueryUserInfo successed: %v", data)
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, data)
|
|
appG.Response(http.StatusOK, e.SUCCESS, data)
|