- elm and weixin token refresh.

This commit is contained in:
gazebo
2018-06-26 15:26:39 +08:00
parent 910c9e02d1
commit ee4e88594d
8 changed files with 241 additions and 30 deletions

View File

@@ -40,7 +40,7 @@ const (
)
const (
prodURL = "https://openo2o.jd.com/djapi/%s"
prodURL = "https://openo2o.jd.com/djapi"
signKey = "sign"
AllPage = 0
DefaultPageSize = 50
@@ -107,23 +107,6 @@ func (a *API) signParams(jdParams map[string]interface{}) string {
return fmt.Sprintf("%X", md5.Sum([]byte(allStr)))
}
func generateURL(baseURL, apiStr string, params map[string]interface{}) string {
fullURL := ""
if params != nil {
for k, v := range params {
if fullURL == "" {
fullURL = "?"
} else {
fullURL += "&"
}
fullURL += k + "=" + url.QueryEscape(fmt.Sprint(v))
}
}
return fmt.Sprintf(baseURL, apiStr) + fullURL
}
func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
curConfig := platformapi.DefAPIConfig
if len(config) > 0 {
@@ -159,7 +142,7 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal
sign := a.signParams(params)
params[signKey] = sign
url, _ := url.Parse(generateURL(prodURL, apiStr, params))
url, _ := url.Parse(utils.GenerateGetURL(prodURL, apiStr, params))
request := &http.Request{
Method: "GET",
URL: url,

View File

@@ -84,7 +84,7 @@ func TestGenerateURL(t *testing.T) {
params["key"] = "v"
params["key2"] = "v2"
fullURL := generateURL(prodURL, "address/allcities", params)
fullURL := utils.GenerateGetURL(prodURL, "address/allcities", params)
response, err := http.Get(fullURL)
if err != nil {