- 注释掉老user与auth相关的代码
This commit is contained in:
@@ -1,121 +1,110 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
// const (
|
||||
// DefTokenDuration = 7 * 24 * time.Hour // 7天
|
||||
// )
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
// type IAuther interface {
|
||||
// Login(id, secret string) (userID, loginType string, err error)
|
||||
// Logout(loginInfo *LoginInfo) error
|
||||
// }
|
||||
|
||||
const (
|
||||
DefTokenDuration = 7 * 24 * time.Hour // 7天
|
||||
)
|
||||
// var (
|
||||
// authers map[string]IAuther
|
||||
// )
|
||||
|
||||
type IAuther interface {
|
||||
Login(id, secret string) (userID, loginType string, err error)
|
||||
Logout(loginInfo *LoginInfo) error
|
||||
}
|
||||
// var (
|
||||
// ErrUserNotExist = errors.New("用户不存在,请联系运营创建")
|
||||
// ErrLoginTypeNotSupported = errors.New("不支持指定的登录类型")
|
||||
// ErrUIDAndPassNotMatch = errors.New("用户与密码不匹配")
|
||||
// ErrAPINeedRealLogin = errors.New("此API要求真正登录")
|
||||
// ErrIllegalLoginType = errors.New("不支持的登录类型")
|
||||
// )
|
||||
|
||||
var (
|
||||
authers map[string]IAuther
|
||||
)
|
||||
// type LoginInfo struct {
|
||||
// ID string
|
||||
// LoginType string
|
||||
// ExpiresIn int64
|
||||
// Token string
|
||||
// }
|
||||
|
||||
var (
|
||||
ErrUserNotExist = errors.New("用户不存在,请联系运营创建")
|
||||
ErrLoginTypeNotSupported = errors.New("不支持指定的登录类型")
|
||||
ErrUIDAndPassNotMatch = errors.New("用户与密码不匹配")
|
||||
ErrAPINeedRealLogin = errors.New("此API要求真正登录")
|
||||
ErrIllegalLoginType = errors.New("不支持的登录类型")
|
||||
)
|
||||
// func init() {
|
||||
// authers = make(map[string]IAuther)
|
||||
// }
|
||||
|
||||
type LoginInfo struct {
|
||||
ID string
|
||||
LoginType string
|
||||
ExpiresIn int64
|
||||
Token string
|
||||
}
|
||||
// func RegisterAuther(loginType string, handler IAuther) {
|
||||
// authers[loginType] = handler
|
||||
// }
|
||||
|
||||
func init() {
|
||||
authers = make(map[string]IAuther)
|
||||
}
|
||||
// func CreateLoginInfo(id, loginType string) (loginInfo *LoginInfo) {
|
||||
// token := utils.GetUUID()
|
||||
// loginInfo = &LoginInfo{
|
||||
// ID: id,
|
||||
// LoginType: loginType,
|
||||
// ExpiresIn: time.Now().Add(DefTokenDuration).Unix(),
|
||||
// Token: token,
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("CreateLoginInfo id:%s, loginType:%s, loginInfo:%s", id, loginType, utils.Format4Output(loginInfo, true))
|
||||
// api.Cacher.Set(token, loginInfo, DefTokenDuration)
|
||||
// return loginInfo
|
||||
// }
|
||||
|
||||
func RegisterAuther(loginType string, handler IAuther) {
|
||||
authers[loginType] = handler
|
||||
}
|
||||
// func Login(id, loginType, secret string) (loginInfo *LoginInfo, err error) {
|
||||
// globals.SugarLogger.Debugf("Login id:%s, loginType:%s, secret:%s", id, loginType, secret)
|
||||
// if handler := authers[loginType]; handler != nil {
|
||||
// userID, loginType2, err2 := handler.Login(id, secret)
|
||||
// if err = err2; err == nil {
|
||||
// if userID != "" {
|
||||
// globals.SugarLogger.Debugf("Login id:%s, loginType:%s, id changed to:%s", id, loginType, userID)
|
||||
// id = userID
|
||||
// }
|
||||
// if loginType2 != "" {
|
||||
// loginType = loginType2
|
||||
// }
|
||||
// return CreateLoginInfo(id, loginType), nil
|
||||
// }
|
||||
// err = ConvertErr2NoUser(err, "")
|
||||
// } else {
|
||||
// err = ErrLoginTypeNotSupported
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
func CreateLoginInfo(id, loginType string) (loginInfo *LoginInfo) {
|
||||
token := utils.GetUUID()
|
||||
loginInfo = &LoginInfo{
|
||||
ID: id,
|
||||
LoginType: loginType,
|
||||
ExpiresIn: time.Now().Add(DefTokenDuration).Unix(),
|
||||
Token: token,
|
||||
}
|
||||
globals.SugarLogger.Debugf("CreateLoginInfo id:%s, loginType:%s, loginInfo:%s", id, loginType, utils.Format4Output(loginInfo, true))
|
||||
api.Cacher.Set(token, loginInfo, DefTokenDuration)
|
||||
return loginInfo
|
||||
}
|
||||
// func Logout(token string) (err error) {
|
||||
// globals.SugarLogger.Debugf("Logout token:%s", token)
|
||||
// loginInfo := new(LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// if handler := authers[loginInfo.LoginType]; handler != nil {
|
||||
// err = handler.Logout(loginInfo)
|
||||
// }
|
||||
// api.Cacher.Del(token)
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func Login(id, loginType, secret string) (loginInfo *LoginInfo, err error) {
|
||||
globals.SugarLogger.Debugf("Login id:%s, loginType:%s, secret:%s", id, loginType, secret)
|
||||
if handler := authers[loginType]; handler != nil {
|
||||
userID, loginType2, err2 := handler.Login(id, secret)
|
||||
if err = err2; err == nil {
|
||||
if userID != "" {
|
||||
globals.SugarLogger.Debugf("Login id:%s, loginType:%s, id changed to:%s", id, loginType, userID)
|
||||
id = userID
|
||||
}
|
||||
if loginType2 != "" {
|
||||
loginType = loginType2
|
||||
}
|
||||
return CreateLoginInfo(id, loginType), nil
|
||||
}
|
||||
err = ConvertErr2NoUser(err, "")
|
||||
} else {
|
||||
err = ErrLoginTypeNotSupported
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
// func GetUserInfo(token string) (loginInfo *LoginInfo, err error) {
|
||||
// loginInfo = new(LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// return loginInfo, nil
|
||||
// }
|
||||
// return nil, model.ErrTokenIsInvalid
|
||||
// }
|
||||
|
||||
func Logout(token string) (err error) {
|
||||
globals.SugarLogger.Debugf("Logout token:%s", token)
|
||||
loginInfo := new(LoginInfo)
|
||||
if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
if handler := authers[loginInfo.LoginType]; handler != nil {
|
||||
err = handler.Logout(loginInfo)
|
||||
}
|
||||
api.Cacher.Del(token)
|
||||
}
|
||||
return err
|
||||
}
|
||||
// func ConvertErr2NoUser(err error, mobileNum string) error {
|
||||
// if dao.IsNoRowsError(err) {
|
||||
// err = ErrUserNotExist
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func GetUserInfo(token string) (loginInfo *LoginInfo, err error) {
|
||||
loginInfo = new(LoginInfo)
|
||||
if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
return loginInfo, nil
|
||||
}
|
||||
return nil, model.ErrTokenIsInvalid
|
||||
}
|
||||
// func (a *LoginInfo) GetAuthID() string {
|
||||
// return a.ID
|
||||
// }
|
||||
|
||||
func ConvertErr2NoUser(err error, mobileNum string) error {
|
||||
if dao.IsNoRowsError(err) {
|
||||
err = ErrUserNotExist
|
||||
}
|
||||
return err
|
||||
}
|
||||
// func (a *LoginInfo) GetAuthType() string {
|
||||
// return a.LoginType
|
||||
// }
|
||||
|
||||
func (a *LoginInfo) GetAuthID() string {
|
||||
return a.ID
|
||||
}
|
||||
|
||||
func (a *LoginInfo) GetAuthType() string {
|
||||
return a.LoginType
|
||||
}
|
||||
|
||||
func (a *LoginInfo) GetUserTag() string {
|
||||
return a.ID
|
||||
}
|
||||
// func (a *LoginInfo) GetUserTag() string {
|
||||
// return a.ID
|
||||
// }
|
||||
|
||||
@@ -1,104 +1,90 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
// const (
|
||||
// DefVerifyCodeDuration = 5 * time.Minute
|
||||
// TestMobile = "91112345678"
|
||||
// TestVerifyCode = "123456"
|
||||
// )
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
|
||||
)
|
||||
// var (
|
||||
// warningMap = map[string]int{
|
||||
// "isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
// "isv.ACCOUNT_ABNORMAL": 1,
|
||||
// "isv.OUT_OF_SERVICE": 1,
|
||||
// "isv.DAY_LIMIT_CONTROL": 1,
|
||||
// }
|
||||
// )
|
||||
|
||||
const (
|
||||
DefVerifyCodeDuration = 5 * time.Minute
|
||||
TestMobile = "91112345678"
|
||||
TestVerifyCode = "123456"
|
||||
)
|
||||
// const (
|
||||
// LoginType = "mobile"
|
||||
// )
|
||||
|
||||
var (
|
||||
warningMap = map[string]int{
|
||||
"isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
"isv.ACCOUNT_ABNORMAL": 1,
|
||||
"isv.OUT_OF_SERVICE": 1,
|
||||
"isv.DAY_LIMIT_CONTROL": 1,
|
||||
}
|
||||
)
|
||||
// var (
|
||||
// ErrVerifyCodeIsWrong = errors.New("验证码错")
|
||||
// )
|
||||
|
||||
const (
|
||||
LoginType = "mobile"
|
||||
)
|
||||
// type Auther struct {
|
||||
// }
|
||||
|
||||
var (
|
||||
ErrVerifyCodeIsWrong = errors.New("验证码错")
|
||||
)
|
||||
// var (
|
||||
// auther *Auther
|
||||
// )
|
||||
|
||||
type Auther struct {
|
||||
}
|
||||
// func init() {
|
||||
// auther = new(Auther)
|
||||
// auth.RegisterAuther(LoginType, auther)
|
||||
// }
|
||||
|
||||
var (
|
||||
auther *Auther
|
||||
)
|
||||
// func SendVerifyCode(mobileNumber string) error {
|
||||
// code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
// globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
func init() {
|
||||
auther = new(Auther)
|
||||
auth.RegisterAuther(LoginType, auther)
|
||||
}
|
||||
// smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
// response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{
|
||||
// "code": code,
|
||||
// })))
|
||||
// api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
||||
// if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||
// } else {
|
||||
// if err == nil {
|
||||
// if warningMap[response.Code] == 1 {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// } else {
|
||||
// globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// }
|
||||
// err = fmt.Errorf("发送短信出错:%s", response.Message)
|
||||
// } else {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func SendVerifyCode(mobileNumber string) error {
|
||||
code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
// func VerifyCode(mobileNumber, code string) (err error) {
|
||||
// globals.SugarLogger.Debugf("VerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{
|
||||
"code": code,
|
||||
})))
|
||||
api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
||||
if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||
} else {
|
||||
if err == nil {
|
||||
if warningMap[response.Code] == 1 {
|
||||
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
} else {
|
||||
globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
}
|
||||
err = fmt.Errorf("发送短信出错:%s", response.Message)
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
// err = ErrVerifyCodeIsWrong
|
||||
// if mobileNumber == TestMobile && code == TestVerifyCode {
|
||||
// err = nil
|
||||
// } else {
|
||||
// if value := api.Cacher.Get(mobileNumber); value != nil {
|
||||
// if code == value.(string) {
|
||||
// api.Cacher.Del(mobileNumber)
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func VerifyCode(mobileNumber, code string) (err error) {
|
||||
globals.SugarLogger.Debugf("VerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
// func (a *Auther) Login(mobileNum, verifyCode string) (userID, LoginType string, err error) {
|
||||
// if err = VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
// _, err = dao.GetWeiXinUserByIDs(dao.GetDB(), mobileNum, "", "", "")
|
||||
// err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// return "", "", err
|
||||
// }
|
||||
|
||||
err = ErrVerifyCodeIsWrong
|
||||
if mobileNumber == TestMobile && code == TestVerifyCode {
|
||||
err = nil
|
||||
} else {
|
||||
if value := api.Cacher.Get(mobileNumber); value != nil {
|
||||
if code == value.(string) {
|
||||
api.Cacher.Del(mobileNumber)
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Auther) Login(mobileNum, verifyCode string) (userID, LoginType string, err error) {
|
||||
if err = VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
_, err = dao.GetWeiXinUserByIDs(dao.GetDB(), mobileNum, "", "", "")
|
||||
err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
}
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
return nil
|
||||
}
|
||||
// func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSendVerifyCode(t *testing.T) {
|
||||
err := SendVerifyCode("18180948107")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// func TestSendVerifyCode(t *testing.T) {
|
||||
// err := SendVerifyCode("18180948107")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,267 +1,249 @@
|
||||
package weixin
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
// const (
|
||||
// LoginType = "weixinsns"
|
||||
// LoginTypeMiniProgram = "weixinmini"
|
||||
// DefTempPasswordDuration = 20 * time.Minute // 登录时间限制在5分钟内
|
||||
// )
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
weixin2 "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
// const (
|
||||
// CacheKeySeparator = "/"
|
||||
// MiniVerifyCodePrefix = "MiniVerifyCode"
|
||||
// SessionKeyPrefix = "SessionKey"
|
||||
// )
|
||||
|
||||
const (
|
||||
LoginType = "weixinsns"
|
||||
LoginTypeMiniProgram = "weixinmini"
|
||||
DefTempPasswordDuration = 20 * time.Minute // 登录时间限制在5分钟内
|
||||
)
|
||||
// var (
|
||||
// StrStateIsWrong = "state:%s状态不对"
|
||||
// )
|
||||
|
||||
const (
|
||||
CacheKeySeparator = "/"
|
||||
MiniVerifyCodePrefix = "MiniVerifyCode"
|
||||
SessionKeyPrefix = "SessionKey"
|
||||
)
|
||||
// var (
|
||||
// auther *Auther
|
||||
// AutherMini *AutherMiniProgram
|
||||
// )
|
||||
|
||||
var (
|
||||
StrStateIsWrong = "state:%s状态不对"
|
||||
)
|
||||
// var (
|
||||
// ErrExceptionalLogin = errors.New("登录异常,超时,请重走绑定流程")
|
||||
// )
|
||||
|
||||
var (
|
||||
auther *Auther
|
||||
AutherMini *AutherMiniProgram
|
||||
)
|
||||
// type Auther struct {
|
||||
// }
|
||||
|
||||
var (
|
||||
ErrExceptionalLogin = errors.New("登录异常,超时,请重走绑定流程")
|
||||
)
|
||||
// type AutherMiniProgram struct {
|
||||
// }
|
||||
|
||||
type Auther struct {
|
||||
}
|
||||
// type UserInfoExt struct {
|
||||
// weixinapi.SNSUserInfo
|
||||
// TempPassword string `json:"tempPassword"` // 一段时间有效的登录密码
|
||||
// LoginInfo *auth.LoginInfo `json:"loginInfo"`
|
||||
// }
|
||||
|
||||
type AutherMiniProgram struct {
|
||||
}
|
||||
// func init() {
|
||||
// auther = new(Auther)
|
||||
// auth.RegisterAuther(LoginType, auther)
|
||||
|
||||
type UserInfoExt struct {
|
||||
weixinapi.SNSUserInfo
|
||||
TempPassword string `json:"tempPassword"` // 一段时间有效的登录密码
|
||||
LoginInfo *auth.LoginInfo `json:"loginInfo"`
|
||||
}
|
||||
// AutherMini = new(AutherMiniProgram)
|
||||
// auth.RegisterAuther(LoginTypeMiniProgram, AutherMini)
|
||||
// }
|
||||
|
||||
func init() {
|
||||
auther = new(Auther)
|
||||
auth.RegisterAuther(LoginType, auther)
|
||||
// func cacheSNSInfo(wxUserinfo *weixinapi.SNSUserInfo, password string, duration time.Duration) {
|
||||
// api.Cacher.Set(wxUserinfo.OpenID, password, duration)
|
||||
// api.Cacher.Set(wxUserinfo.OpenID+".sns", wxUserinfo, duration)
|
||||
// }
|
||||
|
||||
AutherMini = new(AutherMiniProgram)
|
||||
auth.RegisterAuther(LoginTypeMiniProgram, AutherMini)
|
||||
}
|
||||
// func getSNSInfoFromCache(openID string) (wxUserinfo *weixinapi.SNSUserInfo, password string) {
|
||||
// password, _ = api.Cacher.Get(openID).(string)
|
||||
// wxUserinfo = new(weixinapi.SNSUserInfo)
|
||||
// if err := api.Cacher.GetAs(openID+".sns", wxUserinfo); err != nil {
|
||||
// wxUserinfo = nil
|
||||
// }
|
||||
// return wxUserinfo, password
|
||||
// }
|
||||
|
||||
func cacheSNSInfo(wxUserinfo *weixinapi.SNSUserInfo, password string, duration time.Duration) {
|
||||
api.Cacher.Set(wxUserinfo.OpenID, password, duration)
|
||||
api.Cacher.Set(wxUserinfo.OpenID+".sns", wxUserinfo, duration)
|
||||
}
|
||||
// func GetWeiXinUserInfo(code string, state string) (userInfo *UserInfoExt, err error) {
|
||||
// globals.SugarLogger.Debugf("GetUserInfo code:%s", code)
|
||||
// if state == "" {
|
||||
// token, err2 := api.WeixinAPI.SNSRetrieveToken(code)
|
||||
// if err = err2; err == nil {
|
||||
// wxUserinfo, err2 := api.WeixinAPI.SNSGetUserInfo(token.AccessToken, token.OpenID)
|
||||
// if err = err2; err == nil {
|
||||
// userInfo = &UserInfoExt{
|
||||
// SNSUserInfo: *wxUserinfo,
|
||||
// TempPassword: utils.GetUUID(),
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("GetUserInfo code:%s, userInfo:%s", code, utils.Format4Output(userInfo, true))
|
||||
// cacheSNSInfo(wxUserinfo, userInfo.TempPassword, DefTempPasswordDuration)
|
||||
// user, err2 := dao.GetWeiXinUserByIDs(dao.GetDB(), "", wxUserinfo.UnionID, wxUserinfo.OpenID, "")
|
||||
// if err = err2; err == nil {
|
||||
// userInfo.LoginInfo = auth.CreateLoginInfo(user.Tel, mobile.LoginType)
|
||||
// } else if !dao.IsNoRowsError(err) { // 非用户不存在错误,报错
|
||||
// return nil, err
|
||||
// }
|
||||
// return userInfo, nil
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// err = fmt.Errorf(StrStateIsWrong, state)
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
func getSNSInfoFromCache(openID string) (wxUserinfo *weixinapi.SNSUserInfo, password string) {
|
||||
password, _ = api.Cacher.Get(openID).(string)
|
||||
wxUserinfo = new(weixinapi.SNSUserInfo)
|
||||
if err := api.Cacher.GetAs(openID+".sns", wxUserinfo); err != nil {
|
||||
wxUserinfo = nil
|
||||
}
|
||||
return wxUserinfo, password
|
||||
}
|
||||
// // 此函数需要调整
|
||||
// func (a *Auther) Login(openid, password string) (userID, LoginType string, err error) {
|
||||
// globals.SugarLogger.Debugf("weixinsns Login openid:%s, password:%s", openid, password)
|
||||
// _, cachedPwd := getSNSInfoFromCache(openid)
|
||||
// if cachedPwd != "" && password == cachedPwd {
|
||||
// api.Cacher.Del(openid)
|
||||
// return "", "", nil
|
||||
// }
|
||||
// return "", "", ErrExceptionalLogin
|
||||
// }
|
||||
|
||||
func GetWeiXinUserInfo(code string, state string) (userInfo *UserInfoExt, err error) {
|
||||
globals.SugarLogger.Debugf("GetUserInfo code:%s", code)
|
||||
if state == "" {
|
||||
token, err2 := api.WeixinAPI.SNSRetrieveToken(code)
|
||||
if err = err2; err == nil {
|
||||
wxUserinfo, err2 := api.WeixinAPI.SNSGetUserInfo(token.AccessToken, token.OpenID)
|
||||
if err = err2; err == nil {
|
||||
userInfo = &UserInfoExt{
|
||||
SNSUserInfo: *wxUserinfo,
|
||||
TempPassword: utils.GetUUID(),
|
||||
}
|
||||
globals.SugarLogger.Debugf("GetUserInfo code:%s, userInfo:%s", code, utils.Format4Output(userInfo, true))
|
||||
cacheSNSInfo(wxUserinfo, userInfo.TempPassword, DefTempPasswordDuration)
|
||||
user, err2 := dao.GetWeiXinUserByIDs(dao.GetDB(), "", wxUserinfo.UnionID, wxUserinfo.OpenID, "")
|
||||
if err = err2; err == nil {
|
||||
userInfo.LoginInfo = auth.CreateLoginInfo(user.Tel, mobile.LoginType)
|
||||
} else if !dao.IsNoRowsError(err) { // 非用户不存在错误,报错
|
||||
return nil, err
|
||||
}
|
||||
return userInfo, nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf(StrStateIsWrong, state)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
// func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// 此函数需要调整
|
||||
func (a *Auther) Login(openid, password string) (userID, LoginType string, err error) {
|
||||
globals.SugarLogger.Debugf("weixinsns Login openid:%s, password:%s", openid, password)
|
||||
_, cachedPwd := getSNSInfoFromCache(openid)
|
||||
if cachedPwd != "" && password == cachedPwd {
|
||||
api.Cacher.Del(openid)
|
||||
return "", "", nil
|
||||
}
|
||||
return "", "", ErrExceptionalLogin
|
||||
}
|
||||
// func BindMobile(token, mobileNum, code, nickname string) (err error) {
|
||||
// globals.SugarLogger.Debugf("BindMobile token:%s, mobileNum:%s, code:%s, nickname:%s", token, mobileNum, code, nickname)
|
||||
|
||||
func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
return nil
|
||||
}
|
||||
// loginInfo := new(auth.LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// if err = mobile.VerifyCode(mobileNum, code); err == nil {
|
||||
// wxUserinfo, _ := getSNSInfoFromCache(loginInfo.ID)
|
||||
// if wxUserinfo == nil {
|
||||
// return fmt.Errorf("绑定超时,请重新绑定")
|
||||
// }
|
||||
// if nickname == "" {
|
||||
// nickname = wxUserinfo.NickName
|
||||
// }
|
||||
// err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""), mobileNum)
|
||||
// }
|
||||
// }
|
||||
// jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
// return err
|
||||
// }
|
||||
|
||||
func BindMobile(token, mobileNum, code, nickname string) (err error) {
|
||||
globals.SugarLogger.Debugf("BindMobile token:%s, mobileNum:%s, code:%s, nickname:%s", token, mobileNum, code, nickname)
|
||||
// // 绑定手机加登录
|
||||
// func BindMobile2(openid, secret, mobileNum, verifyCode, nickname string) (loginInfo *auth.LoginInfo, err error) {
|
||||
// globals.SugarLogger.Debugf("BindMobile2 openid:%s, secret:%s, mobileNum:%s, verifyCode:%s, nickname:%s", openid, secret, mobileNum, verifyCode, nickname)
|
||||
|
||||
loginInfo := new(auth.LoginInfo)
|
||||
if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
if err = mobile.VerifyCode(mobileNum, code); err == nil {
|
||||
wxUserinfo, _ := getSNSInfoFromCache(loginInfo.ID)
|
||||
if wxUserinfo == nil {
|
||||
return fmt.Errorf("绑定超时,请重新绑定")
|
||||
}
|
||||
if nickname == "" {
|
||||
nickname = wxUserinfo.NickName
|
||||
}
|
||||
err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""), mobileNum)
|
||||
}
|
||||
}
|
||||
jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
return err
|
||||
}
|
||||
// err = ErrExceptionalLogin
|
||||
// if value := api.Cacher.Get(openid); value != nil {
|
||||
// wxUserinfo, cachedSecret := getSNSInfoFromCache(openid)
|
||||
// if wxUserinfo == nil {
|
||||
// return nil, fmt.Errorf("绑定超时,请重新绑定")
|
||||
// }
|
||||
// if secret == cachedSecret {
|
||||
// if err = mobile.VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
// api.Cacher.Del(openid)
|
||||
// err = nil
|
||||
// if nickname == "" {
|
||||
// nickname = wxUserinfo.NickName
|
||||
// }
|
||||
// if err = dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""); err == nil {
|
||||
// loginInfo = auth.CreateLoginInfo(mobileNum, mobile.LoginType)
|
||||
// } else {
|
||||
// err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
// return loginInfo, err
|
||||
// }
|
||||
|
||||
// 绑定手机加登录
|
||||
func BindMobile2(openid, secret, mobileNum, verifyCode, nickname string) (loginInfo *auth.LoginInfo, err error) {
|
||||
globals.SugarLogger.Debugf("BindMobile2 openid:%s, secret:%s, mobileNum:%s, verifyCode:%s, nickname:%s", openid, secret, mobileNum, verifyCode, nickname)
|
||||
// // 此函数已废弃
|
||||
// // 对于小程序来说,
|
||||
// // 1,用户必须先在后台创建(手机号标识)
|
||||
// // 2,用户必须先绑定微信
|
||||
// // 先以短信方式登录:
|
||||
// // SendMobileVerifyCode
|
||||
// // Login use type mobile
|
||||
// // MiniBindWeiXin
|
||||
// // 3,用户以CODE来登录(Login use type weixinmini)
|
||||
// // Login
|
||||
|
||||
err = ErrExceptionalLogin
|
||||
if value := api.Cacher.Get(openid); value != nil {
|
||||
wxUserinfo, cachedSecret := getSNSInfoFromCache(openid)
|
||||
if wxUserinfo == nil {
|
||||
return nil, fmt.Errorf("绑定超时,请重新绑定")
|
||||
}
|
||||
if secret == cachedSecret {
|
||||
if err = mobile.VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
api.Cacher.Del(openid)
|
||||
err = nil
|
||||
if nickname == "" {
|
||||
nickname = wxUserinfo.NickName
|
||||
}
|
||||
if err = dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""); err == nil {
|
||||
loginInfo = auth.CreateLoginInfo(mobileNum, mobile.LoginType)
|
||||
} else {
|
||||
err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
return loginInfo, err
|
||||
}
|
||||
// func (a *AutherMiniProgram) BindWeiXin(ctx *jxcontext.Context, code, nickName string) (err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram BindWeiXin code:%s, nickName:%s", code, nickName)
|
||||
// loginInfo := ctx.GetLoginInfo()
|
||||
// if loginInfo == nil || loginInfo.GetAuthType() != mobile.LoginType {
|
||||
// return fmt.Errorf("调用AutherMiniProgram BindWeiXin时,必须以手机验证方式登录")
|
||||
// }
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// err = dao.UpdateWeiXinUser(dao.GetDB(), loginInfo.GetAuthID(), nickName, sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
// return auth.ConvertErr2NoUser(err, "")
|
||||
// }
|
||||
|
||||
// 此函数已废弃
|
||||
// 对于小程序来说,
|
||||
// 1,用户必须先在后台创建(手机号标识)
|
||||
// 2,用户必须先绑定微信
|
||||
// 先以短信方式登录:
|
||||
// SendMobileVerifyCode
|
||||
// Login use type mobile
|
||||
// MiniBindWeiXin
|
||||
// 3,用户以CODE来登录(Login use type weixinmini)
|
||||
// Login
|
||||
// // 绑定小程序
|
||||
// func (a *AutherMiniProgram) BindMiniProgram(ctx *jxcontext.Context, code string) (err error) {
|
||||
// globals.SugarLogger.Debugf("BindMiniProgram code:%s", code)
|
||||
// if ctx.GetLoginType() != mobile.LoginType {
|
||||
// return errors.New("登录方式应该为手机")
|
||||
// }
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// db := dao.GetDB()
|
||||
// user, err := dao.GetWeiXinUserByIDs(db, ctx.GetLoginID(), "", "", "")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // if user.OpenIDUnion != sessionInfo.UnionID {
|
||||
// // return errors.New("绑定用户不匹配")
|
||||
// // }
|
||||
// err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(db, user.Tel, "", sessionInfo.UnionID, "", sessionInfo.OpenID), user.Tel)
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (a *AutherMiniProgram) BindWeiXin(ctx *jxcontext.Context, code, nickName string) (err error) {
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram BindWeiXin code:%s, nickName:%s", code, nickName)
|
||||
loginInfo := ctx.GetLoginInfo()
|
||||
if loginInfo == nil || loginInfo.GetAuthType() != mobile.LoginType {
|
||||
return fmt.Errorf("调用AutherMiniProgram BindWeiXin时,必须以手机验证方式登录")
|
||||
}
|
||||
sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dao.UpdateWeiXinUser(dao.GetDB(), loginInfo.GetAuthID(), nickName, sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
return auth.ConvertErr2NoUser(err, "")
|
||||
}
|
||||
// func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType string, err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login mobileNum:%s, code:%s", mobileNum, code)
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return "", "", err
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login code:%s, unionID:%s, openID:%s", code, sessionInfo.UnionID, sessionInfo.OpenID)
|
||||
// db := dao.GetDB()
|
||||
// user, err := dao.GetWeiXinUserByIDs(db, "", sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
// if err != nil {
|
||||
// return "", "", auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// if user.OpenIDMini != sessionInfo.OpenID {
|
||||
// user.OpenIDMini = sessionInfo.OpenID
|
||||
// dao.UpdateEntity(db, user, "OpenIDMini")
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login user.Tel:%s, code:%s, openID:%s", user.Tel, code, sessionInfo.OpenID)
|
||||
// if mobileNum != user.Tel {
|
||||
|
||||
// 绑定小程序
|
||||
func (a *AutherMiniProgram) BindMiniProgram(ctx *jxcontext.Context, code string) (err error) {
|
||||
globals.SugarLogger.Debugf("BindMiniProgram code:%s", code)
|
||||
if ctx.GetLoginType() != mobile.LoginType {
|
||||
return errors.New("登录方式应该为手机")
|
||||
}
|
||||
sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
db := dao.GetDB()
|
||||
user, err := dao.GetWeiXinUserByIDs(db, ctx.GetLoginID(), "", "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// if user.OpenIDUnion != sessionInfo.UnionID {
|
||||
// return errors.New("绑定用户不匹配")
|
||||
// }
|
||||
err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(db, user.Tel, "", sessionInfo.UnionID, "", sessionInfo.OpenID), user.Tel)
|
||||
return err
|
||||
}
|
||||
// }
|
||||
// api.Cacher.Set(composeSessionKeyCacheKey(user.Tel), sessionInfo.SessionKey, auth.DefTokenDuration)
|
||||
// return user.Tel, mobile.LoginType, err
|
||||
// }
|
||||
|
||||
func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType string, err error) {
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram Login mobileNum:%s, code:%s", mobileNum, code)
|
||||
sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram Login code:%s, unionID:%s, openID:%s", code, sessionInfo.UnionID, sessionInfo.OpenID)
|
||||
db := dao.GetDB()
|
||||
user, err := dao.GetWeiXinUserByIDs(db, "", sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
if err != nil {
|
||||
return "", "", auth.ConvertErr2NoUser(err, mobileNum)
|
||||
}
|
||||
if user.OpenIDMini != sessionInfo.OpenID {
|
||||
user.OpenIDMini = sessionInfo.OpenID
|
||||
dao.UpdateEntity(db, user, "OpenIDMini")
|
||||
}
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram Login user.Tel:%s, code:%s, openID:%s", user.Tel, code, sessionInfo.OpenID)
|
||||
if mobileNum != user.Tel {
|
||||
// func (a *AutherMiniProgram) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Logout openid:%s", utils.Format4Output(loginInfo, false))
|
||||
// return api.Cacher.Del(composeSessionKeyCacheKey(loginInfo.GetAuthID()))
|
||||
// }
|
||||
|
||||
}
|
||||
api.Cacher.Set(composeSessionKeyCacheKey(user.Tel), sessionInfo.SessionKey, auth.DefTokenDuration)
|
||||
return user.Tel, mobile.LoginType, err
|
||||
}
|
||||
// func (a *AutherMiniProgram) DecryptData(ctx *jxcontext.Context, encryptedData, iv string) (decryptedDataBase64 string, err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram DecryptData encryptedData:%s, iv:%s", encryptedData, iv)
|
||||
// var sessionKey string
|
||||
// if err = api.Cacher.GetAs(composeSessionKeyCacheKey(ctx.GetLoginInfo().GetAuthID()), &sessionKey); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// decryptedData, err := weixin2.ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return base64.StdEncoding.EncodeToString(decryptedData), nil
|
||||
// }
|
||||
|
||||
func (a *AutherMiniProgram) Logout(loginInfo *auth.LoginInfo) error {
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram Logout openid:%s", utils.Format4Output(loginInfo, false))
|
||||
return api.Cacher.Del(composeSessionKeyCacheKey(loginInfo.GetAuthID()))
|
||||
}
|
||||
// func composeMiniVerifiyCacheKey(key string) string {
|
||||
// return MiniVerifyCodePrefix + CacheKeySeparator + key
|
||||
// }
|
||||
|
||||
func (a *AutherMiniProgram) DecryptData(ctx *jxcontext.Context, encryptedData, iv string) (decryptedDataBase64 string, err error) {
|
||||
globals.SugarLogger.Debugf("AutherMiniProgram DecryptData encryptedData:%s, iv:%s", encryptedData, iv)
|
||||
var sessionKey string
|
||||
if err = api.Cacher.GetAs(composeSessionKeyCacheKey(ctx.GetLoginInfo().GetAuthID()), &sessionKey); err != nil {
|
||||
return "", err
|
||||
}
|
||||
decryptedData, err := weixin2.ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(decryptedData), nil
|
||||
}
|
||||
|
||||
func composeMiniVerifiyCacheKey(key string) string {
|
||||
return MiniVerifyCodePrefix + CacheKeySeparator + key
|
||||
}
|
||||
|
||||
func composeSessionKeyCacheKey(key string) string {
|
||||
return SessionKeyPrefix + CacheKeySeparator + key
|
||||
}
|
||||
// func composeSessionKeyCacheKey(key string) string {
|
||||
// return SessionKeyPrefix + CacheKeySeparator + key
|
||||
// }
|
||||
|
||||
@@ -179,15 +179,15 @@ func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]inte
|
||||
sqlWhereParams = append(sqlWhereParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
if !globals.DisableWXAuth1 && jxutils.IsLegalMobileNumber(keywordInt64) {
|
||||
sql += `
|
||||
LEFT JOIN weixins wx1 ON t1.id = wx1.jxstoreid AND wx1.parentid = -1 AND wx1.tel = ?
|
||||
LEFT JOIN weixins wx2 ON t1.id = wx2.jxstoreid AND wx2.parentid = -1
|
||||
LEFT JOIN weixins wx3 ON wx3.parentid = wx2.id AND wx3.tel = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64)
|
||||
sqlWhere += " OR wx1.id IS NOT NULL OR wx3.id IS NOT NULL"
|
||||
}
|
||||
// if !globals.DisableWXAuth1 && jxutils.IsLegalMobileNumber(keywordInt64) {
|
||||
// sql += `
|
||||
// LEFT JOIN weixins wx1 ON t1.id = wx1.jxstoreid AND wx1.parentid = -1 AND wx1.tel = ?
|
||||
// LEFT JOIN weixins wx2 ON t1.id = wx2.jxstoreid AND wx2.parentid = -1
|
||||
// LEFT JOIN weixins wx3 ON wx3.parentid = wx2.id AND wx3.tel = ?
|
||||
// `
|
||||
// sqlParams = append(sqlParams, keywordInt64, keywordInt64)
|
||||
// sqlWhere += " OR wx1.id IS NOT NULL OR wx3.id IS NOT NULL"
|
||||
// }
|
||||
sqlWhere += " OR t1.id = ? OR t1.city_code = ? OR t1.district_code = ?"
|
||||
sqlWhereParams = append(sqlWhereParams, keywordInt64, keywordInt64, keywordInt64)
|
||||
if jxutils.GuessVendorIDFromVendorStoreID(keywordInt64) != model.VendorIDUnknown {
|
||||
|
||||
@@ -1,226 +1,210 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// var (
|
||||
// LoginTypeFieldMap = map[string]string{
|
||||
// mobile.LoginType: "tel",
|
||||
// weixin.LoginType: "openid",
|
||||
// weixin.LoginTypeMiniProgram: "openid_mini",
|
||||
// }
|
||||
// )
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
// func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*dao.StoreUserInfo, err error) {
|
||||
// sql := `
|
||||
// SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
// CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"parentID":', t2.parentid, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
// FROM weixins t1
|
||||
// LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
||||
// LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
||||
// WHERE t1.parentid = -1 AND t1.jxstoreid = ?
|
||||
// GROUP BY 1,2,3,4,5,6,7;
|
||||
// `
|
||||
// // globals.SugarLogger.Debug(sql)
|
||||
// if err = dao.GetRows(nil, &storeUserInfos, sql, storeID); err == nil {
|
||||
// for _, storeUserInfo := range storeUserInfos {
|
||||
// if storeUserInfo.MembersStr != "" {
|
||||
// err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return storeUserInfos, err
|
||||
// }
|
||||
|
||||
var (
|
||||
LoginTypeFieldMap = map[string]string{
|
||||
mobile.LoginType: "tel",
|
||||
weixin.LoginType: "openid",
|
||||
weixin.LoginTypeMiniProgram: "openid_mini",
|
||||
}
|
||||
)
|
||||
// func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||
// storeUserInfo, err = dao.GetUserStoreInfo(dao.GetDB(), "tel", mobile)
|
||||
// globals.SugarLogger.Debugf("GetUserInfo:%s, token:%s, mobile:%s, storeUserInfo:%s, err:%v", ctx.GetTrackInfo(), ctx.GetToken(), mobile, utils.Format4Output(storeUserInfo, true), err)
|
||||
// return storeUserInfo, err
|
||||
// }
|
||||
|
||||
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*dao.StoreUserInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"parentID":', t2.parentid, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
FROM weixins t1
|
||||
LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
||||
LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
||||
WHERE t1.parentid = -1 AND t1.jxstoreid = ?
|
||||
GROUP BY 1,2,3,4,5,6,7;
|
||||
`
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
if err = dao.GetRows(nil, &storeUserInfos, sql, storeID); err == nil {
|
||||
for _, storeUserInfo := range storeUserInfos {
|
||||
if storeUserInfo.MembersStr != "" {
|
||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
}
|
||||
}
|
||||
}
|
||||
return storeUserInfos, err
|
||||
}
|
||||
// func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||
// loginInfo := ctx.GetLoginInfo()
|
||||
// if loginInfo == nil {
|
||||
// return nil, auth.ErrAPINeedRealLogin
|
||||
// }
|
||||
// fieldName := LoginTypeFieldMap[loginInfo.GetAuthType()]
|
||||
// if fieldName == "" {
|
||||
// return nil, auth.ErrIllegalLoginType
|
||||
// }
|
||||
// storeUserInfo, err = dao.GetUserStoreInfo(dao.GetDB(), fieldName, loginInfo.GetAuthID())
|
||||
// globals.SugarLogger.Debugf("GetSelfInfo:%s, token:%s, storeUserInfo:%s, err:%v", ctx.GetTrackInfo(), ctx.GetToken(), utils.Format4Output(storeUserInfo, true), err)
|
||||
// return storeUserInfo, err
|
||||
// }
|
||||
|
||||
func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||
storeUserInfo, err = dao.GetUserStoreInfo(dao.GetDB(), "tel", mobile)
|
||||
globals.SugarLogger.Debugf("GetUserInfo:%s, token:%s, mobile:%s, storeUserInfo:%s, err:%v", ctx.GetTrackInfo(), ctx.GetToken(), mobile, utils.Format4Output(storeUserInfo, true), err)
|
||||
return storeUserInfo, err
|
||||
}
|
||||
// func GetMyStoreList(ctx *jxcontext.Context) (storeList []*dao.StoreWithCityName, err error) {
|
||||
// mobileNum, _ := ctx.GetMobileAndUserID()
|
||||
// if mobileNum == "" {
|
||||
// return nil, fmt.Errorf("不能得到用户手机号")
|
||||
// }
|
||||
// storeList, err = dao.GetStoreListByMobile(dao.GetDB(), mobileNum)
|
||||
// return storeList, err
|
||||
// }
|
||||
|
||||
func GetSelfInfo(ctx *jxcontext.Context) (storeUserInfo *dao.StoreUserInfo, err error) {
|
||||
loginInfo := ctx.GetLoginInfo()
|
||||
if loginInfo == nil {
|
||||
return nil, auth.ErrAPINeedRealLogin
|
||||
}
|
||||
fieldName := LoginTypeFieldMap[loginInfo.GetAuthType()]
|
||||
if fieldName == "" {
|
||||
return nil, auth.ErrIllegalLoginType
|
||||
}
|
||||
storeUserInfo, err = dao.GetUserStoreInfo(dao.GetDB(), fieldName, loginInfo.GetAuthID())
|
||||
globals.SugarLogger.Debugf("GetSelfInfo:%s, token:%s, storeUserInfo:%s, err:%v", ctx.GetTrackInfo(), ctx.GetToken(), utils.Format4Output(storeUserInfo, true), err)
|
||||
return storeUserInfo, err
|
||||
}
|
||||
// func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
|
||||
// db := dao.GetDB()
|
||||
// num, err = dao.UpdateEntityByKV(db, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
// "JxStoreID": 0,
|
||||
// "ParentID": -1,
|
||||
// }, map[string]interface{}{
|
||||
// "Tel": mobile,
|
||||
// })
|
||||
// if err == nil {
|
||||
// jxutils.HandleUserWXRemark(db, mobile, false)
|
||||
// TransferLegacyWeixins(mobile)
|
||||
// }
|
||||
// return num, err
|
||||
// }
|
||||
|
||||
func GetMyStoreList(ctx *jxcontext.Context) (storeList []*dao.StoreWithCityName, err error) {
|
||||
mobileNum, _ := ctx.GetMobileAndUserID()
|
||||
if mobileNum == "" {
|
||||
return nil, fmt.Errorf("不能得到用户手机号")
|
||||
}
|
||||
storeList, err = dao.GetStoreListByMobile(dao.GetDB(), mobileNum)
|
||||
return storeList, err
|
||||
}
|
||||
// func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num int64, err error) {
|
||||
// db := dao.GetDB()
|
||||
// user, err2 := verifyMobileIsBlank(db, mobile)
|
||||
// if err = err2; err == nil || err == orm.ErrNoRows {
|
||||
// user.JxStoreID = storeID
|
||||
// if err == nil {
|
||||
// dao.Begin(db)
|
||||
// defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// dao.Rollback(db)
|
||||
// panic(r)
|
||||
// }
|
||||
// }()
|
||||
// if num, err = dao.UpdateEntity(db, user, "JxStoreID"); err == nil {
|
||||
// err = dao.SetWeiXinsEmpty2Null(db, user)
|
||||
// }
|
||||
// if err != nil {
|
||||
// dao.Rollback(db)
|
||||
// } else {
|
||||
// dao.Commit(db)
|
||||
// }
|
||||
// } else {
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
// dao.WrapAddIDCULEntity(user, ctx.GetUserName())
|
||||
// user.ParentID = -1
|
||||
// if err = dao.CreateWeiXins(db, user); err == nil {
|
||||
// num = 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// jxutils.HandleUserWXRemark(db, mobile, false)
|
||||
// TransferLegacyWeixins(mobile)
|
||||
// }
|
||||
// return num, err
|
||||
// }
|
||||
|
||||
func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
num, err = dao.UpdateEntityByKV(db, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
"JxStoreID": 0,
|
||||
"ParentID": -1,
|
||||
}, map[string]interface{}{
|
||||
"Tel": mobile,
|
||||
})
|
||||
if err == nil {
|
||||
jxutils.HandleUserWXRemark(db, mobile, false)
|
||||
TransferLegacyWeixins(mobile)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
// func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num int64, err error) {
|
||||
// db := dao.GetDB()
|
||||
// parentUser := &legacymodel.WeiXins{}
|
||||
// parentUser.Tel = parentMobile
|
||||
// if err = dao.GetEntity(db, parentUser, "Tel"); err == nil {
|
||||
// if parentUser.ParentID == -1 {
|
||||
// globals.SugarLogger.Debug(parentUser)
|
||||
// if err = verifyMobileHasNoMembers(db, mobile); err == nil {
|
||||
// user, err2 := verifyMobileIsBlank(db, mobile)
|
||||
// if err = err2; err == nil || err == orm.ErrNoRows {
|
||||
// user.ParentID = parentUser.ID
|
||||
// if err == nil {
|
||||
// // todo transaction
|
||||
// if num, err = dao.UpdateEntity(db, user, "ParentID"); err == nil {
|
||||
// err = dao.SetWeiXinsEmpty2Null(db, user)
|
||||
// }
|
||||
// } else {
|
||||
// dao.WrapAddIDCULEntity(user, ctx.GetUserName())
|
||||
// if err = dao.CreateWeiXins(db, user); err == nil {
|
||||
// num = 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// err = fmt.Errorf("%s本身是成员", parentMobile)
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// jxutils.HandleUserWXRemark(db, mobile, false)
|
||||
// TransferLegacyWeixins(mobile)
|
||||
// }
|
||||
// return num, err
|
||||
// }
|
||||
|
||||
func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
user, err2 := verifyMobileIsBlank(db, mobile)
|
||||
if err = err2; err == nil || err == orm.ErrNoRows {
|
||||
user.JxStoreID = storeID
|
||||
if err == nil {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if num, err = dao.UpdateEntity(db, user, "JxStoreID"); err == nil {
|
||||
err = dao.SetWeiXinsEmpty2Null(db, user)
|
||||
}
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
} else {
|
||||
dao.Commit(db)
|
||||
}
|
||||
} else {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
dao.WrapAddIDCULEntity(user, ctx.GetUserName())
|
||||
user.ParentID = -1
|
||||
if err = dao.CreateWeiXins(db, user); err == nil {
|
||||
num = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
jxutils.HandleUserWXRemark(db, mobile, false)
|
||||
TransferLegacyWeixins(mobile)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
// func ChangeMobile(ctx *jxcontext.Context, curMobile, expectedMobile string) (num int64, err error) {
|
||||
// num, err = dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
// "Tel": expectedMobile,
|
||||
// }, map[string]interface{}{
|
||||
// "Tel": curMobile,
|
||||
// })
|
||||
// if err == nil {
|
||||
// TransferLegacyWeixins(curMobile)
|
||||
// TransferLegacyWeixins(expectedMobile)
|
||||
// }
|
||||
// return num, err
|
||||
// }
|
||||
|
||||
func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
parentUser := &legacymodel.WeiXins{}
|
||||
parentUser.Tel = parentMobile
|
||||
if err = dao.GetEntity(db, parentUser, "Tel"); err == nil {
|
||||
if parentUser.ParentID == -1 {
|
||||
globals.SugarLogger.Debug(parentUser)
|
||||
if err = verifyMobileHasNoMembers(db, mobile); err == nil {
|
||||
user, err2 := verifyMobileIsBlank(db, mobile)
|
||||
if err = err2; err == nil || err == orm.ErrNoRows {
|
||||
user.ParentID = parentUser.ID
|
||||
if err == nil {
|
||||
// todo transaction
|
||||
if num, err = dao.UpdateEntity(db, user, "ParentID"); err == nil {
|
||||
err = dao.SetWeiXinsEmpty2Null(db, user)
|
||||
}
|
||||
} else {
|
||||
dao.WrapAddIDCULEntity(user, ctx.GetUserName())
|
||||
if err = dao.CreateWeiXins(db, user); err == nil {
|
||||
num = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("%s本身是成员", parentMobile)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
jxutils.HandleUserWXRemark(db, mobile, false)
|
||||
TransferLegacyWeixins(mobile)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
// func verifyMobileIsBlank(db *dao.DaoDB, mobile string) (user *legacymodel.WeiXins, err error) {
|
||||
// if !jxutils.IsStringLikeMobile(mobile) {
|
||||
// return nil, fmt.Errorf("%s看起来不像是一个手机号", mobile)
|
||||
// }
|
||||
// user = &legacymodel.WeiXins{
|
||||
// Tel: mobile,
|
||||
// }
|
||||
// if err = dao.GetEntity(db, user, "Tel"); err == nil {
|
||||
// if user.ParentID != -1 && user.ParentID != 0 {
|
||||
// userParent := &legacymodel.WeiXins{
|
||||
// ID: user.ParentID,
|
||||
// }
|
||||
// if err = dao.GetEntity(db, userParent); err != nil && err != orm.ErrNoRows {
|
||||
// return nil, err
|
||||
// }
|
||||
// if err != orm.ErrNoRows {
|
||||
// err = fmt.Errorf("%s已经是组长:%s,门店:%d的小组成员", mobile, userParent.Tel, userParent.JxStoreID)
|
||||
// } else {
|
||||
// err = nil
|
||||
// }
|
||||
// } else if user.JxStoreID != 0 {
|
||||
// store := &model.Store{}
|
||||
// store.ID = user.JxStoreID
|
||||
// if err = dao.GetEntity(db, store); err == nil {
|
||||
// err = fmt.Errorf("%s本身已经是门店:%d的组长", mobile, user.JxStoreID)
|
||||
// } else if dao.IsNoRowsError(err) {
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return user, err
|
||||
// }
|
||||
|
||||
func ChangeMobile(ctx *jxcontext.Context, curMobile, expectedMobile string) (num int64, err error) {
|
||||
num, err = dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
"Tel": expectedMobile,
|
||||
}, map[string]interface{}{
|
||||
"Tel": curMobile,
|
||||
})
|
||||
if err == nil {
|
||||
TransferLegacyWeixins(curMobile)
|
||||
TransferLegacyWeixins(expectedMobile)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func verifyMobileIsBlank(db *dao.DaoDB, mobile string) (user *legacymodel.WeiXins, err error) {
|
||||
if !jxutils.IsStringLikeMobile(mobile) {
|
||||
return nil, fmt.Errorf("%s看起来不像是一个手机号", mobile)
|
||||
}
|
||||
user = &legacymodel.WeiXins{
|
||||
Tel: mobile,
|
||||
}
|
||||
if err = dao.GetEntity(db, user, "Tel"); err == nil {
|
||||
if user.ParentID != -1 && user.ParentID != 0 {
|
||||
userParent := &legacymodel.WeiXins{
|
||||
ID: user.ParentID,
|
||||
}
|
||||
if err = dao.GetEntity(db, userParent); err != nil && err != orm.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
if err != orm.ErrNoRows {
|
||||
err = fmt.Errorf("%s已经是组长:%s,门店:%d的小组成员", mobile, userParent.Tel, userParent.JxStoreID)
|
||||
} else {
|
||||
err = nil
|
||||
}
|
||||
} else if user.JxStoreID != 0 {
|
||||
store := &model.Store{}
|
||||
store.ID = user.JxStoreID
|
||||
if err = dao.GetEntity(db, store); err == nil {
|
||||
err = fmt.Errorf("%s本身已经是门店:%d的组长", mobile, user.JxStoreID)
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
func verifyMobileHasNoMembers(db *dao.DaoDB, mobile string) (err error) {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err = dao.GetRow(db, countInfo, `
|
||||
SELECT COUNT(*) ct
|
||||
FROM weixins t1
|
||||
JOIN weixins t2 ON t1.parentid = t2.id AND t2.tel = ?
|
||||
`, mobile); err == nil {
|
||||
if countInfo.Ct > 0 {
|
||||
user := &legacymodel.WeiXins{
|
||||
Tel: mobile,
|
||||
}
|
||||
dao.GetEntity(db, user, "Tel")
|
||||
err = fmt.Errorf("%s本身已经是门店:%d组长", mobile, user.JxStoreID)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
// func verifyMobileHasNoMembers(db *dao.DaoDB, mobile string) (err error) {
|
||||
// countInfo := &struct{ Ct int }{}
|
||||
// if err = dao.GetRow(db, countInfo, `
|
||||
// SELECT COUNT(*) ct
|
||||
// FROM weixins t1
|
||||
// JOIN weixins t2 ON t1.parentid = t2.id AND t2.tel = ?
|
||||
// `, mobile); err == nil {
|
||||
// if countInfo.Ct > 0 {
|
||||
// user := &legacymodel.WeiXins{
|
||||
// Tel: mobile,
|
||||
// }
|
||||
// dao.GetEntity(db, user, "Tel")
|
||||
// err = fmt.Errorf("%s本身已经是门店:%d组长", mobile, user.JxStoreID)
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
@@ -5,9 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
@@ -63,11 +61,13 @@ func New(notUsed interface{}, token string, w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
}
|
||||
} else {
|
||||
userInfo, err2 := auth.GetUserInfo(token)
|
||||
if err = err2; err == nil {
|
||||
// globals.SugarLogger.Debugf("jxcontext New, V1 authInfo:%s", utils.Format4Output(userInfo, true))
|
||||
ctx.userInfo = userInfo
|
||||
}
|
||||
globals.SugarLogger.Warnf("jxcontext wrong token:%s", token)
|
||||
errCode = model.ErrCodeTokenIsInvalid
|
||||
// userInfo, err2 := auth.GetUserInfo(token)
|
||||
// if err = err2; err == nil {
|
||||
// // globals.SugarLogger.Debugf("jxcontext New, V1 authInfo:%s", utils.Format4Output(userInfo, true))
|
||||
// ctx.userInfo = userInfo
|
||||
// }
|
||||
}
|
||||
if err == model.ErrTokenIsInvalid {
|
||||
if !globals.IsProductEnv() {
|
||||
@@ -142,14 +142,6 @@ func (ctx *Context) GetMobileAndUserID() (mobile, userID string) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
userInfo, err2 := auth.GetUserInfo(token)
|
||||
if err2 == nil {
|
||||
if mobile = userInfo.GetAuthID(); mobile != "" {
|
||||
if user, err := dao.GetUserByID(dao.GetDB(), "mobile", mobile); err == nil {
|
||||
userID = user.UserID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mobile, userID
|
||||
}
|
||||
|
||||
@@ -448,13 +448,13 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string, mobileIsUerID bool) (err e
|
||||
storeID := 0
|
||||
remark := ""
|
||||
|
||||
if !globals.DisableWXAuth1 {
|
||||
wxinfo, err := dao.GetUserStoreInfo(db, "tel", mobile)
|
||||
if err == nil {
|
||||
openIDs = []string{wxinfo.OpenID}
|
||||
storeID = wxinfo.JxStoreID
|
||||
}
|
||||
}
|
||||
// if !globals.DisableWXAuth1 {
|
||||
// wxinfo, err := dao.GetUserStoreInfo(db, "tel", mobile)
|
||||
// if err == nil {
|
||||
// openIDs = []string{wxinfo.OpenID}
|
||||
// storeID = wxinfo.JxStoreID
|
||||
// }
|
||||
// }
|
||||
if globals.EnableWXAuth2 {
|
||||
userID := ""
|
||||
if mobileIsUerID {
|
||||
|
||||
@@ -89,33 +89,33 @@ var (
|
||||
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
|
||||
db := dao.GetDB()
|
||||
openIDMap := make(map[string]int)
|
||||
if !globals.DisableWXAuth1 {
|
||||
var openIDList []string
|
||||
sql := `
|
||||
SELECT openid
|
||||
FROM weixins t1
|
||||
JOIN
|
||||
(SELECT id
|
||||
FROM weixins
|
||||
WHERE jxstoreid = ? AND parentid = -1) t2 ON t2.id = t1.parentid
|
||||
WHERE openid IS NOT NULL
|
||||
UNION
|
||||
SELECT openid
|
||||
FROM weixins
|
||||
WHERE jxstoreid = ? AND parentid = -1 AND openid IS NOT NULL`
|
||||
sqlParams := []interface{}{
|
||||
storeID,
|
||||
storeID,
|
||||
}
|
||||
err := dao.GetRows(db, &openIDList, sql, sqlParams...)
|
||||
if err != nil || len(openIDList) == 0 {
|
||||
globals.SugarLogger.Infof("GetWeixinOpenIDsFromStoreID can not find openid for store:%d, num:%d, error:%v", storeID, len(openIDList), err)
|
||||
return retVal
|
||||
}
|
||||
for _, v := range openIDList {
|
||||
openIDMap[v] = 1
|
||||
}
|
||||
}
|
||||
// if !globals.DisableWXAuth1 {
|
||||
// var openIDList []string
|
||||
// sql := `
|
||||
// SELECT openid
|
||||
// FROM weixins t1
|
||||
// JOIN
|
||||
// (SELECT id
|
||||
// FROM weixins
|
||||
// WHERE jxstoreid = ? AND parentid = -1) t2 ON t2.id = t1.parentid
|
||||
// WHERE openid IS NOT NULL
|
||||
// UNION
|
||||
// SELECT openid
|
||||
// FROM weixins
|
||||
// WHERE jxstoreid = ? AND parentid = -1 AND openid IS NOT NULL`
|
||||
// sqlParams := []interface{}{
|
||||
// storeID,
|
||||
// storeID,
|
||||
// }
|
||||
// err := dao.GetRows(db, &openIDList, sql, sqlParams...)
|
||||
// if err != nil || len(openIDList) == 0 {
|
||||
// globals.SugarLogger.Infof("GetWeixinOpenIDsFromStoreID can not find openid for store:%d, num:%d, error:%v", storeID, len(openIDList), err)
|
||||
// return retVal
|
||||
// }
|
||||
// for _, v := range openIDList {
|
||||
// openIDMap[v] = 1
|
||||
// }
|
||||
// }
|
||||
if globals.EnableWXAuth2 {
|
||||
if userIDList, err2 := api2.RoleMan.GetRoleUserList(autils.NewStoreBossRole(storeID)); err2 == nil {
|
||||
for _, v := range userIDList {
|
||||
|
||||
@@ -1,182 +1,111 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// type StoreUserInfo struct {
|
||||
// legacymodel.WeiXins
|
||||
// ParentMobile string `json:"parentMobile"`
|
||||
// Members []*legacymodel.WeiXins `orm:"-" json:"members"`
|
||||
// MembersStr string `json:"-"`
|
||||
// }
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
)
|
||||
// func CreateWeiXins(db *DaoDB, user *legacymodel.WeiXins) (err error) {
|
||||
// Begin(db)
|
||||
// if err = CreateEntity(db, user); err != nil {
|
||||
// Rollback(db)
|
||||
// return err
|
||||
// }
|
||||
// if err = SetWeiXinsEmpty2Null(db, user); err != nil {
|
||||
// Rollback(db)
|
||||
// return err
|
||||
// }
|
||||
// Commit(db)
|
||||
// return err
|
||||
// }
|
||||
|
||||
type StoreUserInfo struct {
|
||||
legacymodel.WeiXins
|
||||
ParentMobile string `json:"parentMobile"`
|
||||
Members []*legacymodel.WeiXins `orm:"-" json:"members"`
|
||||
MembersStr string `json:"-"`
|
||||
}
|
||||
// func SetWeiXinsEmpty2Null(db *DaoDB, user *legacymodel.WeiXins) (err error) {
|
||||
// _, err = ExecuteSQL(db, `
|
||||
// UPDATE weixins
|
||||
// SET
|
||||
// openid = IF(openid = '', NULL, openid),
|
||||
// openid_mini = IF(openid_mini = '', NULL, openid_mini),
|
||||
// openid_union = IF(openid_union = '', NULL, openid_union),
|
||||
// tel = IF(tel = '', NULL, tel),
|
||||
// parentid = IF(parentid = 0, -1, parentid)
|
||||
// WHERE id = ?
|
||||
// `, user.ID)
|
||||
// return err
|
||||
// }
|
||||
|
||||
type StoreWithCityName struct {
|
||||
model.Store
|
||||
CityName string `json:"cityName"`
|
||||
}
|
||||
// func GetWeiXinUserByIDs(db *DaoDB, tel, unionID, openID, miniOpenID string) (user *legacymodel.WeiXins, err error) {
|
||||
// fieldList := []string{
|
||||
// "Tel",
|
||||
// "OpenIDUnion",
|
||||
// "OpenID",
|
||||
// "OpenIDMini",
|
||||
// }
|
||||
// valueList := []string{
|
||||
// tel,
|
||||
// unionID,
|
||||
// openID,
|
||||
// miniOpenID,
|
||||
// }
|
||||
// user = &legacymodel.WeiXins{
|
||||
// Tel: tel,
|
||||
// OpenIDUnion: unionID,
|
||||
// OpenID: openID,
|
||||
// OpenIDMini: miniOpenID,
|
||||
// }
|
||||
// for index := range valueList {
|
||||
// if valueList[index] != "" {
|
||||
// if err = GetEntity(db, user, fieldList[index]); err == nil {
|
||||
// return user, nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
func CreateWeiXins(db *DaoDB, user *legacymodel.WeiXins) (err error) {
|
||||
Begin(db)
|
||||
if err = CreateEntity(db, user); err != nil {
|
||||
Rollback(db)
|
||||
return err
|
||||
}
|
||||
if err = SetWeiXinsEmpty2Null(db, user); err != nil {
|
||||
Rollback(db)
|
||||
return err
|
||||
}
|
||||
Commit(db)
|
||||
return err
|
||||
}
|
||||
// func UpdateWeiXinUser(db *DaoDB, tel, nickname, unionID, openID, miniOpenID string) (err error) {
|
||||
// user := &legacymodel.WeiXins{
|
||||
// Tel: tel,
|
||||
// }
|
||||
// if err = GetEntity(db, user, "Tel"); err == nil {
|
||||
// updateFields := []string{}
|
||||
// if openID != "" {
|
||||
// user.OpenID = openID
|
||||
// updateFields = append(updateFields, "OpenID")
|
||||
// }
|
||||
// if unionID != "" {
|
||||
// user.OpenIDUnion = unionID
|
||||
// updateFields = append(updateFields, "OpenIDUnion")
|
||||
// }
|
||||
// if miniOpenID != "" {
|
||||
// user.OpenIDMini = miniOpenID
|
||||
// updateFields = append(updateFields, "OpenIDMini")
|
||||
// }
|
||||
// if nickname != "" {
|
||||
// user.NickName = nickname
|
||||
// updateFields = append(updateFields, "NickName")
|
||||
// }
|
||||
// _, err = UpdateEntity(db, user, updateFields...)
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func SetWeiXinsEmpty2Null(db *DaoDB, user *legacymodel.WeiXins) (err error) {
|
||||
_, err = ExecuteSQL(db, `
|
||||
UPDATE weixins
|
||||
SET
|
||||
openid = IF(openid = '', NULL, openid),
|
||||
openid_mini = IF(openid_mini = '', NULL, openid_mini),
|
||||
openid_union = IF(openid_union = '', NULL, openid_union),
|
||||
tel = IF(tel = '', NULL, tel),
|
||||
parentid = IF(parentid = 0, -1, parentid)
|
||||
WHERE id = ?
|
||||
`, user.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetWeiXinUserByIDs(db *DaoDB, tel, unionID, openID, miniOpenID string) (user *legacymodel.WeiXins, err error) {
|
||||
fieldList := []string{
|
||||
"Tel",
|
||||
"OpenIDUnion",
|
||||
"OpenID",
|
||||
"OpenIDMini",
|
||||
}
|
||||
valueList := []string{
|
||||
tel,
|
||||
unionID,
|
||||
openID,
|
||||
miniOpenID,
|
||||
}
|
||||
user = &legacymodel.WeiXins{
|
||||
Tel: tel,
|
||||
OpenIDUnion: unionID,
|
||||
OpenID: openID,
|
||||
OpenIDMini: miniOpenID,
|
||||
}
|
||||
for index := range valueList {
|
||||
if valueList[index] != "" {
|
||||
if err = GetEntity(db, user, fieldList[index]); err == nil {
|
||||
return user, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func UpdateWeiXinUser(db *DaoDB, tel, nickname, unionID, openID, miniOpenID string) (err error) {
|
||||
user := &legacymodel.WeiXins{
|
||||
Tel: tel,
|
||||
}
|
||||
if err = GetEntity(db, user, "Tel"); err == nil {
|
||||
updateFields := []string{}
|
||||
if openID != "" {
|
||||
user.OpenID = openID
|
||||
updateFields = append(updateFields, "OpenID")
|
||||
}
|
||||
if unionID != "" {
|
||||
user.OpenIDUnion = unionID
|
||||
updateFields = append(updateFields, "OpenIDUnion")
|
||||
}
|
||||
if miniOpenID != "" {
|
||||
user.OpenIDMini = miniOpenID
|
||||
updateFields = append(updateFields, "OpenIDMini")
|
||||
}
|
||||
if nickname != "" {
|
||||
user.NickName = nickname
|
||||
updateFields = append(updateFields, "NickName")
|
||||
}
|
||||
_, err = UpdateEntity(db, user, updateFields...)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserStoreInfo(db *DaoDB, fieldName, fieldValue string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT t1.id, IF(t3.id IS NULL, t1.jxstoreid, t3.jxstoreid) jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
FROM weixins t1
|
||||
LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
||||
LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
||||
WHERE t1.%s = ?
|
||||
GROUP BY 1,2,3,4,5,6,7;
|
||||
`, fieldName)
|
||||
if err = GetRow(db, &storeUserInfo, sql, fieldValue); err == nil { // todo
|
||||
err = nil
|
||||
if storeUserInfo.MembersStr != "" {
|
||||
err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
}
|
||||
}
|
||||
return storeUserInfo, err
|
||||
}
|
||||
|
||||
func GetStoreListByMobile(db *DaoDB, mobile string) (storeList []*StoreWithCityName, err error) {
|
||||
if mobile != "" {
|
||||
sql := `
|
||||
SELECT
|
||||
DISTINCT t1.*, t2.name city_name
|
||||
FROM (
|
||||
SELECT *
|
||||
FROM store t1
|
||||
WHERE (t1.market_man_phone = ? OR t1.operator_phone = ?)
|
||||
UNION DISTINCT
|
||||
SELECT t1.*
|
||||
FROM store t1
|
||||
JOIN weixins t2 ON t2.jxstoreid = t1.id AND t2.parentid = -1
|
||||
LEFT JOIN weixins t3 ON t3.parentid = t2.id
|
||||
WHERE (t2.tel = ? OR t3.tel = ?)
|
||||
) t1
|
||||
LEFT JOIN place t2 ON t2.code = t1.city_code
|
||||
WHERE t1.deleted_at = ?
|
||||
ORDER BY t1.name`
|
||||
sqlParams := []interface{}{
|
||||
mobile,
|
||||
mobile,
|
||||
mobile,
|
||||
mobile,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
err = GetRows(db, &storeList, sql, sqlParams...)
|
||||
}
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
func GetStoreListByMobileOrStoreIDs(db *DaoDB, mobile string, shortRoleNameList []string, storeIDs []int) (storeList []*StoreWithCityName, err error) {
|
||||
sql := `
|
||||
SELECT t1.*, t2.name city_name
|
||||
FROM store t1
|
||||
LEFT JOIN place t2 ON t2.code = t1.city_code
|
||||
WHERE t1.deleted_at = ? AND ( 1 = 0`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if mobile != "" {
|
||||
sql += " OR t1.market_man_phone = ? OR t1.operator_phone = ?"
|
||||
sqlParams = append(sqlParams, mobile, mobile)
|
||||
}
|
||||
if len(shortRoleNameList) > 0 {
|
||||
questionMarks := GenQuestionMarks(len(shortRoleNameList))
|
||||
sql += " OR t1.market_man_role IN (" + questionMarks + ") OR t1.operator_role IN (" + questionMarks + ") OR t1.operator_role2 IN (" + questionMarks + ")"
|
||||
sqlParams = append(sqlParams, shortRoleNameList, shortRoleNameList, shortRoleNameList)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " OR t1.id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
sql += ")"
|
||||
err = GetRows(db, &storeList, sql, sqlParams...)
|
||||
return storeList, err
|
||||
}
|
||||
// func GetUserStoreInfo(db *DaoDB, fieldName, fieldValue string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
// sql := fmt.Sprintf(`
|
||||
// SELECT t1.id, IF(t3.id IS NULL, t1.jxstoreid, t3.jxstoreid) jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
// CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
// FROM weixins t1
|
||||
// LEFT JOIN weixins t2 ON t2.parentid = t1.id
|
||||
// LEFT JOIN weixins t3 ON t1.parentid = t3.id
|
||||
// WHERE t1.%s = ?
|
||||
// GROUP BY 1,2,3,4,5,6,7;
|
||||
// `, fieldName)
|
||||
// if err = GetRow(db, &storeUserInfo, sql, fieldValue); err == nil { // todo
|
||||
// err = nil
|
||||
// if storeUserInfo.MembersStr != "" {
|
||||
// err = utils.UnmarshalUseNumber([]byte(storeUserInfo.MembersStr), &storeUserInfo.Members)
|
||||
// }
|
||||
// }
|
||||
// return storeUserInfo, err
|
||||
// }
|
||||
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type StoreWithCityName struct {
|
||||
model.Store
|
||||
CityName string `json:"cityName"`
|
||||
}
|
||||
|
||||
func GetUserByID(db *DaoDB, fieldName, fieldValue string) (user *model.User, err error) {
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT *
|
||||
@@ -85,3 +90,61 @@ func DeleteUsers(db *DaoDB, userIDs []string) (num int64, err error) {
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetStoreListByMobile(db *DaoDB, mobile string) (storeList []*StoreWithCityName, err error) {
|
||||
if mobile != "" {
|
||||
sql := `
|
||||
SELECT
|
||||
DISTINCT t1.*, t2.name city_name
|
||||
FROM (
|
||||
SELECT *
|
||||
FROM store t1
|
||||
WHERE (t1.market_man_phone = ? OR t1.operator_phone = ?)
|
||||
UNION DISTINCT
|
||||
SELECT t1.*
|
||||
FROM store t1
|
||||
JOIN weixins t2 ON t2.jxstoreid = t1.id AND t2.parentid = -1
|
||||
LEFT JOIN weixins t3 ON t3.parentid = t2.id
|
||||
WHERE (t2.tel = ? OR t3.tel = ?)
|
||||
) t1
|
||||
LEFT JOIN place t2 ON t2.code = t1.city_code
|
||||
WHERE t1.deleted_at = ?
|
||||
ORDER BY t1.name`
|
||||
sqlParams := []interface{}{
|
||||
mobile,
|
||||
mobile,
|
||||
mobile,
|
||||
mobile,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
err = GetRows(db, &storeList, sql, sqlParams...)
|
||||
}
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
func GetStoreListByMobileOrStoreIDs(db *DaoDB, mobile string, shortRoleNameList []string, storeIDs []int) (storeList []*StoreWithCityName, err error) {
|
||||
sql := `
|
||||
SELECT t1.*, t2.name city_name
|
||||
FROM store t1
|
||||
LEFT JOIN place t2 ON t2.code = t1.city_code
|
||||
WHERE t1.deleted_at = ? AND ( 1 = 0`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if mobile != "" {
|
||||
sql += " OR t1.market_man_phone = ? OR t1.operator_phone = ?"
|
||||
sqlParams = append(sqlParams, mobile, mobile)
|
||||
}
|
||||
if len(shortRoleNameList) > 0 {
|
||||
questionMarks := GenQuestionMarks(len(shortRoleNameList))
|
||||
sql += " OR t1.market_man_role IN (" + questionMarks + ") OR t1.operator_role IN (" + questionMarks + ") OR t1.operator_role2 IN (" + questionMarks + ")"
|
||||
sqlParams = append(sqlParams, shortRoleNameList, shortRoleNameList, shortRoleNameList)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " OR t1.id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
sql += ")"
|
||||
err = GetRows(db, &storeList, sql, sqlParams...)
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
@@ -1,41 +1,33 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"testing"
|
||||
// func TestCreateWeiXins(t *testing.T) {
|
||||
// err := CreateWeiXins(GetDB(), &legacymodel.WeiXins{
|
||||
// Tel: "12345",
|
||||
// })
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
// func TestGetWeiXinUserByIDs(t *testing.T) {
|
||||
// user, err := GetWeiXinUserByIDs(GetDB(), "", "unionid", "", "")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
// }
|
||||
|
||||
func TestCreateWeiXins(t *testing.T) {
|
||||
err := CreateWeiXins(GetDB(), &legacymodel.WeiXins{
|
||||
Tel: "12345",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// func TestUpdateWeiXinUser(t *testing.T) {
|
||||
// err := UpdateWeiXinUser(GetDB(), "12345", "nickname", "unionid", "openid", "miniid")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestGetWeiXinUserByIDs(t *testing.T) {
|
||||
user, err := GetWeiXinUserByIDs(GetDB(), "", "unionid", "", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
}
|
||||
|
||||
func TestUpdateWeiXinUser(t *testing.T) {
|
||||
err := UpdateWeiXinUser(GetDB(), "12345", "nickname", "unionid", "openid", "miniid")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUserStoreInfo(t *testing.T) {
|
||||
user, err := GetUserStoreInfo(GetDB(), "tel", "18180948107")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
}
|
||||
// func TestGetUserStoreInfo(t *testing.T) {
|
||||
// user, err := GetUserStoreInfo(GetDB(), "tel", "18180948107")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
// }
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
@@ -11,12 +12,28 @@ import (
|
||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile" // 强制导入mobile认证方式
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/password"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
func GetComposedCode(c *beego.Controller, code string) (composedCode string) {
|
||||
composedCode = code
|
||||
referer := c.Ctx.Request.Referer()
|
||||
globals.SugarLogger.Debugf("GetComposedCode referer:%s", referer)
|
||||
index := strings.Index(referer, "//")
|
||||
if index > 0 {
|
||||
list := strings.Split(referer[index+2:], "/")
|
||||
if len(list) >= 2 {
|
||||
composedCode = strings.Join([]string{
|
||||
list[1],
|
||||
code,
|
||||
}, ",")
|
||||
}
|
||||
}
|
||||
return composedCode
|
||||
}
|
||||
|
||||
type Auth2Controller struct {
|
||||
beego.Controller
|
||||
}
|
||||
@@ -84,10 +101,10 @@ func (c *Auth2Controller) Login() {
|
||||
// @router /GetTokenInfo [get]
|
||||
func (c *Auth2Controller) GetTokenInfo() {
|
||||
c.callGetTokenInfo(func(params *tAuth2GetTokenInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
if auth2.IsV2Token(params.Token) {
|
||||
if true { //auth2.IsV2Token(params.Token) {
|
||||
retVal, err = auth2.GetTokenInfo(params.Token)
|
||||
} else {
|
||||
retVal, err = auth.GetUserInfo(params.Token)
|
||||
// retVal, err = auth.GetUserInfo(params.Token)
|
||||
}
|
||||
if err == model.ErrTokenIsInvalid {
|
||||
errCode = model.ErrCodeTokenIsInvalid
|
||||
@@ -214,7 +231,7 @@ func (c *Auth2Controller) Logout() {
|
||||
if authInfo, ok := params.Ctx.GetLoginInfo().(*auth2.AuthInfo); ok {
|
||||
err = auth2.Logout(authInfo)
|
||||
} else {
|
||||
err = auth.Logout(params.Token)
|
||||
// err = auth.Logout(params.Token)
|
||||
}
|
||||
return nil, "", err
|
||||
})
|
||||
|
||||
@@ -1,238 +1,205 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
// type WeixinCallbackResult struct {
|
||||
// Code int `json:"code"`
|
||||
// Msg string `json:"msg"`
|
||||
// Data interface{} `json:"data"`
|
||||
// }
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/mobile"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
// // 认证相关API
|
||||
// type AuthController struct {
|
||||
// beego.Controller
|
||||
// }
|
||||
|
||||
type WeixinCallbackResult struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
// var (
|
||||
// ErrParameterIsIllegal = "参数不全或不合法"
|
||||
// )
|
||||
|
||||
// 认证相关API
|
||||
type AuthController struct {
|
||||
beego.Controller
|
||||
}
|
||||
// // @Title 给微信用的回调接口
|
||||
// // @Description 给微信用的回调接口,自己不能直接调用
|
||||
// // @Param code query string true "客户同意后得到的code"
|
||||
// // @Param block query string true "回调地址"
|
||||
// // @Param state query string false "微信回调的登录状态"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /GetWeiXinUserInfo [get]
|
||||
// func (c *AuthController) GetWeiXinUserInfo() {
|
||||
// retVal := &WeixinCallbackResult{}
|
||||
// var err error
|
||||
// code := c.GetString("code")
|
||||
// block := c.GetString("block")
|
||||
// state := c.GetString("state")
|
||||
// if block != "" {
|
||||
// if code != "" {
|
||||
// result, err2 := weixin.GetWeiXinUserInfo(code, state)
|
||||
// if err = err2; err == nil {
|
||||
// retVal.Code = 1
|
||||
// retVal.Msg = "微信登录成功"
|
||||
// retVal.Data = result
|
||||
// } else {
|
||||
// retVal.Msg = err.Error()
|
||||
// }
|
||||
// } else {
|
||||
// retVal.Msg = "code为空"
|
||||
// }
|
||||
// } else {
|
||||
// retVal.Msg = "没有block"
|
||||
// }
|
||||
// redirectURL := fmt.Sprintf("%s?info=%s", block, base64.StdEncoding.EncodeToString(utils.MustMarshal(retVal)))
|
||||
// globals.SugarLogger.Debugf("auth GetWeiXinUserInfo retVal:%s, redirectURL:%s", utils.Format4Output(retVal, true), redirectURL)
|
||||
// c.Redirect(redirectURL, http.StatusTemporaryRedirect)
|
||||
// }
|
||||
|
||||
var (
|
||||
ErrParameterIsIllegal = "参数不全或不合法"
|
||||
)
|
||||
// // @Title 登录接口
|
||||
// // @Description 登录接口
|
||||
// // @Param id formData string false "登录ID"
|
||||
// // @Param type formData string true "登录类型,当前支持[weixinsns:微信公众号登录,localpass:本地账号密码,mobile:手机短信,weixinmini;小程序code登录]"
|
||||
// // @Param secret formData string true "不同登录类型的登录秘密"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /Login [post]
|
||||
// func (c *AuthController) Login() {
|
||||
// c.callLogin(func(params *tAuthLoginParams) (retVal interface{}, errCode string, err error) {
|
||||
// if params.Type == weixin.LoginTypeMiniProgram {
|
||||
// params.Secret = GetComposedCode(&c.Controller, params.Secret)
|
||||
// }
|
||||
// retVal, err = auth.Login(params.Id, params.Type, params.Secret)
|
||||
// if err == auth.ErrUserNotExist {
|
||||
// return retVal, model.ErrCodeUserNotExist, err
|
||||
// }
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 给微信用的回调接口
|
||||
// @Description 给微信用的回调接口,自己不能直接调用
|
||||
// @Param code query string true "客户同意后得到的code"
|
||||
// @Param block query string true "回调地址"
|
||||
// @Param state query string false "微信回调的登录状态"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetWeiXinUserInfo [get]
|
||||
func (c *AuthController) GetWeiXinUserInfo() {
|
||||
retVal := &WeixinCallbackResult{}
|
||||
var err error
|
||||
code := c.GetString("code")
|
||||
block := c.GetString("block")
|
||||
state := c.GetString("state")
|
||||
if block != "" {
|
||||
if code != "" {
|
||||
result, err2 := weixin.GetWeiXinUserInfo(code, state)
|
||||
if err = err2; err == nil {
|
||||
retVal.Code = 1
|
||||
retVal.Msg = "微信登录成功"
|
||||
retVal.Data = result
|
||||
} else {
|
||||
retVal.Msg = err.Error()
|
||||
}
|
||||
} else {
|
||||
retVal.Msg = "code为空"
|
||||
}
|
||||
} else {
|
||||
retVal.Msg = "没有block"
|
||||
}
|
||||
redirectURL := fmt.Sprintf("%s?info=%s", block, base64.StdEncoding.EncodeToString(utils.MustMarshal(retVal)))
|
||||
globals.SugarLogger.Debugf("auth GetWeiXinUserInfo retVal:%s, redirectURL:%s", utils.Format4Output(retVal, true), redirectURL)
|
||||
c.Redirect(redirectURL, http.StatusTemporaryRedirect)
|
||||
}
|
||||
// // @Title 登出接口
|
||||
// // @Description 登出接口
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /Logout [delete]
|
||||
// func (c *AuthController) Logout() {
|
||||
// c.callLogout(func(params *tAuthLogoutParams) (retVal interface{}, errCode string, err error) {
|
||||
// err = auth.Logout(params.Token)
|
||||
// globals.SugarLogger.Debug(err)
|
||||
// return nil, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 登录接口
|
||||
// @Description 登录接口
|
||||
// @Param id formData string false "登录ID"
|
||||
// @Param type formData string true "登录类型,当前支持[weixinsns:微信公众号登录,localpass:本地账号密码,mobile:手机短信,weixinmini;小程序code登录]"
|
||||
// @Param secret formData string true "不同登录类型的登录秘密"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Login [post]
|
||||
func (c *AuthController) Login() {
|
||||
c.callLogin(func(params *tAuthLoginParams) (retVal interface{}, errCode string, err error) {
|
||||
if params.Type == weixin.LoginTypeMiniProgram {
|
||||
params.Secret = GetComposedCode(&c.Controller, params.Secret)
|
||||
}
|
||||
retVal, err = auth.Login(params.Id, params.Type, params.Secret)
|
||||
if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 得到用户信息
|
||||
// // @Description 得到用户信息(从token中)
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /GetUserInfo [get]
|
||||
// func (c *AuthController) GetUserInfo() {
|
||||
// c.callGetUserInfo(func(params *tAuthGetUserInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = auth.GetUserInfo(params.Token)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 登出接口
|
||||
// @Description 登出接口
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Logout [delete]
|
||||
func (c *AuthController) Logout() {
|
||||
c.callLogout(func(params *tAuthLogoutParams) (retVal interface{}, errCode string, err error) {
|
||||
err = auth.Logout(params.Token)
|
||||
globals.SugarLogger.Debug(err)
|
||||
return nil, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 发送验证码
|
||||
// // @Description 发送验证码
|
||||
// // @Param mobile formData string true "手机号"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /SendMobileVerifyCode [post]
|
||||
// func (c *AuthController) SendMobileVerifyCode() {
|
||||
// c.callSendMobileVerifyCode(func(params *tAuthSendMobileVerifyCodeParams) (retVal interface{}, errCode string, err error) {
|
||||
// err = mobile.SendVerifyCode(params.Mobile)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 得到用户信息
|
||||
// @Description 得到用户信息(从token中)
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetUserInfo [get]
|
||||
func (c *AuthController) GetUserInfo() {
|
||||
c.callGetUserInfo(func(params *tAuthGetUserInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = auth.GetUserInfo(params.Token)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 绑定手机
|
||||
// // @Description 绑定手机,待删除
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param mobile formData string true "手机号"
|
||||
// // @Param code formData string true "验证码"
|
||||
// // @Param nickname formData string false "用户名"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /BindMobile [post]
|
||||
// func (c *AuthController) BindMobile() {
|
||||
// c.callBindMobile(func(params *tAuthBindMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
// err = weixin.BindMobile(params.Token, params.Mobile, params.Code, params.Nickname)
|
||||
// if err == auth.ErrUserNotExist {
|
||||
// return retVal, model.ErrCodeUserNotExist, err
|
||||
// }
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 发送验证码
|
||||
// @Description 发送验证码
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SendMobileVerifyCode [post]
|
||||
func (c *AuthController) SendMobileVerifyCode() {
|
||||
c.callSendMobileVerifyCode(func(params *tAuthSendMobileVerifyCodeParams) (retVal interface{}, errCode string, err error) {
|
||||
err = mobile.SendVerifyCode(params.Mobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 微信公众号绑定手机2
|
||||
// // @Description 微信公众号绑定手机2
|
||||
// // @Param openID formData string true "微信公众号ID"
|
||||
// // @Param secret formData string true "后台之前返回的secret"
|
||||
// // @Param nickname formData string false "用户名"
|
||||
// // @Param mobile formData string true "手机号"
|
||||
// // @Param verifyCode formData string true "手机验证码"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /BindMobile2 [post]
|
||||
// func (c *AuthController) BindMobile2() {
|
||||
// c.callBindMobile2(func(params *tAuthBindMobile2Params) (retVal interface{}, errCode string, err error) {
|
||||
// if retVal, err = weixin.BindMobile2(params.OpenID, params.Secret, params.Mobile, params.VerifyCode, params.Nickname); err == nil {
|
||||
// cms.TransferLegacyWeixins(params.Mobile)
|
||||
// } else if err == auth.ErrUserNotExist {
|
||||
// return retVal, model.ErrCodeUserNotExist, err
|
||||
// }
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 绑定手机
|
||||
// @Description 绑定手机,待删除
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Param code formData string true "验证码"
|
||||
// @Param nickname formData string false "用户名"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /BindMobile [post]
|
||||
func (c *AuthController) BindMobile() {
|
||||
c.callBindMobile(func(params *tAuthBindMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
err = weixin.BindMobile(params.Token, params.Mobile, params.Code, params.Nickname)
|
||||
if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 绑定手机
|
||||
// // @Description 绑定手机(调用此方法前先需要以短信方式登录),待删除
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param code formData string true "小程序用户code"
|
||||
// // @Param nickname formData string false "用户名"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /MiniBindWeiXin [post]
|
||||
// func (c *AuthController) MiniBindWeiXin() {
|
||||
// c.callMiniBindWeiXin(func(params *tAuthMiniBindWeiXinParams) (retVal interface{}, errCode string, err error) {
|
||||
// err = weixin.AutherMini.BindWeiXin(params.Ctx, GetComposedCode(&c.Controller, params.Code), params.Nickname)
|
||||
// if err == auth.ErrUserNotExist {
|
||||
// return retVal, model.ErrCodeUserNotExist, err
|
||||
// }
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 微信公众号绑定手机2
|
||||
// @Description 微信公众号绑定手机2
|
||||
// @Param openID formData string true "微信公众号ID"
|
||||
// @Param secret formData string true "后台之前返回的secret"
|
||||
// @Param nickname formData string false "用户名"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Param verifyCode formData string true "手机验证码"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /BindMobile2 [post]
|
||||
func (c *AuthController) BindMobile2() {
|
||||
c.callBindMobile2(func(params *tAuthBindMobile2Params) (retVal interface{}, errCode string, err error) {
|
||||
if retVal, err = weixin.BindMobile2(params.OpenID, params.Secret, params.Mobile, params.VerifyCode, params.Nickname); err == nil {
|
||||
cms.TransferLegacyWeixins(params.Mobile)
|
||||
} else if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 绑定小程序
|
||||
// // @Description 绑定小程序
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param code formData string true "小程序用户code"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /BindMiniProgram [post]
|
||||
// func (c *AuthController) BindMiniProgram() {
|
||||
// c.callBindMiniProgram(func(params *tAuthBindMiniProgramParams) (retVal interface{}, errCode string, err error) {
|
||||
// err = weixin.AutherMini.BindMiniProgram(params.Ctx, GetComposedCode(&c.Controller, params.Code))
|
||||
// if err == nil {
|
||||
// cms.TransferLegacyWeixins(params.Ctx.GetLoginID())
|
||||
// }
|
||||
// if err == auth.ErrUserNotExist {
|
||||
// return retVal, model.ErrCodeUserNotExist, err
|
||||
// }
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 绑定手机
|
||||
// @Description 绑定手机(调用此方法前先需要以短信方式登录),待删除
|
||||
// @Param token header string true "认证token"
|
||||
// @Param code formData string true "小程序用户code"
|
||||
// @Param nickname formData string false "用户名"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /MiniBindWeiXin [post]
|
||||
func (c *AuthController) MiniBindWeiXin() {
|
||||
c.callMiniBindWeiXin(func(params *tAuthMiniBindWeiXinParams) (retVal interface{}, errCode string, err error) {
|
||||
err = weixin.AutherMini.BindWeiXin(params.Ctx, GetComposedCode(&c.Controller, params.Code), params.Nickname)
|
||||
if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 绑定小程序
|
||||
// @Description 绑定小程序
|
||||
// @Param token header string true "认证token"
|
||||
// @Param code formData string true "小程序用户code"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /BindMiniProgram [post]
|
||||
func (c *AuthController) BindMiniProgram() {
|
||||
c.callBindMiniProgram(func(params *tAuthBindMiniProgramParams) (retVal interface{}, errCode string, err error) {
|
||||
err = weixin.AutherMini.BindMiniProgram(params.Ctx, GetComposedCode(&c.Controller, params.Code))
|
||||
if err == nil {
|
||||
cms.TransferLegacyWeixins(params.Ctx.GetLoginID())
|
||||
}
|
||||
if err == auth.ErrUserNotExist {
|
||||
return retVal, model.ErrCodeUserNotExist, err
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 解密小程序数据
|
||||
// @Description 解密小程序数据
|
||||
// @Param token header string true "认证token"
|
||||
// @Param data formData string true "加密数据"
|
||||
// @Param iv formData string true "iv"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /MiniDecryptData [post]
|
||||
func (c *AuthController) MiniDecryptData() {
|
||||
c.callMiniDecryptData(func(params *tAuthMiniDecryptDataParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = weixin.AutherMini.DecryptData(params.Ctx, params.Data, params.Iv)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
func GetComposedCode(c *beego.Controller, code string) (composedCode string) {
|
||||
composedCode = code
|
||||
referer := c.Ctx.Request.Referer()
|
||||
globals.SugarLogger.Debugf("GetComposedCode referer:%s", referer)
|
||||
index := strings.Index(referer, "//")
|
||||
if index > 0 {
|
||||
list := strings.Split(referer[index+2:], "/")
|
||||
if len(list) >= 2 {
|
||||
composedCode = strings.Join([]string{
|
||||
list[1],
|
||||
code,
|
||||
}, ",")
|
||||
}
|
||||
}
|
||||
return composedCode
|
||||
}
|
||||
// // @Title 解密小程序数据
|
||||
// // @Description 解密小程序数据
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param data formData string true "加密数据"
|
||||
// // @Param iv formData string true "iv"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /MiniDecryptData [post]
|
||||
// func (c *AuthController) MiniDecryptData() {
|
||||
// c.callMiniDecryptData(func(params *tAuthMiniDecryptDataParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = weixin.AutherMini.DecryptData(params.Ctx, params.Data, params.Iv)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
@@ -1,123 +1,118 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
// type UserController struct {
|
||||
// beego.Controller
|
||||
// }
|
||||
|
||||
type UserController struct {
|
||||
beego.Controller
|
||||
}
|
||||
// // @Title 得到门店用户信息
|
||||
// // @Description 得到门店用户信息
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param storeID query int true "门店号"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpGetStoreUsers [get]
|
||||
// func (c *UserController) TmpGetStoreUsers() {
|
||||
// c.callTmpGetStoreUsers(func(params *tUserTmpGetStoreUsersParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.GetStoreUsers(params.Ctx, params.StoreID)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 得到门店用户信息
|
||||
// @Description 得到门店用户信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID query int true "门店号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpGetStoreUsers [get]
|
||||
func (c *UserController) TmpGetStoreUsers() {
|
||||
c.callTmpGetStoreUsers(func(params *tUserTmpGetStoreUsersParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetStoreUsers(params.Ctx, params.StoreID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 得到用户门店及成员信息
|
||||
// // @Description 得到用户门店及成员信息
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param mobile query string true "手机号"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpGetUserInfo [get]
|
||||
// func (c *UserController) TmpGetUserInfo() {
|
||||
// c.callTmpGetUserInfo(func(params *tUserTmpGetUserInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.GetUserInfo(params.Ctx, params.Mobile)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 得到用户门店及成员信息
|
||||
// @Description 得到用户门店及成员信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mobile query string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpGetUserInfo [get]
|
||||
func (c *UserController) TmpGetUserInfo() {
|
||||
c.callTmpGetUserInfo(func(params *tUserTmpGetUserInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetUserInfo(params.Ctx, params.Mobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 得到用户自己的门店及成员信息
|
||||
// // @Description 得到用户自己的门店及成员信息
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpGetSelfInfo [get]
|
||||
// func (c *UserController) TmpGetSelfInfo() {
|
||||
// c.callTmpGetSelfInfo(func(params *tUserTmpGetSelfInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.GetSelfInfo(params.Ctx)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 得到用户自己的门店及成员信息
|
||||
// @Description 得到用户自己的门店及成员信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpGetSelfInfo [get]
|
||||
func (c *UserController) TmpGetSelfInfo() {
|
||||
c.callTmpGetSelfInfo(func(params *tUserTmpGetSelfInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetSelfInfo(params.Ctx)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 得到用户自己的门店列表
|
||||
// // @Description 得到用户自己的门店列表
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpGetMyStoreList [get]
|
||||
// func (c *UserController) TmpGetMyStoreList() {
|
||||
// c.callTmpGetSelfInfo(func(params *tUserTmpGetSelfInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.GetMyStoreList(params.Ctx)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 得到用户自己的门店列表
|
||||
// @Description 得到用户自己的门店列表
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpGetMyStoreList [get]
|
||||
func (c *UserController) TmpGetMyStoreList() {
|
||||
c.callTmpGetSelfInfo(func(params *tUserTmpGetSelfInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetMyStoreList(params.Ctx)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 取消手机门店绑定
|
||||
// // @Description 此操作会将此手机关联的所有门店信息清除(取消组长,取消自己为他组组员),如果此人为组长,取消后组员也相应会取消门店绑定(但组员的成员关系还在)
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param mobile formData string true "手机号"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpUnbindMobile [put]
|
||||
// func (c *UserController) TmpUnbindMobile() {
|
||||
// c.callTmpUnbindMobile(func(params *tUserTmpUnbindMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.UnbindMobile(params.Ctx, params.Mobile)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 取消手机门店绑定
|
||||
// @Description 此操作会将此手机关联的所有门店信息清除(取消组长,取消自己为他组组员),如果此人为组长,取消后组员也相应会取消门店绑定(但组员的成员关系还在)
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpUnbindMobile [put]
|
||||
func (c *UserController) TmpUnbindMobile() {
|
||||
c.callTmpUnbindMobile(func(params *tUserTmpUnbindMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.UnbindMobile(params.Ctx, params.Mobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 手机门店绑定
|
||||
// // @Description 此操作会将此手机设置成为相应门的组长,如果之前有组员关系,则此操作后,组员也会自动与门店绑定
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param mobile formData string true "手机号"
|
||||
// // @Param storeID formData int true "门店ID"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpBindMobile2Store [put]
|
||||
// func (c *UserController) TmpBindMobile2Store() {
|
||||
// c.callTmpBindMobile2Store(func(params *tUserTmpBindMobile2StoreParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.BindMobile2Store(params.Ctx, params.Mobile, params.StoreID)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 手机门店绑定
|
||||
// @Description 此操作会将此手机设置成为相应门的组长,如果之前有组员关系,则此操作后,组员也会自动与门店绑定
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Param storeID formData int true "门店ID"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpBindMobile2Store [put]
|
||||
func (c *UserController) TmpBindMobile2Store() {
|
||||
c.callTmpBindMobile2Store(func(params *tUserTmpBindMobile2StoreParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.BindMobile2Store(params.Ctx, params.Mobile, params.StoreID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 将手机加到另一手机上
|
||||
// // @Description 将手机加到另一手机上
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param parentMobile formData string true "父手机号"
|
||||
// // @Param mobile formData string true "手机号"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpAddMobile2Mobile [put]
|
||||
// func (c *UserController) TmpAddMobile2Mobile() {
|
||||
// c.callTmpAddMobile2Mobile(func(params *tUserTmpAddMobile2MobileParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.AddMobile2Mobile(params.Ctx, params.ParentMobile, params.Mobile)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
// @Title 将手机加到另一手机上
|
||||
// @Description 将手机加到另一手机上
|
||||
// @Param token header string true "认证token"
|
||||
// @Param parentMobile formData string true "父手机号"
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpAddMobile2Mobile [put]
|
||||
func (c *UserController) TmpAddMobile2Mobile() {
|
||||
c.callTmpAddMobile2Mobile(func(params *tUserTmpAddMobile2MobileParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.AddMobile2Mobile(params.Ctx, params.ParentMobile, params.Mobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 变更手机号
|
||||
// @Description 变更手机号
|
||||
// @Param token header string true "认证token"
|
||||
// @Param curMobile formData string true "当前手机号"
|
||||
// @Param expectedMobile formData string true "手机号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /TmpChangeMobile [put]
|
||||
func (c *UserController) TmpChangeMobile() {
|
||||
c.callTmpChangeMobile(func(params *tUserTmpChangeMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.ChangeMobile(params.Ctx, params.CurMobile, params.ExpectedMobile)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
// // @Title 变更手机号
|
||||
// // @Description 变更手机号
|
||||
// // @Param token header string true "认证token"
|
||||
// // @Param curMobile formData string true "当前手机号"
|
||||
// // @Param expectedMobile formData string true "手机号"
|
||||
// // @Success 200 {object} controllers.CallResult
|
||||
// // @Failure 200 {object} controllers.CallResult
|
||||
// // @router /TmpChangeMobile [put]
|
||||
// func (c *UserController) TmpChangeMobile() {
|
||||
// c.callTmpChangeMobile(func(params *tUserTmpChangeMobileParams) (retVal interface{}, errCode string, err error) {
|
||||
// retVal, err = cms.ChangeMobile(params.Ctx, params.CurMobile, params.ExpectedMobile)
|
||||
// return retVal, "", err
|
||||
// })
|
||||
// }
|
||||
|
||||
@@ -15,9 +15,9 @@ func Init() {
|
||||
orm.RegisterModel(new(legacymodel.BlackClient))
|
||||
orm.RegisterModel(new(legacymodel.JxBadComments))
|
||||
orm.RegisterModel(new(legacymodel.StoreBill))
|
||||
if !globals.DisableWXAuth1 {
|
||||
orm.RegisterModel(new(legacymodel.WeiXins))
|
||||
}
|
||||
// if !globals.DisableWXAuth1 {
|
||||
// orm.RegisterModel(new(legacymodel.WeiXins))
|
||||
// }
|
||||
orm.RegisterModel(new(model.GoodsOrder))
|
||||
orm.RegisterModel(new(model.GoodsOrderOriginal))
|
||||
orm.RegisterModel(new(model.TempGoodsOrderMobile))
|
||||
|
||||
@@ -187,96 +187,6 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "BindMiniProgram",
|
||||
Router: `/BindMiniProgram`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "BindMobile",
|
||||
Router: `/BindMobile`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "BindMobile2",
|
||||
Router: `/BindMobile2`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetUserInfo",
|
||||
Router: `/GetUserInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetWeiXinUserInfo",
|
||||
Router: `/GetWeiXinUserInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "Login",
|
||||
Router: `/Login`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "Logout",
|
||||
Router: `/Logout`,
|
||||
AllowHTTPMethods: []string{"delete"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "MiniBindWeiXin",
|
||||
Router: `/MiniBindWeiXin`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "MiniDecryptData",
|
||||
Router: `/MiniDecryptData`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SendMobileVerifyCode",
|
||||
Router: `/SendMobileVerifyCode`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:CmsController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateQrOrBarCode",
|
||||
@@ -1926,76 +1836,4 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpAddMobile2Mobile",
|
||||
Router: `/TmpAddMobile2Mobile`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpBindMobile2Store",
|
||||
Router: `/TmpBindMobile2Store`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpChangeMobile",
|
||||
Router: `/TmpChangeMobile`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpGetMyStoreList",
|
||||
Router: `/TmpGetMyStoreList`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpGetSelfInfo",
|
||||
Router: `/TmpGetSelfInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpGetStoreUsers",
|
||||
Router: `/TmpGetStoreUsers`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpGetUserInfo",
|
||||
Router: `/TmpGetUserInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpUnbindMobile",
|
||||
Router: `/TmpUnbindMobile`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
}
|
||||
|
||||
@@ -31,21 +31,21 @@ func init() {
|
||||
&controllers.StoreController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/auth",
|
||||
beego.NSInclude(
|
||||
&controllers.AuthController{},
|
||||
),
|
||||
),
|
||||
// beego.NSNamespace("/auth",
|
||||
// beego.NSInclude(
|
||||
// &controllers.AuthController{},
|
||||
// ),
|
||||
// ),
|
||||
beego.NSNamespace("/cms",
|
||||
beego.NSInclude(
|
||||
&controllers.CmsController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/user",
|
||||
beego.NSInclude(
|
||||
&controllers.UserController{},
|
||||
),
|
||||
),
|
||||
// beego.NSNamespace("/user",
|
||||
// beego.NSInclude(
|
||||
// &controllers.UserController{},
|
||||
// ),
|
||||
// ),
|
||||
beego.NSNamespace("/store/sku",
|
||||
beego.NSInclude(
|
||||
&controllers.StoreSkuController{},
|
||||
|
||||
Reference in New Issue
Block a user