优化结构
This commit is contained in:
Vendored
+32
@@ -87,6 +87,38 @@ func (s *Store) Delete(ctx context.Context, key string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) GetAndDelete(ctx context.Context, key string) (string, bool, error) {
|
||||
if client := s.client(); client != nil {
|
||||
value, err := client.Eval(ctx, "local v=redis.call('GET',KEYS[1]); if v then redis.call('DEL',KEYS[1]); end; return v", []string{key}).Result()
|
||||
if err == redis.Nil {
|
||||
return "", false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if value == nil {
|
||||
return "", false, nil
|
||||
}
|
||||
switch typed := value.(type) {
|
||||
case string:
|
||||
return typed, true, nil
|
||||
case []byte:
|
||||
return string(typed), true, nil
|
||||
default:
|
||||
return "", false, nil
|
||||
}
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
entry, ok := s.memory[key]
|
||||
if !ok || (!entry.expiresAt.IsZero() && time.Now().After(entry.expiresAt)) {
|
||||
delete(s.memory, key)
|
||||
return "", false, nil
|
||||
}
|
||||
delete(s.memory, key)
|
||||
return entry.value, true, nil
|
||||
}
|
||||
|
||||
func (s *Store) Increment(ctx context.Context, key string, expiration time.Duration) (int64, error) {
|
||||
if client := s.client(); client != nil {
|
||||
if expiration > 0 {
|
||||
|
||||
@@ -438,7 +438,7 @@ func alipayCreateMethod(extra, config map[string]any) (string, error) {
|
||||
}
|
||||
normalized := paymentkit.NormalizePaymentMethod(value)
|
||||
switch normalized {
|
||||
case "", "create", "trade_create", "alipay_trade_create", "jsapi", "miniapp", "mini_program":
|
||||
case "", "create", "trade_create", "alipay_trade_create", "jsapi", "js_api", "miniapp", "mini_app", "mini_program":
|
||||
return "alipay.trade.create", nil
|
||||
case "pay", "trade_pay", "alipay_trade_pay", "barcode", "barcode_pay", "micropay", "face_to_face":
|
||||
return "alipay.trade.pay", nil
|
||||
|
||||
@@ -183,7 +183,7 @@ func wechatV2CreateMethod(extra, config map[string]any) (string, error) {
|
||||
}
|
||||
normalized := paymentkit.NormalizePaymentMethod(value)
|
||||
switch normalized {
|
||||
case "", "jsapi", "js_api", "mini", "miniapp", "mini_program", "miniprogram", "applet":
|
||||
case "", "jsapi", "js_api", "mini", "miniapp", "mini_app", "mini_program", "miniprogram", "applet":
|
||||
return gopayWechat.TradeType_JsApi, nil
|
||||
case "app", "app_pay":
|
||||
return gopayWechat.TradeType_App, nil
|
||||
|
||||
@@ -49,7 +49,7 @@ func (a *wechatV3Adapter) Create(ctx context.Context, req *bizpayment.PaymentReq
|
||||
tradeType = normalizeWechatV3TradeType(firstAny(c, "trade_type", "pay_type", "method"))
|
||||
}
|
||||
switch tradeType {
|
||||
case "", "jsapi", "mini", "miniprogram", "mini_program", "applet":
|
||||
case "", "jsapi", "js_api", "mini", "miniapp", "mini_app", "miniprogram", "mini_program", "applet":
|
||||
if openID := firstAny(req.Extra, "openid", "open_id"); openID != "" {
|
||||
bm.SetBodyMap("payer", func(payer gopay.BodyMap) { payer.Set("openid", openID) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user