From e197a1ca87952129cdeb7b6f6e4d0f1ba4543013 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 1 Jul 2024 16:47:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=96=E9=9F=B3=E5=9B=A2=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sms/api.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/sms/api.go b/sms/api.go index b1e0486..e9352ce 100644 --- a/sms/api.go +++ b/sms/api.go @@ -134,6 +134,58 @@ func SmsSend(engine *xorm.Engine, args map[string]interface{}) error { fmt.Println(err) return nil } +func SmsSendZy(engine *xorm.Engine, args map[string]interface{}) error { + where := make(map[string]interface{}) + param := []string{ + "content", //短信内容 + "mobile", //号码多个以英文”,”号分割,最大 2000 个 + "code", //扩展号 0-9 数字,超过 8 位自动截取前 8 位 + "ext", //自定义信息,状态报告时返回,可以为空 + } + for _, v := range param { + if args[v] != "" && args[v] != nil { + where[v] = args[v].(string) + } + } + send := "" + var err error + if args["type"] == "mob" { //mob + if args["templateCode"] == "" { + args["templateCode"] = "normal" + } + where = map[string]interface{}{ + "appkey": args["smsmsg_key"], + "zone": args["zone"], + "phone": args["mobile"], + "templateCode": args["templateCode"], + } + send, err = SmsMobApiSend(where) + if err != nil { + return err + } + status := gjson.Get(send, "status").Int() + msg := gjson.Get(send, "error").String() + if status == 471 { + return errors.New("发送的ip不在白名单中") + } + if status == 406 { + return errors.New("appkey不存在") + } + if status != 200 { + return errors.New(msg) + } + } else { + send, err = SmsApiSend(engine, "api.v1.sms", where) + if err != nil { + return err + } + success := gjson.Get(send, "code").Int() + if success != 20000 { + return errors.New("发送失败") + } + } + return nil +} func SmsApiSend(engine *xorm.Engine, method string, args map[string]interface{}) (string, error) { smsmsgKey := offical.SysCfgByKey(engine, "smsmsg_key")