<returnsms> <returnstatus>Success</returnstatus> <message>ok</message> <remainpoint>150528</remainpoint> <taskID>518334</taskID> <successCounts>1</successCounts> </returnsms>
解析
//xml的struct结构 type Duanxin struct { Returnstatus string `xml:"returnstatus"` Message string `xml:"message"` Remainpoint string `xml:"remainpoint"` TaskID string `xml:"taskID"` SuccessCounts string `xml:"successCounts"` } //发手机短信 func Send_duanxin(mobile int64, content string) (dx Duanxin, err error) { m := strconv.FormatInt(mobile, 10) if len(content) < 30 { return dx, errors.New("内容少于30个字符") } content = content + "【XX公司发送】" SendUrl := beego.AppConfig.String("sendurl") url := SendUrl + "&mobile=" + m + "&content=" + content resp, err := http.Get(url) if err != nil { return dx, err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return dx, err } err = xml.Unmarshal(body, &dx)//好方便,就这样就解析了xml,so关键是xml的结构 return dx, err }