- mini program login

This commit is contained in:
gazebo
2018-12-27 16:49:32 +08:00
parent b1a7cfdaa8
commit 5adc5e61f3
16 changed files with 301 additions and 51 deletions

View File

@@ -2,10 +2,12 @@ package auth
import (
"errors"
"fmt"
"time"
"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/api"
)
@@ -14,8 +16,8 @@ const (
)
type IAuther interface {
Login(id, secret string) error
Logout(id string) error
Login(id, secret string) (userID string, err error)
Logout(loginInfo *LoginInfo) error
}
var (
@@ -44,7 +46,11 @@ func RegisterAuther(loginType string, handler IAuther) {
func Login(id, loginType, secret string) (loginInfo *LoginInfo, err error) {
if handler := authers[loginType]; handler != nil {
if err = handler.Login(id, secret); err == nil {
userID, err2 := handler.Login(id, secret)
if err = err2; err == nil {
if userID != "" {
id = userID
}
token := utils.GetUUID()
loginInfo = &LoginInfo{
ID: id,
@@ -65,7 +71,7 @@ func Logout(token string) (err error) {
loginInfo := new(LoginInfo)
if err = api.Cacher.GetAs(token, loginInfo); err == nil {
if handler := authers[loginInfo.LoginType]; handler != nil {
err = handler.Logout(loginInfo.ID)
err = handler.Logout(loginInfo)
}
api.Cacher.Del(token)
}
@@ -79,3 +85,10 @@ func GetUserInfo(token string) (loginInfo *LoginInfo, err error) {
}
return nil, model.ErrTokenIsInvalid
}
func ConvertErr2NoUser(err error, mobileNum string) error {
if dao.IsNoRowsError(err) {
err = fmt.Errorf("没有%s这个用户", mobileNum)
}
return err
}

View File

@@ -20,19 +20,19 @@ func init() {
auth.RegisterAuther(LoginType, new(Auther))
}
func (a *Auther) Login(uname, password string) (err error) {
func (a *Auther) Login(uname, password string) (userID string, err error) {
user := &legacymodel.JxBackendUser{
UName: uname,
}
if err = dao.GetEntity(nil, user, "UName"); err == nil {
if fmt.Sprintf("%x", md5.Sum([]byte(password))) == user.UPass {
return nil
return "", nil
}
err = auth.ErrUIDAndPassNotMatch
}
return err
return "", err
}
func (a *Auther) Logout(openid string) error {
func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
return nil
}

View File

@@ -1,11 +1,15 @@
package mobile
import (
"errors"
"fmt"
"math/rand"
"time"
"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/business/model/legacymodel"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/KenmyZhang/aliyun-communicate"
@@ -15,6 +19,22 @@ const (
DefVerifyCodeDuration = 5 * time.Minute
)
const (
LoginType = "mobile"
)
type Auther struct {
}
var (
auther *Auther
)
func init() {
auther = new(Auther)
auth.RegisterAuther(LoginType, auther)
}
func SendVerifyCode(mobileNumber string) error {
code := fmt.Sprintf("%06d", rand.Intn(1000000))
globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
@@ -42,3 +62,22 @@ func VerifyCode(mobileNumber, code string) bool {
}
return false
}
func (a *Auther) Login(mobileNum, verifyCode string) (userID string, err error) {
if VerifyCode(mobileNum, verifyCode) {
user := &legacymodel.WeiXins{
Tel: mobileNum,
}
db := dao.GetDB()
if err = dao.GetEntity(db, user, "Tel"); err != nil {
err = auth.ConvertErr2NoUser(err, mobileNum)
}
} else {
err = errors.New("验证错误")
}
return "", err
}
func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
return nil
}

View File

@@ -1,6 +1,7 @@
package weixin
import (
"encoding/base64"
"errors"
"fmt"
"time"
@@ -9,6 +10,7 @@ import (
"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/jxutils/jxcontext"
"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"
@@ -18,21 +20,32 @@ import (
const (
LoginType = "weixinsns"
LoginTypeMiniProgram = "weixinmini"
DefTempPasswordDuration = 5 * time.Minute // 登录时间限制在5分钟内
)
const (
CacheKeySeparator = "/"
MiniVerifyCodePrefix = "MiniVerifyCode"
SessionKeyPrefix = "SessionKey"
)
var (
ErrLoginFailed = errors.New("登录失败")
StrStateIsWrong = "state:%s状态不对"
)
var (
auther *Auther
auther *Auther
AutherMini *AutherMiniProgram
)
type Auther struct {
}
type AutherMiniProgram struct {
}
type UserInfoExt struct {
weixinapi.SNSUserInfo
TempPassword string `json:"tempPassword"` // 一段时间有效的登录密码
@@ -41,6 +54,9 @@ type UserInfoExt struct {
func init() {
auther = new(Auther)
auth.RegisterAuther(LoginType, auther)
AutherMini = new(AutherMiniProgram)
auth.RegisterAuther(LoginTypeMiniProgram, AutherMini)
}
func GetUserInfo(code string, state string) (token *UserInfoExt, err error) {
@@ -66,8 +82,8 @@ func GetUserInfo(code string, state string) (token *UserInfoExt, err error) {
return nil, err
}
func (a *Auther) Login(openid, password string) (err error) {
globals.SugarLogger.Debugf("Login openid:%s, password:%s", openid, password)
func (a *Auther) Login(openid, password string) (userID string, err error) {
globals.SugarLogger.Debugf("weixinsns Login openid:%s, password:%s", openid, password)
if value := api.Cacher.Get(openid); value != nil {
if password == value.(string) {
@@ -76,17 +92,17 @@ func (a *Auther) Login(openid, password string) (err error) {
// }
// if err = dao.GetEntity(nil, wxUser, "OpenID"); err == nil {
api.Cacher.Del(openid)
return nil
return "", nil
// }
}
} else {
err = ErrLoginFailed
}
return err
return "", err
}
func (a *Auther) Logout(openid string) error {
return api.Cacher.Del(openid)
func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
return nil
}
func BindMobile(token, mobileNum, code, nickname string) (err error) {
@@ -122,3 +138,84 @@ func BindMobile(token, mobileNum, code, nickname string) (err error) {
}
return err
}
// 对于小程序来说,
// 1用户必须先在后台创建手机号标识
// 2用户必须先绑定微信
// 先以短信方式登录:
// SendMobileVerifyCode
// Login use type mobile
// MiniBindWeiXin
// 3用户以CODE来登录Login use type weixinmini
// Login
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.LoginType != mobile.LoginType {
return fmt.Errorf("调用AutherMiniProgram BindWeiXin时必须以手机验证方式登录")
}
user := &legacymodel.WeiXins{
Tel: loginInfo.ID,
}
db := dao.GetDB()
if err = dao.GetEntity(db, user, "Tel"); err != nil {
return auth.ConvertErr2NoUser(err, loginInfo.ID)
}
sessionInfo, err := api.WeixinAPI.SNSCode2Session(code)
if err != nil {
return err
}
user.OpenIDMini = sessionInfo.OpenID
if nickName != "" {
user.NickName = nickName
}
_, err = dao.UpdateEntity(db, user)
return err
}
func (a *AutherMiniProgram) Login(mobileNum, code string) (userID string, err error) {
globals.SugarLogger.Debugf("AutherMiniProgram Login mobileNum:%s, code:%s", mobileNum, code)
sessionInfo, err := api.WeixinAPI.SNSCode2Session(code)
if err != nil {
return "", err
}
user := &legacymodel.WeiXins{
OpenIDMini: sessionInfo.OpenID,
}
db := dao.GetDB()
if err = dao.GetEntity(db, user, "OpenIDMini"); err != nil {
return "", auth.ConvertErr2NoUser(err, mobileNum)
}
if mobileNum != user.Tel {
}
api.Cacher.Set(composeSessionKeyCacheKey(sessionInfo.OpenID), sessionInfo.SessionKey, auth.DefTokenDuration)
return sessionInfo.OpenID, err
}
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.ID))
}
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().ID), &sessionKey); err != nil {
return "", err
}
decryptedData, err := api.WeixinAPI.SNSDecodeMiniProgramData(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
}

View File

@@ -7,7 +7,7 @@ import (
)
func TestSendStoreMessage(t *testing.T) {
err := SendStoreMessage(jxcontext.AdminCtx, "title", "content", []int{1}, false, true)
_, err := SendStoreMessage(jxcontext.AdminCtx, "title", "content", []int{1}, false, true)
if err != nil {
t.Fatal(err)
}

View File

@@ -22,13 +22,14 @@ type StoreUserInfo struct {
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*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, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
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 t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid;
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 != "" {
@@ -42,12 +43,12 @@ func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*Store
func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *StoreUserInfo, err error) {
sql := `
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, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
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.tel = ?
GROUP BY t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid;
GROUP BY 1,2,3,4,5,6,7;
`
storeUserInfo = new(StoreUserInfo)
if err = dao.GetRow(nil, storeUserInfo, sql, mobile); err == nil {
@@ -61,12 +62,12 @@ func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *StoreUse
func GetSelfInfo(ctx *jxcontext.Context, openID string) (storeUserInfo *StoreUserInfo, err error) {
sql := `
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, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
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.openid = ?
GROUP BY t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid;
GROUP BY 1,2,3,4,5,6,7;
`
storeUserInfo = new(StoreUserInfo)
if err = dao.GetRow(nil, storeUserInfo, sql, openID); err == nil || err == orm.ErrNoRows { // todo
@@ -80,7 +81,7 @@ func GetSelfInfo(ctx *jxcontext.Context, openID string) (storeUserInfo *StoreUse
func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
return dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
"JxStoreID": nil,
"JxStoreID": 0,
"ParentID": -1,
}, map[string]interface{}{
"Tel": mobile,
@@ -96,7 +97,7 @@ func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num i
num, err = dao.UpdateEntity(db, user, "JxStoreID")
} else {
user.ParentID = -1
if err = createUserAndSetOpenIDNull(db, user); err == nil {
if err = dao.CreateWeiXins(db, user); err == nil {
num = 1
}
}
@@ -118,7 +119,7 @@ func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num
if err == nil {
num, err = dao.UpdateEntity(db, user, "ParentID")
} else {
if err = createUserAndSetOpenIDNull(db, user); err == nil {
if err = dao.CreateWeiXins(db, user); err == nil {
num = 1
}
}
@@ -186,17 +187,3 @@ func verifyMobileHasNoMembers(db *dao.DaoDB, mobile string) (err error) {
}
return err
}
func createUserAndSetOpenIDNull(db *dao.DaoDB, user *legacymodel.WeiXins) (err error) {
dao.Begin(db)
if err = dao.CreateEntity(db, user); err != nil {
dao.Rollback(db)
return err
}
if _, err = dao.ExecuteSQL(db, "UPDATE weixins SET openid = NULL WHERE tel = ?", user.Tel); err != nil {
dao.Rollback(db)
return err
}
dao.Commit(db)
return err
}

View File

@@ -82,6 +82,10 @@ func (ctx *Context) GetUserID() string {
return ctx.token
}
func (ctx *Context) GetLoginInfo() *auth.LoginInfo {
return ctx.userInfo
}
func (ctx *Context) GetRootTask() tasksch.ITask {
ctx.locker.RLock()
defer ctx.locker.RUnlock()

View File

@@ -0,0 +1,26 @@
package dao
import (
"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 = ExecuteSQL(db, `
UPDATE weixins
SET
openid = IF(openid = '', NULL, openid),
openid_mini = IF(openid_mini = '', NULL, openid_mini),
tel = IF(tel = '', NULL, tel)
WHERE id = ?
`, user.ID); err != nil {
Rollback(db)
return err
}
Commit(db)
return err
}

View File

@@ -1,6 +1,7 @@
package dao
import (
"fmt"
"reflect"
"strings"
"time"
@@ -130,3 +131,40 @@ func GetCategoryIDJsonField(prefix string) string {
func GetCategoryIDDBField(prefix string) string {
return ConvertDBFieldPrefix(prefix) + "_category_id"
}
func value2Value(srcValue, dstValue reflect.Value, copyType int) {
srcType := srcValue.Type()
for i := 0; i < srcType.NumField(); i++ {
fieldName := srcType.Field(i).Name
if dstFieldvalue := dstValue.FieldByName(fieldName); dstFieldvalue.IsValid() {
srcFieldValue := srcValue.FieldByName(fieldName)
if false { //dstFieldvalue.Kind() == reflect.Struct {
fmt.Printf("%v, %v\n", utils.Format4Output(srcFieldValue.Interface(), false), utils.Format4Output(dstFieldvalue.Interface(), false))
value2Value(srcFieldValue, dstFieldvalue, copyType)
} else {
// fmt.Printf("%v, %v\n", srcFieldValue.Interface(), dstFieldvalue.Interface())
dstFieldvalue.Set(srcFieldValue)
}
}
}
}
// func copyBetweenNoramAndNullObj(src, dst interface{}, copyType int) {
// dstValue := reflect.ValueOf(dst)
// if dstValue.Kind() != reflect.Ptr {
// panic("ObjNormal2Null dst must be ptr of struct")
// }
// srcValue := reflect.ValueOf(src)
// if srcValue.Kind() == reflect.Ptr {
// srcValue = srcValue.Elem()
// }
// value2Value(srcValue, dstValue.Elem(), copyType)
// }
// func ObjNormal2Null(src, dst interface{}) {
// copyBetweenNoramAndNullObj(src, dst, 1)
// }
// func ObjNull2Normal(src, dst interface{}) {
// copyBetweenNoramAndNullObj(src, dst, 2)
// }

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals"
)
@@ -186,7 +185,7 @@ func GetFullStoreSkus(db *DaoDB, vendorID, storeID int) (skus []*StoreSkuSyncInf
return skus, err
}
func SetStoreSkuSyncStatus(ctx *jxcontext.Context, db *DaoDB, vendorID, storeID int, skuIDs []int, syncStatus int) (num int64, err error) {
func SetStoreSkuSyncStatus(db *DaoDB, vendorID, storeID int, skuIDs []int, syncStatus int) (num int64, err error) {
globals.SugarLogger.Debugf("SetStoreSkuSyncStatus, storeID:%d, vendorID:%d", storeID, vendorID)
fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])

View File

@@ -1,12 +1,13 @@
package legacymodel
type WeiXins struct {
ID int `orm:"column(id)" json:"id"`
JxStoreID int `orm:"column(jxstoreid);index" json:"storeID"`
OpenID string `orm:"column(openid);size(70);unique;null" json:"openID"`
Tel string `orm:"size(15);unique" json:"tel"`
ParentID int `orm:"column(parentid);default(-1);index" json:"parentID"`
NickName string `orm:"column(nickname);size(30)" json:"nickname"`
ID int `orm:"column(id)" json:"id"`
JxStoreID int `orm:"column(jxstoreid);index" json:"storeID"`
OpenID string `orm:"column(openid);size(70);unique;null" json:"-"`
OpenIDMini string `orm:"column(openid_mini);size(70);unique;null" json:"-"`
Tel string `orm:"size(15);null;unique" json:"tel"`
ParentID int `orm:"column(parentid);default(-1);index" json:"parentID"`
NickName string `orm:"column(nickname);size(30)" json:"nickname"`
}
func (*WeiXins) TableName() string {

View File

@@ -542,7 +542,7 @@ func (p *PurchaseHandler) updateLocalCatAsNew(db *dao.DaoDB, localCatMap map[str
func (p *PurchaseHandler) setStoreSkuSyncStatus(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, skuIDs []int, syncStatus int) (num int64, err error) {
globals.SugarLogger.Debugf("setStoreSkuSyncStatus饿百 storeID:%d", storeID)
return dao.SetStoreSkuSyncStatus(ctx, db, model.VendorIDEBAI, storeID, skuIDs, syncStatus)
return dao.SetStoreSkuSyncStatus(db, model.VendorIDEBAI, storeID, skuIDs, syncStatus)
}
func formatName(name string) string {

View File

@@ -136,7 +136,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
globals.SugarLogger.Debugf("jd FullSyncStoreSkus, storeID:%d", storeID)
db := dao.GetDB()
_, err = dao.SetStoreSkuSyncStatus(ctx, db, model.VendorIDJD, storeID, nil, model.SyncFlagModifiedMask|model.SyncFlagPriceMask|model.SyncFlagSaleMask)
_, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDJD, storeID, nil, model.SyncFlagModifiedMask|model.SyncFlagPriceMask|model.SyncFlagSaleMask)
if err != nil {
return "", err
}

View File

@@ -304,7 +304,7 @@ func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask t
case 0:
err = p.DeleteRemoteSkus(ctx, rootTask, storeID, nil)
case 1:
_, err = dao.SetStoreSkuSyncStatus(ctx, db, model.VendorIDMTWM, storeID, nil, model.SyncFlagNewMask)
_, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDMTWM, storeID, nil, model.SyncFlagNewMask)
case 2:
_, err = p.SyncLocalStoreCategory(ctx, db, storeID, true, false)
case 3:

View File

@@ -106,7 +106,6 @@ func (c *AuthController) GetUserInfo() {
// @Title 发送验证码
// @Description 发送验证码
// @Param token header string true "认证token"
// @Param mobile formData string true "手机号"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
@@ -133,3 +132,34 @@ func (c *AuthController) BindMobile() {
return retVal, "", err
})
}
// @Title 绑定手机
// @Description 绑定手机(调用此方法前先需要以短信方式登录)
// @Param token header string true "认证token"
// @Param mobile formData string true "手机号,当前无用,置空"
// @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, params.Code, params.Nickname)
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 /MiniDecrpytData [post]
func (c *AuthController) MiniDecrpytData() {
c.callMiniDecrpytData(func(params *tAuthMiniDecrpytDataParams) (retVal interface{}, errCode string, err error) {
retVal, err = weixin.AutherMini.DecryptData(params.Ctx, params.Data, params.Iv)
return retVal, "", err
})
}

View File

@@ -47,6 +47,22 @@ func init() {
MethodParams: param.Make(),
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(),
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: "MiniDecrpytData",
Router: `/MiniDecrpytData`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
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",