2020年04月21日
Md5生成
func md5V3(str string) string {
w := md5.New()
io.WriteString(w, str)
md5str := fmt.Sprintf("%x", w.Sum(nil))
return strings.ToUpper(md5str)
}
GetUrl
//GET方式提交请求至服务端
func GetUrl() {
// 请求参数
appkey := "7819fc**709142eeb32e10bc44ce19f3"
seckey := "F39AC**D7A83C5E606F94291DF46554B"
//encode := "utf-8"
// Http请求头设置
timespan := strconv.FormatInt(time.Now().Unix(),10)
token := appkey + timespan + seckey
log.Println(token)
cipherStr :=md5V3(token)
log.Println("MD5加密后为 :", cipherStr)
// 设置请求Url-请自行设置Url
reqInterNme := "http://api.qichacha.com/ECIV4/Search"
paramStr := "keyword=阿里巴巴"
urlString := reqInterNme + "?key=" + appkey + "&" + paramStr
log.Println("url="+urlString)
// nil 位置参数是Header
// 其设置值在下面的两句
// req.Header.Set("Token", cipherStr)
// req.Header.Set("Timespan", timespan)
req, err := http.NewRequest("GET",urlString, nil)
req.Header.Set("Token", cipherStr)
req.Header.Set("Timespan", timespan)
client := &http.Client{}
resp, err := client.Do(req)
log.Println(err)
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
log.Println("Result:")
fmt.Println(string(body))
}
这是一个调取开发平台接口的代码实例,相关对Java语言实现,代码量少了许多。
其运行结果:
Start WebClient Post ......
2020/04/21 21:32:24 Start WebClient Post ......
2020/04/21 21:32:24 7819fc0c709142eeb32e10bc44ce19f31587475944F39ACEED7A83C5E606F94291DF46554B
2020/04/21 21:32:24 MD5加密后为 : 8267A1976D7825C42C6A4FC4EFE87F29
2020/04/21 21:32:24 url=http://api.qichacha.com/ECIV4/Search?key=7819fc0c709142eeb32e10bc44ce19f3&keyword=阿里巴巴
2020/04/21 21:32:24 <nil>
2020/04/21 21:32:24 Result:
{"OrderNumber":"ECI2020042121332556965358","Paging":{"PageSize":10,"PageIndex":1,"TotalRecords":8029},"Result":[{"KeyNo":"c70a55cb048c8e4db7bca357a2c113e0","Name":"阿里(中国)网络技术有限公司","OperName":"戴珊","StartDate":"1999-09-09 00:00:00","Status":"存续","No":"330100400015575","CreditCode":"91330100716105852F"},{"KeyNo":"eaed3bd411a8ac76","Name":"浙江阿里巴巴机器人有限公司","OperName":"陈丽娟","StartDate":"2016-06-23 00:00:00","Status":"存续","No":"330108400000100","CreditCode":"91330108MA27Y8c9f7ddc1a7bcee3d1f7676773fe9404","Name":"阿里巴巴(中国)有限公司","OperName":"张勇","StartDate":"2007-03-26 00:00:00","Status":"存续","No":"330100400013364","CreditCo655058B"},{"KeyNo":"h7a5a6c405fca1754b9ef13a6a174600","Name":"阿里巴巴集團控股有限公司","OperName":"张勇","StartDate":"2019-11-07 00:00:00","Status":"仍注册","No":"F002":""},{"KeyNo":"64a93974d8dcdf7e250333a589cd5a77","Name":"阿里巴巴丝路有限公司","OperName":"张建锋","StartDate":"2017-11-24 00:00:00","Status":"在业","No":"610131100396e":"91610131MA6UAL4458"},{"KeyNo":"3adac8c0b3859baebd6be029f7a69a67","Name":"杭州阿里巴巴泽泰信息技术有限公司","OperName":"陈嫄","StartDate":"2016-11-15 00:00:00","Stat184000545565","CreditCode":"91330110MA28054B7Q"},{"KeyNo":"d771936aea1c205bdb6cf96d5e93172c","Name":"阿里巴巴华北技术有限公司","OperName":"童文红","StartDate":"2017-11-tatus":"存续","No":"120222000648184","CreditCode":"91120222MA05Y0CR4B"},{"KeyNo":"aebb375105cf81a29339e2e8f10e2571","Name":"阿里巴巴(江西)有限公司","OperName":"郭坤坤19-05-20 00:00:00","Status":"存续","No":"","CreditCode":"91360125MA38LAFY5X"},{"KeyNo":"b0fa3d310df2c236415d638d18da195c","Name":"阿里巴巴华南技术有限公司","OperName":"e":"2017-11-21 00:00:00","Status":"在业","No":"440125000363995","CreditCode":"91440101MA5ALRRJ0E"},{"KeyNo":"15d5ced8fd4eb62ddb7d203b46b81e43","Name":"阿里巴巴(重庆)有Name":"李津","StartDate":"2018-04-20 00:00:00","Status":"存续","No":"","CreditCode":"91500000MA5YUUWB6M"}],"Status":"200","Message":"查询成功"}
Process finished with exit code 0
只是个人做的一个笔记。其他阅读者有可能看不太明白。呵呵!