登录联调
This commit is contained in:
parent
1d9bd5b179
commit
c5eadb85b4
|
@ -10,6 +10,7 @@ WORKDIR /app
|
|||
|
||||
# 设置环境变量
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
# 复制项目源码
|
||||
COPY . .
|
||||
|
|
|
@ -46,6 +46,8 @@ const (
|
|||
InsertUserFail = 3001
|
||||
//邮储code解析失败
|
||||
YouChuCodeFail = 4001
|
||||
//客户号为空
|
||||
YouChuCustNoEmpty = 4002
|
||||
)
|
||||
|
||||
var MsgEN = map[int]string{
|
||||
|
@ -75,6 +77,7 @@ var MsgZH = map[int]string{
|
|||
InsertUserFail: "用户新增失败",
|
||||
Fail: "请求失败",
|
||||
YouChuCodeFail: "Code解析失败",
|
||||
YouChuCustNoEmpty: "客户编号为空",
|
||||
}
|
||||
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
||||
|
||||
|
|
|
@ -185,8 +185,9 @@ func GetUserId(c *gin.Context) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func GetUserPhone(c *gin.Context) string {
|
||||
userIdStr, _ := c.Get("phone")
|
||||
// GetUserCustNo 获取用户custNo
|
||||
func GetUserCustNo(c *gin.Context) string {
|
||||
userIdStr, _ := c.Get("custNo")
|
||||
if userIdStr != nil {
|
||||
var userId, _ = userIdStr.(string)
|
||||
return userId
|
||||
|
|
|
@ -18,16 +18,14 @@ import (
|
|||
|
||||
func CreateOrder(c *gin.Context) {
|
||||
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
|
||||
//userId := controllers.GetUserId(c)
|
||||
userId := 1
|
||||
userId := controllers.GetUserId(c)
|
||||
code, data := services.CreateOrderService(userId, request.ProductId)
|
||||
controllers.HandCodeRes(c, data, code)
|
||||
}
|
||||
|
||||
func OrderList(c *gin.Context) {
|
||||
var request = controllers.GetRequest(c).(*front.OrderListRequest)
|
||||
//userId := controllers.GetUserId(c)
|
||||
userId := 1
|
||||
userId := controllers.GetUserId(c)
|
||||
code, orderList, count := services.OrderQueryService(userId, request)
|
||||
var rsp []front.OrderListResponse
|
||||
if count > 0 {
|
||||
|
|
|
@ -5,7 +5,7 @@ type UnionLoginRequest struct {
|
|||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
Token string
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type YouChuDecryptData struct {
|
||||
|
|
|
@ -31,7 +31,7 @@ func Auth() gin.HandlerFunc {
|
|||
}
|
||||
if err == nil {
|
||||
c.Set("userId", claims.Id)
|
||||
c.Set("phone", claims.Phone)
|
||||
c.Set("custNo", claims.CustNo)
|
||||
c.Next()
|
||||
return
|
||||
} else {
|
||||
|
|
|
@ -58,8 +58,8 @@ func RegisterRoute(router *gin.Engine) {
|
|||
v1.POST("/product/detail", front.ProductDetail)
|
||||
|
||||
//auth
|
||||
auth := v1.Group("auth")
|
||||
//auth := v1.Group("auth", middlewares.Auth())
|
||||
//auth := v1.Group("auth")
|
||||
auth := v1.Group("auth", middlewares.Auth())
|
||||
{
|
||||
order := auth.Group("/order")
|
||||
{
|
||||
|
|
|
@ -20,21 +20,20 @@ func YouChuLogin(req *front.UnionLoginRequest) (code int, login front.LoginRespo
|
|||
}
|
||||
if YouChuResponse.RespCode == "000000" {
|
||||
// 获取用户信息
|
||||
var user usersmodel.Users
|
||||
err := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Where("custNo = ?", YouChuResponse.CustNo).Find(&user)
|
||||
code = handErr(err)
|
||||
if user.Id == "" {
|
||||
user := usersmodel.Users{}
|
||||
has, _ := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Where("custNo = ?", YouChuResponse.CustNo).Get(&user)
|
||||
if !has && YouChuResponse.CustNo != "" {
|
||||
user.CustNo = YouChuResponse.CustNo
|
||||
user.Status = strconv.Itoa(common.STATUSABLED)
|
||||
user.CreateTime = time.Now()
|
||||
_, err := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Insert(&user)
|
||||
_, err := usersmodel.GetInstance().GetDb().Insert(&user)
|
||||
if err != nil {
|
||||
return errorcode.InsertUserFail, front.LoginResponse{}
|
||||
}
|
||||
}
|
||||
login.Token = utils.GeneratorJwtToken(utils.User{
|
||||
Id: user.Id,
|
||||
Phone: user.CustNo,
|
||||
Id: user.Id,
|
||||
CustNo: user.CustNo,
|
||||
})
|
||||
return errorcode.Success, login
|
||||
} else {
|
||||
|
|
|
@ -39,6 +39,7 @@ func (this *YouChuClient) Login(code string) (Code int, response front.YouChuLog
|
|||
}
|
||||
requestData := EncryptRequest(request)
|
||||
bytes, err := json.Marshal(requestData)
|
||||
utils.Log(nil, "YouChuLoginRequest", string(bytes))
|
||||
if err != nil {
|
||||
return errorcode.SystemError, response
|
||||
}
|
||||
|
|
|
@ -372,8 +372,8 @@ func IsNil(x interface{}) bool {
|
|||
}
|
||||
|
||||
type User struct {
|
||||
Id string
|
||||
Phone string
|
||||
Id string
|
||||
CustNo string
|
||||
}
|
||||
|
||||
func GeneratorJwtToken(user User) string {
|
||||
|
@ -382,9 +382,9 @@ func GeneratorJwtToken(user User) string {
|
|||
|
||||
// 创建一个MapClaims对象,用于存放自定义的声明信息
|
||||
claims := jwt.MapClaims{
|
||||
"id": user.Id,
|
||||
"phone": user.Phone,
|
||||
"exp": time.Now().Add(time.Hour * 24).Unix(), // 设置过期时间为24小时后
|
||||
"id": user.Id,
|
||||
"custNo": user.CustNo,
|
||||
"exp": time.Now().Add(time.Hour * 24).Unix(), // 设置过期时间为24小时后
|
||||
}
|
||||
// 使用HS256算法创建一个Token对象
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
@ -399,8 +399,8 @@ func GeneratorJwtToken(user User) string {
|
|||
}
|
||||
|
||||
type Claims struct {
|
||||
Id int
|
||||
Phone string
|
||||
Id string
|
||||
CustNo string
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue