参考ui效果:
https://www.kuaidi100.com/?from=openv
思路:
调用快递100的接口,可以免费查询快递跟踪记录了...
线上请求地址 https://test.ibanana.club/kd100/auto_com_num?num=73119782411952
线上请求地址 https://test.ibanana.club/kd100/query_num_detail?num=73119782411952&comCode=zhongtong
//路由 router.GET("/kd100/auto_com_num", controller.AutoComNum) //获取快递公司类型 router.GET("/kd100/query_num_detail", controller.QueryNumDetail) //获取快递跟踪信息 //获取快递公司类型 func AutoComNum(ctx *gin.Context) { //fmt.Println("AutoComNum...") text := ctx.Query("num") //单号 url := "https://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=" + text paramData := gin.H{} headerData := make(map[string]string, 1) headerData["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0" resp := SendPostWithHeard(url, paramData, headerData) respData := gin.H{} if err := json.Unmarshal([]byte(resp), &respData); err != nil { fmt.Println("voucher_detail_list", err) } fmt.Println(respData) httpext.SuccessExt(ctx, respData) } //获取快递跟踪信息 func QueryNumDetail(ctx *gin.Context) { //fmt.Println("AutoComNum...") postid := ctx.Query("num") //单号 kdtype := ctx.Query("comCode") //快递类型 temp := strconv.Itoa(int(time.Now().UnixNano())) //时间戳 //phone := "" //手机号,默认为空 url := fmt.Sprintf("https://www.kuaidi100.com/query?postid=%s&type=%s&temp=%s",postid,kdtype,temp) fmt.Println("url:",url) resp:=httpext.SendtGet(url) respData := gin.H{} if err := json.Unmarshal([]byte(resp), &respData); err != nil { fmt.Println("voucher_detail_list", err) } fmt.Println(respData) fmt.Println(respData["status"]) if respData["status"]!= "200"{ httpext.ErrorExt(ctx, e.INVALID_PARAMS,respData) return } httpext.SuccessExt(ctx, respData) }
来源:https://www.cnblogs.com/haima/p/12658956.html