- 达达与美团配送的接口修改为较正式参数

This commit is contained in:
gazebo
2019-07-23 09:12:33 +08:00
parent 7ac11981b3
commit 7242dd435e
9 changed files with 255 additions and 81 deletions

View File

@@ -2,9 +2,7 @@ package utils
import (
"encoding/base64"
"fmt"
"net/http"
"net/url"
"reflect"
"strings"
"time"
@@ -172,14 +170,7 @@ func CallFuncRetryAsync(handler func(int) error, duration time.Duration, retryCo
func GenerateGetURL(baseURL, apiStr string, params map[string]interface{}) string {
queryString := ""
if params != nil {
for k, v := range params {
if queryString == "" {
queryString = "?"
} else {
queryString += "&"
}
queryString += k + "=" + url.QueryEscape(fmt.Sprint(v))
}
queryString = "?" + Map2URLValues(params).Encode()
}
if apiStr != "" {
return baseURL + "/" + apiStr + queryString

View File

@@ -235,3 +235,20 @@ func TestLimitUTF8StringLen(t *testing.T) {
t.Log(LimitUTF8StringLen("a大家好1234567", 8))
t.Log(LimitMixedStringLen("a大家好1234567", 8))
}
func TestGenerateGetURL(t *testing.T) {
fullURL := GenerateGetURL("http://www.163.com", "api", map[string]interface{}{
"k1": "v1",
"k2": 2,
})
t.Log(fullURL)
if fullURL != "http://www.163.com/api?k1=v1&k2=2" {
t.Fatal("GenerateGetURL错误")
}
fullURL = GenerateGetURL("http://www.163.com", "api", nil)
t.Log(fullURL)
if fullURL != "http://www.163.com/api" {
t.Fatal("GenerateGetURL错误")
}
}