联系客服: iP138.com客服89932929 iP138.com客服1586314992
手机号码查询接口

手机号码查询接口支持HTTPS(赠送1000次)

简介:获取手机号码段的省市区以及运营商名称

已连接应用数:31748

  • API接口QQ交流群:177096428   iP138 api接口
  • 数据修正QQ处理群:94181690    iP138数据修正

国内:网宿cdn; 国际:亚洲中国香港、韩国首尔、日本东京、新加坡、泰国曼谷、欧洲德国法兰克福、北美洲美国硅谷、南美洲巴西圣保罗

Go语言调用手机号码查询接口示例:

                                            package main

                                            import (
                                                "encoding/json"
                                                "encoding/xml"
                                                "fmt"
                                                "io/ioutil"
                                                "net/http"
                                            )

                                            const (
                                                URL   = "https://api.ip138.com/mobile/"
                                                TOKEN = "bd4c2bf9a38ab06f7cae88c9759ee172"
                                            )

                                            //----------------------------------
                                            // 手机号查询接口调用示例代码
                                            //----------------------------------

                                            // xml struct
                                            type xmlinfo struct {
                                                Ret  string          `xml:"ret"`
                                                Mobile string        `xml:"mobile"`
                                                Data locationxmlInfo `xml:"data"`
                                            }

                                            type locationxmlInfo struct {
                                                Province string `xml:"province"`
                                                City     string `xml:"city"`
                                                Card     string `xml:"card"`
                                                Zone     string `xml:"zone"`
                                            }

                                            //json struct
                                            type jsoninfo struct {
                                                Ret     string    `json:"ret"`
                                                Mobile   string    `json:"mobile"`
                                                Data [4] string    `json:"data"`
                                            }

                                            func main() {
                                                mobileLocation("13600130000","xml")
                                            }

                                            func mobileLocation(mobile string,dataType string) {

                                                queryUrl := fmt.Sprintf("%s?mobile=%s&datatype=%s",URL,mobile,dataType)
                                                client := &http.Client{}
                                                reqest, err := http.NewRequest("GET",queryUrl,nil)

                                                if err != nil {
                                                    fmt.Println("Fatal error ",err.Error())
                                                }

                                                reqest.Header.Add("token",TOKEN)
                                                response, err := client.Do(reqest)
                                                defer response.Body.Close()

                                                if err != nil {
                                                    fmt.Println("Fatal error ",err.Error())
                                                }
                                                if response.StatusCode == 200 {
                                                    bodyByte, _ := ioutil.ReadAll(response.Body)

                                                    if dataType == "jsonp" {
                                                        var info jsoninfo
                                                        json.Unmarshal(bodyByte,&info)
                                                        fmt.Println(info.Mobile)
                                                    } else if dataType == "xml" {
                                                        var info xmlinfo
                                                        xml.Unmarshal(bodyByte,&info)
                                                        fmt.Println(info.Mobile)
                                                    }
                                                }

                                                return
                                            }