1 Star 0 Fork 53

wateremh / smscode

forked from xluohome / smscode 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
juheapi.go 929 Bytes
一键复制 编辑 原始数据 按行查看 历史
xluo 提交于 2017-01-14 09:59 . v0.1
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
log "github.com/golang/glog"
)
type JuheApi struct {
Url string
Phone string
Key string
Result *ApiResult
}
type ApiResult struct {
Resultcode string `json:"resultcode"`
Result map[string]string `json:"result"`
Error_code int `json:"error_code"`
}
func NewJuheApi() *JuheApi {
return &JuheApi{Url: "http://apis.juhe.cn/mobile/get", Key: config.Juheapikey}
}
func (j *JuheApi) Query(phone string) error {
var url = fmt.Sprintf("%s?phone=%s&key=%s", j.Url, phone, j.Key)
log.V(1).Info(url)
res, err := http.Get(url)
if err != nil {
log.Error("JuheApi访问出错!!!")
return err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
log.V(1).Infof("%s", body)
if err := json.Unmarshal(body, &j.Result); err != nil {
return err
}
return nil
}
Go
1
https://gitee.com/wateremh/smscode.git
git@gitee.com:wateremh/smscode.git
wateremh
smscode
smscode
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891