mobile.go 525 Bytes
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package common

import (
	"errors"
	"gin-vue-admin/model/request"

	"github.com/gin-gonic/gin"
)

func GetUserPhone(c *gin.Context) (string, error) {
	if claims, exists := c.Get("claims"); exists {
		//global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件!")
		waitUse := claims.(*request.CustomClaims)
		if len(waitUse.Mobile) != 11 {
			return "", errors.New("账号错误")
		}
		return waitUse.Mobile, nil
	}

	return "", errors.New("参数错误")
}