1 Star 0 Fork 53

joliny / smscode

forked from xluohome / smscode 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
f_hywx.go 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
xluo 提交于 2017-02-01 21:34 . v0.11 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 (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.Error("%v", h)
return fmt.Errorf("%s", h.Msg)
}
return nil
}
func init() {
smsvendor["hywx"] = &Hywx{}
}
Go
1
https://gitee.com/jbakwd/smscode.git
git@gitee.com:jbakwd/smscode.git
jbakwd
smscode
smscode
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891