@@ -0,0 +1,74 @@
|
||||
package fengniao
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/httputil"
|
||||
"91porn-server/common/log"
|
||||
)
|
||||
|
||||
type requestBody struct {
|
||||
MercId string `json:"mercId"`
|
||||
Secret string `json:"secret"`
|
||||
TemplateId string `json:"templateId"`
|
||||
SmsCode 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 {
|
||||
data := fmt.Sprintf("mercId=%s&templateId=%s&smsCode=%s&mobile=%s&secret=%s", f.MercId, f.Tmpl, code, mobile, f.Secret)
|
||||
sha := sha1.New()
|
||||
if _, err := sha.Write([]byte(data)); err != nil {
|
||||
log.Error("fengniao send error", log.Any("mobile", mobile), log.Any("templateId", f.Tmpl), log.E(err))
|
||||
return err
|
||||
}
|
||||
args, _ := common.JSONStruct2Map(&requestBody{
|
||||
MercId: f.MercId,
|
||||
Secret: f.Secret,
|
||||
TemplateId: f.Tmpl,
|
||||
SmsCode: code,
|
||||
SignType: "sha1",
|
||||
Mobile: mobile,
|
||||
Sign: fmt.Sprintf("%x", sha.Sum(nil)),
|
||||
})
|
||||
rp := responseBody{}
|
||||
statusCode, err := httputil.DefaultClientPostJsonWithResp(&rp, f.Url, nil, args)
|
||||
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))
|
||||
return errors.New(rp.Err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user