From 761b8371d84908d4241c0bd8c206ccc48a66c934 Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Tue, 8 Apr 2025 11:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9F=AD=E4=BF=A1=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E4=B8=9A=E5=8A=A1=E7=B1=BB=E5=9E=8B=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- const.go | 14 ++++++++++++++ msg.go | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/const.go b/const.go index 5435bf9..17e7fe9 100644 --- a/const.go +++ b/const.go @@ -35,3 +35,17 @@ var smsBusinessWithRequestPath = map[SmsBusiness]RequestPath{ SmsBusinessHs: sendSmsHs, SmsBusinessDefault: sendSms, } + +type ( + SmsOption func(*SmsOptionData) + SmsOptionData struct { + Business SmsBusiness + } +) + +func WithBusiness(business SmsBusiness) SmsOption { + + return func(OptionData *SmsOptionData) { + OptionData.Business = business + } +} diff --git a/msg.go b/msg.go index 9f7c08b..be62a1e 100644 --- a/msg.go +++ b/msg.go @@ -58,19 +58,27 @@ func (m *MessageCenter) OAGetDetail(outTradeNo string) (data OAGetDetailData, er // SendSms 短信 // business SmsBusiness -func (m *MessageCenter) SendSms(tels []string, jsonParam string, business SmsBusiness) (data SmsSend, err error) { +func (m *MessageCenter) SendSms(tels []string, jsonParam string, args ...SmsOption) (data SmsSend, err error) { var ( - path RequestPath - ex bool + e = new(SmsOptionData) ) if len(tels) == 0 { err = errors.New("手机号不能为空") return } - if path, ex = smsBusinessWithRequestPath[business]; !ex { - err = errors.New("未知的供应商") - return + for _, arg := range args { + arg(e) } + if e.Business != "" { + if _, ex := smsBusinessWithRequestPath[e.Business]; !ex { + err = errors.New("business参数错误") + return + } + } else { + e.Business = SmsBusinessDefault + } + path := smsBusinessWithRequestPath[e.Business] + param := m.parseSmsSendParam(tels, jsonParam) err = m.post(path, param, &data) if err != nil {