Browse Source

更新

master
huangjiajun 1 year ago
parent
commit
c8542731ce
2 changed files with 72 additions and 0 deletions
  1. +57
    -0
      hw_365/api.go
  2. +15
    -0
      utils/string.go

+ 57
- 0
hw_365/api.go View File

@@ -0,0 +1,57 @@
package hw_365

import (
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"strings"
)

func Send(url string, param map[string]string, secret string) string {
sign := getSign(param, secret)
param["sign"] = sign
for k, v := range param {
if v == "" {
continue
}
if strings.Contains(url, "?") == false {
url += "?" + k + "=" + php2go.URLEncode(v)
} else {
url += "&" + k + "=" + php2go.URLEncode(v)
}
}
return url
}

func SendOrder(url string, param map[string]string, secret string) string {
sign := getSign(param, secret)
param["sign"] = sign
for k, v := range param {
if v == "" {
continue
}
if strings.Contains(url, "?") == false {
url += "?" + k + "=" + php2go.URLEncode(v)
} else {
url += "&" + k + "=" + php2go.URLEncode(v)
}
}
data, _ := zhios_third_party_utils.CurlGet(url, nil)
list := gjson.Get(string(data), "data.list").String()
if list == "" {
list = gjson.Get(string(data), "data.order").String()
}
return list
}
func getSign(param map[string]string, secret string) string {
strMap := zhios_third_party_utils.KsortToStr(param)
str := ""
for _, v := range strMap {
if v == "sign" || param[v] == "" {
continue
}
str += zhios_third_party_utils.UderscoreToUpperCamelCase(v) + "=" + param[v] + "&"
}
str += "secretKey=" + secret
return strings.ToUpper(php2go.Md5(str))
}

+ 15
- 0
utils/string.go View File

@@ -201,3 +201,18 @@ func ShowSubstr(s string, l int) string {
}
return ss
}
func KsortToStr(params map[string]string) []string {
keys := make([]string, len(params))
i := 0
for k, _ := range params {
keys[i] = k
i++
}
sort.Strings(keys)
return keys
}
func UderscoreToUpperCamelCase(s string) string {
s = strings.Replace(s, "_", " ", -1)
s = strings.Title(s)
return strings.Replace(s, " ", "", -1)
}

Loading…
Cancel
Save