Order订单待测试
This commit is contained in:
parent
d4d11db732
commit
e50dac6b1c
1
go.mod
1
go.mod
|
@ -16,6 +16,7 @@ require (
|
|||
require (
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/schollz/progressbar v1.0.0 // indirect
|
||||
github.com/stripe/stripe-go/v74 v74.22.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
5
go.sum
5
go.sum
|
@ -229,6 +229,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/stripe/stripe-go/v74 v74.22.0 h1:A6yqbyS61JYWhq6H4b0PFZukM8Ltx1VOXxsLYBNL+wE=
|
||||
github.com/stripe/stripe-go/v74 v74.22.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw=
|
||||
github.com/tidwall/gjson v1.12.0 h1:61wEp/qfvFnqKH/WCI3M8HuRut+mHT6Mr82QrFmM2SY=
|
||||
github.com/tidwall/gjson v1.12.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
|
@ -333,6 +335,7 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
|
|||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
|
||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
|
@ -376,6 +379,7 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
@ -388,6 +392,7 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
|
|||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
|
|
|
@ -25,7 +25,7 @@ func NewServiceContext(c {{.config}}) *ServiceContext {
|
|||
}
|
||||
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -2,6 +2,7 @@ package gmodel
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@ -51,7 +52,7 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
|||
func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddress) (err error) {
|
||||
err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if *address.IsDefault > 0 {
|
||||
err = tx.Where("user_id = ? and is_default = 1", *address.UserId).Update("is_default", 0).Error
|
||||
err = tx.Where("user_id = ? and is_default = 1", address.UserId).Update("is_default", 0).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,10 +9,8 @@ func (p *FsPayModel) GetListByOrderNumber(ctx context.Context, sn string) (resp
|
|||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (p *FsPayModel) GetOrderPayList(ctx context.Context, sn string, payStatus int64, isRefund int64) (resp []FsPay, err error) {
|
||||
err = p.db.WithContext(ctx).Model(&FsPay{}).Where("`order_number` = ? and `pay_status` = ? and `is_refund` = ?", sn, payStatus, isRefund).Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
return resp, err
|
||||
}
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
package gmodel
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (fsRefundReason *FsRefundReasonModel) Update(cxt context.Context) {
|
||||
func (m *FsRefundReasonModel) Create(ctx context.Context, obj *FsRefundReason) error {
|
||||
return m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) Update(ctx context.Context, obj *FsRefundReason) error {
|
||||
return m.db.WithContext(ctx).Model(obj).Where("`id` = ?", obj.Id).Updates(obj).Error
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) UpdateByRefundReasonId(ctx context.Context, obj *FsRefundReason) error {
|
||||
return m.db.WithContext(ctx).Model(obj).Where("`refund_reason_id` = ?", obj.RefundReasonId).Updates(obj).Error
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import (
|
|||
"fmt"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/canteen/internal/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
|
@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -5,9 +5,10 @@ import (
|
|||
"fmt"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/data-transfer/internal/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
|
@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -7,3 +7,6 @@ Auth:
|
|||
AccessSecret: fusen2023
|
||||
AccessExpire: 60
|
||||
RefreshAfter: 60
|
||||
|
||||
Stripe:
|
||||
SK: "123"
|
||||
|
|
|
@ -10,4 +10,8 @@ type Config struct {
|
|||
rest.RestConf
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
|
||||
Stripe struct {
|
||||
SK string
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ import (
|
|||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/stripe/stripe-go/v74"
|
||||
"github.com/stripe/stripe-go/v74/client"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
@ -104,27 +107,40 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
|
|||
CreatedAt: &CreatedAt,
|
||||
}
|
||||
|
||||
mFsRefund := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn)
|
||||
|
||||
err = refund.Save()
|
||||
mFsRefundReason := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn)
|
||||
err = mFsRefundReason.Create(l.ctx, refund)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
|
||||
// 退款
|
||||
// 调用第三方接口发起退款
|
||||
config := GetStripeConfig()
|
||||
|
||||
config := &stripe.BackendConfig{
|
||||
MaxNetworkRetries: stripe.Int64(0), // Zero retries
|
||||
}
|
||||
|
||||
sc := &client.API{}
|
||||
sc.Init(l.svcCtx.Config.Stripe.SK, &stripe.Backends{
|
||||
API: stripe.GetBackendWithConfig(stripe.APIBackend, config),
|
||||
Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config),
|
||||
})
|
||||
// ['order_number' => $order->sn, 'is_refund' => 0, 'pay_status' => 1]
|
||||
pay := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
|
||||
|
||||
// 查询支付信息
|
||||
pays, err := Pay.Find(db.Where("order_number = ? AND is_refund = ? AND pay_status = ?", order.SN, 0, 1))
|
||||
pays, err := pay.GetOrderPayList(l.ctx, *order.Sn, 1, 0)
|
||||
for _, pay := range pays {
|
||||
stripe := stripe.New(config.SK)
|
||||
_, err := stripe.Refunds.Create(stripe.RefundParams{
|
||||
sc.Refunds.New(&stripe.RefundParams{
|
||||
PaymentIntent: pay.TradeNo,
|
||||
})
|
||||
}
|
||||
|
||||
if err == nil && err == nil {
|
||||
return ResponseSuccess(200, "Cancel successfully", order)
|
||||
}
|
||||
return ResponseError(500, "Cancellation failure")
|
||||
// if err == nil && err == nil {
|
||||
// return ResponseSuccess(200, "Cancel successfully", order)
|
||||
// }
|
||||
// return ResponseError(500, "Cancellation failure")
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if AuthKey == "" {
|
||||
return nil, nil
|
||||
|
@ -35,7 +35,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return []byte(svcCxt.Config.Auth.AccessSecret), nil
|
||||
return []byte(svcCtx.Config.Auth.AccessSecret), nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -5,9 +5,10 @@ import (
|
|||
"fmt"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/map-library/internal/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
|
@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -5,9 +5,10 @@ import (
|
|||
"fmt"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/orders/internal/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
|
@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -2,11 +2,13 @@ package svc
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/product-templatev2/internal/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
|
@ -23,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -35,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -25,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -25,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||
AuthKey := r.Header.Get("Authorization")
|
||||
if len(AuthKey) <= 50 {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||
|
@ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
|
|||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// 返回用于验证签名的密钥
|
||||
return svcCxt.Config.Auth.AccessSecret, nil
|
||||
return svcCtx.Config.Auth.AccessSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||
|
|
|
@ -68,8 +68,17 @@ func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Respon
|
|||
} else {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
} else if len(data) > 1 {
|
||||
newResp.Data = data
|
||||
} else if len(data) == 2 {
|
||||
var dataIndex = 0
|
||||
if err, ok := data[dataIndex].(error); ok {
|
||||
newResp.Message = err.Error()
|
||||
dataIndex++
|
||||
} else {
|
||||
panic("data只接收1或2个 data 或 error.Error() 和 data ")
|
||||
}
|
||||
newResp.Data = data[1]
|
||||
} else {
|
||||
panic("data只接收1或2个 data, error.Error() 和 data ")
|
||||
}
|
||||
|
||||
return newResp
|
||||
|
@ -83,6 +92,21 @@ func (resp *Response) SetStatusWithMessage(sr *StatusResponse, msg string, data
|
|||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
} else {
|
||||
panic("data只接收一个 data")
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
||||
func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message + ":" + msg,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
} else {
|
||||
panic("data只接收一个")
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user