Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package fengniao
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"videoweb/pub/common/httputil"
|
||||
"videoweb/pub/common/log"
|
||||
)
|
||||
|
||||
type requestBody struct {
|
||||
MercId string `json:"mercId"`
|
||||
Secret string `json:"secret"`
|
||||
TemplateId string `json:"templateId"`
|
||||
Code string `json:"smsCode"`
|
||||
Mobile string `json:"mobile"`
|
||||
SignType string `json:"signType"` // 固定sha1
|
||||
Sign string `json:"sign"` // 签名
|
||||
}
|
||||
|
||||
type msg struct {
|
||||
Status string `json:"status"`
|
||||
TaskId string `json:"taskId"`
|
||||
}
|
||||
|
||||
type responseBody struct {
|
||||
Code int `json:"code"`
|
||||
Msg msg `json:"msg"`
|
||||
Err string `json:"err"`
|
||||
}
|
||||
|
||||
type FengNiao struct {
|
||||
Url string
|
||||
MercId string
|
||||
Secret string
|
||||
Tmpl string
|
||||
}
|
||||
|
||||
// Send 发送, 目前蜂鸟貌似只支持数字
|
||||
func (f *FengNiao) Send(mobile string, code string) error {
|
||||
content := fmt.Sprintf(f.Tmpl, code)
|
||||
data := fmt.Sprintf("mercId=%s&templateId=%s&smsCode=%s&mobile=%s&secret=%s", f.MercId, f.Tmpl, code, mobile, f.Secret)
|
||||
|
||||
sha := sha1.New()
|
||||
_, err := sha.Write([]byte(data))
|
||||
if err != nil {
|
||||
log.Error("fengniao send error", log.Any("mobile", mobile), log.Any("content", content), log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
body := &requestBody{
|
||||
MercId: f.MercId,
|
||||
Secret: f.Secret,
|
||||
TemplateId: f.Tmpl,
|
||||
Code: code,
|
||||
Mobile: mobile,
|
||||
SignType: "sha1",
|
||||
Sign: fmt.Sprintf("%x", sha.Sum(nil)),
|
||||
}
|
||||
rp := responseBody{}
|
||||
statusCode, err := httputil.Client().POSTJsonWithJResp(&rp, f.Url, nil, body)
|
||||
if err != nil {
|
||||
log.Error("fengniao POSTJsonWithResp err", log.E(err))
|
||||
return err
|
||||
}
|
||||
if statusCode != http.StatusOK {
|
||||
log.Error("fengniao status code not 200")
|
||||
return errors.New("fengniao statusCode not 200")
|
||||
}
|
||||
if rp.Code != 200 {
|
||||
log.Error("fengniao code not 200", log.Any("errdesc", rp.Err))
|
||||
err = errors.New(rp.Err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"videoweb/pub/common/sms/fengniao"
|
||||
)
|
||||
|
||||
type Provider = int
|
||||
|
||||
const (
|
||||
tmplID1 = "6029f19a99fd8b404062e4d2" // 大陆
|
||||
tmplID2 = "5f8412c39396d16f787e561b" // 非大陆
|
||||
)
|
||||
|
||||
const (
|
||||
FengNiao Provider = 1 //蜂鸟
|
||||
YunPian Provider = 2 //云片
|
||||
)
|
||||
|
||||
func sendByFengNiao(mobile string, code string) error {
|
||||
var tmplID string
|
||||
if strings.HasPrefix(mobile, "+86") {
|
||||
tmplID = tmplID1
|
||||
return (&fengniao.FengNiao{
|
||||
Url: "https://t9x6k.cc/api/sms/sendSms",
|
||||
MercId: "10177",
|
||||
Secret: "2dfb7ec44ed59ee3c1fe8dc533384e16",
|
||||
Tmpl: tmplID,
|
||||
}).Send(mobile, code)
|
||||
} else {
|
||||
tmplID = tmplID2
|
||||
return (&fengniao.FengNiao{
|
||||
Url: "https://t9x6k.cc/api/sms/sendSms",
|
||||
MercId: "10228",
|
||||
Secret: "3ea58a27a162dad4ed3e18c076648742",
|
||||
Tmpl: tmplID,
|
||||
}).Send(mobile, code)
|
||||
}
|
||||
// return
|
||||
}
|
||||
|
||||
// Send 发送短信
|
||||
func Send(mobile string, code string) error {
|
||||
return sendByFengNiao(mobile, code)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package sms
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSend(t *testing.T) {
|
||||
err := Send("15008279990", "654321")
|
||||
t.Log(err)
|
||||
}
|
||||
Reference in New Issue
Block a user