52 Star 171 Fork 53

xluohome / smscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
f_hywx.go 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
xluo 提交于 2017-05-27 23:28 . v0.16 beta
/**
互亿无线 短信通道
http://www.ihuyi.cn/
**/
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
log "github.com/golang/glog"
)
type Hywx struct {
sms *SMS
XMLName xml.Name `xml:"SubmitResult"`
Code int `xml:"code"`
Msg string `xml:"msg"`
}
func init() {
SenderMap["hywx"] = func() Sender {
return &Hywx{}
}
}
func (h *Hywx) Send(sms *SMS) error {
h.sms = sms
var data = make(url.Values)
data.Set("account", config.Vendors["hywx"]["account"])
data.Set("password", config.Vendors["hywx"]["password"])
data.Set("mobile", h.sms.Mobile)
data.Set("content", strings.Replace(h.sms.Config.Tpl, "{code}", h.sms.Code, -1))
res, err := http.PostForm(config.Vendors["hywx"]["RestURL"], data)
if err != nil {
return err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
if err := xml.Unmarshal(body, h); err != nil {
return err
}
if h.Code != 2 {
log.Errorf("%v", h)
return fmt.Errorf("%s", h.Msg)
}
return nil
}
Go
1
https://gitee.com/oss/smscode.git
git@gitee.com:oss/smscode.git
oss
smscode
smscode
master

搜索帮助