package unionpay import ( "bytes" "encoding/base64" "encoding/hex" "encoding/json" "fmt" "net/http" "net/url" "sort" "strings" "time" "git.chuangxin1.com/cx/util" "git.chuangxin1.com/cx/util/binding" ) const ( // TimeFmtNumeric format of time to numeric TimeFmtNumeric = `20060102150405` ) var ( base64Encode = base64.StdEncoding.EncodeToString base64Decode = base64.StdEncoding.DecodeString hexDump = hex.EncodeToString ) // TimeToNumericStr 时间转换为数字格式字符串 func TimeToNumericStr(t time.Time) string { return t.Format(TimeFmtNumeric) } // createLinkString unionpay sdk func func createLinkString(params map[string]string, isSort, isEncode bool) string { var ( keys []string ss []string ) if isSort { for key := range params { keys = append(keys, key) } sort.Strings(keys) for _, v := range keys { value := v + "=" if isEncode { value += url.QueryEscape(params[v]) } else { value += params[v] } ss = append(ss, value) } } else { for k, v := range params { value := k + "=" if isEncode { value += url.QueryEscape(v) } else { value += v } ss = append(ss, value) } } return strings.Join(ss, "&") } // POST 提交请求 func post(uri string, body []byte) (res ReqRespose, err error) { var msg util.Message headers := make(map[string]string) headers["Accept"] = "text/html; charset=UTF-8" headers["Accept-Encoding"] = "gzip, deflate, br" headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" msg, err = util.Post(uri, "", "", headers, bytes.NewReader(body)) if err != nil { return } if msg.StatusCode != http.StatusOK { err = fmt.Errorf("Request status code %d", msg.StatusCode) return } //* fmt.Println("*************************************") fmt.Println(uri) fmt.Println(msg.StatusCode) fmt.Println(msg.Header) fmt.Println(string(msg.Body)) fmt.Println("*************************************") // */ var values url.Values values, err = url.ParseQuery(string(msg.Body)) if err != nil { return } err = binding.MapForm(&res, values) //* if err != nil { return } bs, _ := json.Marshal(&res) fmt.Println(string(bs)) fmt.Println("respCode", res.RespCode, "respMsg", res.RespMsg) // */ return }