From f8eca1a0a132afdb442a077e74cd5a263dcc476e Mon Sep 17 00:00:00 2001 From: shy Date: Wed, 5 Mar 2025 17:48:10 +0800 Subject: [PATCH] opt some --- src/gonganxitong/common.go | 4 +++ src/gonganxitong/portal.go | 9 ++++- .../external/weixinpayment/weixinpayment.go | 33 ------------------- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/gonganxitong/common.go b/src/gonganxitong/common.go index 8735693..f4b4fd1 100644 --- a/src/gonganxitong/common.go +++ b/src/gonganxitong/common.go @@ -119,6 +119,7 @@ func (s Table) InputsListValue(m *ice.Message, list ice.Any, key string) string return "" } func (s Table) TransPrice(m *ice.Message, arg []string, field ...string) []string { + kit.If(len(field) == 0, func() { field = append(field, "price") }) for i := 0; i < len(arg)-1; i += 2 { if kit.IndexOf(field, arg[i]) > -1 { arg[i+1] = kit.Format(kit.Int(kit.Float(arg[i+1]) * 100)) @@ -190,6 +191,9 @@ func (s Table) Select(m *ice.Message, arg ...string) *ice.Message { kit.If(m.Length() > 0, func() { s.UserPlaceInit(m) }) return m } +func (s Table) InsertIfNeed(m *ice.Message, arg ...string) { + kit.If(m.Cmd("", s.Select, arg).Length() == 0, func() { m.Cmd("", s.Insert, arg) }) +} func (s Table) InsertOrUpdate(m *ice.Message, arg []string, args ...string) { if s.Select(m, args...).Length() > 0 { s.Update(m, arg, args...) diff --git a/src/gonganxitong/portal.go b/src/gonganxitong/portal.go index 77e01f3..576dcff 100644 --- a/src/gonganxitong/portal.go +++ b/src/gonganxitong/portal.go @@ -126,7 +126,7 @@ func (s Portal) List(m *ice.Message, arg ...string) { s.Hash.List(m, kit.Slice(arg, 1)...).PushAction(mdb.DETAIL, s.Hash.Remove).Action().SortInt(mdb.ORDER) return } - if m.Option(model.USER_UID) == "" || m.Cmd(s.user, s.Table.Select, model.UID, m.Option(model.USER_UID)).Length() == 0 { + if m.Option(model.USER_UID) == "" { if msg := m.Cmd(s.user, s.Table.Select, model.OPEN_ID, m.Option(ice.MSG_USERNAME)); msg.Length() == 0 { msg := m.Cmd(s.user, s.Table.Create, m.Option(ice.MSG_USERNAME), "", m.OptionDefault(ice.MSG_USERNICK, m.Option(ice.MSG_USERNAME))) m.ProcessCookie(model.USER_UID, msg.Result()) @@ -135,6 +135,13 @@ func (s Portal) List(m *ice.Message, arg ...string) { } return } + if m.Cmd(s.user, s.Table.Select, model.UID, m.Option(model.USER_UID)).Length() == 0 { + m.Cmd(s.user, s.Table.Insert, + model.UID, m.Option(model.USER_UID), + model.OPEN_ID, m.Option(ice.MSG_USERNAME), + model.NAME, m.OptionDefault(ice.MSG_USERNICK, m.Option(ice.MSG_USERNAME)), + ) + } m.Option(model.SERVICE_UID, ServiceUID(m)) if len(arg) == 0 { m.Cmdy(m.PrefixKey(), s.PlaceList, m.Option(model.USER_UID)).PushAction(s.PlaceRemove).Action(s.PlaceCreate) diff --git a/src/renzhengshouquan/external/weixinpayment/weixinpayment.go b/src/renzhengshouquan/external/weixinpayment/weixinpayment.go index 99ec8be..c4795a8 100644 --- a/src/renzhengshouquan/external/weixinpayment/weixinpayment.go +++ b/src/renzhengshouquan/external/weixinpayment/weixinpayment.go @@ -1,9 +1,6 @@ package weixinpayment import ( - "bytes" - "crypto/x509" - "net/http" "path" "strings" @@ -16,8 +13,6 @@ import ( "shylinux.com/x/community/src/renzhengshouquan/external/weixinpayment/model" "github.com/wechatpay-apiv3/wechatpay-go/core" - "github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers" - "github.com/wechatpay-apiv3/wechatpay-go/core/notify" "github.com/wechatpay-apiv3/wechatpay-go/core/option" "github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi" "github.com/wechatpay-apiv3/wechatpay-go/utils" @@ -67,7 +62,6 @@ func (s weixinpayment) Response(m *ice.Message, arg ...string) { resp, result, err := svc.QueryOrderByOutTradeNo(m, jsapi.QueryOrderByOutTradeNoRequest{ Mchid: core.String(msg.Append(model.MCH_ID)), OutTradeNo: core.String(arg[1]), - // OutTradeNo: core.String("027581e07da12f52dac052d7a8ef7659"), }) m.Info("weixinpayment %s %s %#v", kit.Format(resp), kit.Format(result), err) if err, ok := err.(*core.APIError); ok { @@ -77,33 +71,6 @@ func (s weixinpayment) Response(m *ice.Message, arg ...string) { if m.Warn(*resp.TradeState != "SUCCESS") { return } - return - - request, err := http.NewRequest(http.MethodPost, m.MergePodCmd("", m.PrefixKey()), bytes.NewBufferString(m.Option("request.data"))) - if m.Warn(err) { - return - } - kit.For([]string{ - "Wechatpay-Serial", - "Wechatpay-Signature", - "Wechatpay-Nonce", - "Wechatpay-Timestamp", - "Wechatpay-Signature-Type", - }, func(k string) { request.Header.Set(k, m.Option(k)) }) - content := make(map[string]interface{}) - - mchAPIv3Key := msg.Append(model.API_KEY) - wechatPayCert, err := utils.LoadCertificate(msg.Append(model.CERT_FILE)) - if m.Warn(err) { - return - } - certificateVisitor := core.NewCertificateMapWithList([]*x509.Certificate{wechatPayCert}) - handler := notify.NewNotifyHandler(mchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(certificateVisitor)) - notifyReq, err := handler.ParseNotifyRequest(m, request, &content) - if m.Warn(err) { - return - } - m.Echo(notifyReq.Summary) } func init() { ice.TeamCtxCmd(weixinpayment{}) }