190 lines
5.5 KiB
Go
190 lines
5.5 KiB
Go
|
package service
|
||
|
|
||
|
//
|
||
|
//import (
|
||
|
// "bytes"
|
||
|
// "dfp-open-sdk-go/config"
|
||
|
// "dfp-open-sdk-go/util"
|
||
|
// "encoding/base64"
|
||
|
// "encoding/json"
|
||
|
// "fmt"
|
||
|
// "github.com/google/uuid"
|
||
|
// "sort"
|
||
|
// "strings"
|
||
|
// "time"
|
||
|
//)
|
||
|
//
|
||
|
//type AbstractTranService interface {
|
||
|
//}
|
||
|
//
|
||
|
//func Txn(url string, method string, authInfo string, headParams map[string]string, bodyParamString map[string]string, filePath string,
|
||
|
// bodyParamMap map[string]string, keyConfigure config.KeyConfigure, bodyJson string) interface{} {
|
||
|
//
|
||
|
// return nil
|
||
|
//}
|
||
|
//func Send(reqUri string, reqMethod string, headParams map[string]string,
|
||
|
// urlParams map[string]string, bodyParamMap map[string]string, filePath string, KeyConfigure config.KeyConfigure,
|
||
|
// bodyJson string) {
|
||
|
// signParams := make(map[string]string)
|
||
|
// for k, v := range headParams {
|
||
|
// signParams[k] = v
|
||
|
// }
|
||
|
//
|
||
|
// for k, v := range urlParams {
|
||
|
// signParams[k] = v
|
||
|
// }
|
||
|
//
|
||
|
// for k, v := range bodyParamMap {
|
||
|
// signParams[k] = v
|
||
|
// }
|
||
|
//
|
||
|
// for json.Valid([]byte(bodyJson)) {
|
||
|
// signParams["BODY"] = bodyJson
|
||
|
// }
|
||
|
//
|
||
|
// authInfo := getAuthInfo(reqMethod, reqUri, signParams, KeyConfigure)
|
||
|
// urlParamString := util.JointMap(urlParams)
|
||
|
// bodyParamString := util.JointMap(bodyParamMap)
|
||
|
//
|
||
|
// var builder bytes.Buffer
|
||
|
// builder.WriteString(getPostUrl())
|
||
|
// builder.WriteString(reqUri)
|
||
|
//
|
||
|
// if urlParamString != "" {
|
||
|
// if strings.Contains(string(builder.Bytes()), "?") {
|
||
|
// builder.WriteString("&")
|
||
|
// } else {
|
||
|
// builder.WriteString("?")
|
||
|
// }
|
||
|
// builder.WriteString(urlParamString)
|
||
|
// }
|
||
|
//
|
||
|
// Txn(string(builder.Bytes()), reqMethod, authInfo, headParams, bodyParamString, filePath, bodyParamMap, KeyConfigure, bodyJson)
|
||
|
//}
|
||
|
//
|
||
|
//func execNetSign(reqUri string, reqMethod string, headParams map[string]string,
|
||
|
// urlParams map[string]string, bodyParamMap map[string]string, filePath string, KeyConfigure config.KeyConfigure,
|
||
|
// bodyJson string) interface{} {
|
||
|
// // 生成对称密钥
|
||
|
//
|
||
|
// signParams := make(map[string]string)
|
||
|
// for k, v := range headParams {
|
||
|
// signParams[k] = v
|
||
|
// }
|
||
|
//
|
||
|
// for k, v := range urlParams {
|
||
|
// signParams[k] = v
|
||
|
// }
|
||
|
//
|
||
|
// for k, v := range bodyParamMap {
|
||
|
// signParams[k] = v
|
||
|
// }
|
||
|
//
|
||
|
// for json.Valid([]byte(bodyJson)) {
|
||
|
// signParams["BODY"] = bodyJson
|
||
|
// }
|
||
|
//
|
||
|
// authInfo := getAuthInfo(reqMethod, reqUri, signParams, KeyConfigure)
|
||
|
// getNetAuthInfo(reqMethod, reqUri, commomKey, signParams, KeyConfigure)
|
||
|
// var builder bytes.Buffer
|
||
|
// builder.WriteString(getPostUrl())
|
||
|
// builder.WriteString(reqUri)
|
||
|
//
|
||
|
// if urlParamString != "" {
|
||
|
// if strings.Contains(string(builder.Bytes()), "?") {
|
||
|
// builder.WriteString("&")
|
||
|
// } else {
|
||
|
// builder.WriteString("?")
|
||
|
// }
|
||
|
// builder.WriteString(urlParamString)
|
||
|
// }
|
||
|
//
|
||
|
// Txn(string(builder.Bytes()), reqMethod, authInfo, headParams, bodyParamString, filePath, bodyParamMap, KeyConfigure, bodyJson)
|
||
|
//}
|
||
|
//
|
||
|
//func getAuthInfo(method string, uri string, signParams map[string]string, keyconfigure config.KeyConfigure) string {
|
||
|
// // 获取当前时间
|
||
|
// timestamp := time.Now().Format("yyyyHHddHHmmss")
|
||
|
// nonce := strings.Replace(uuid.New().String(), "-", "", -1)
|
||
|
//
|
||
|
// sprintf := fmt.Sprintf("%s&%s&%s&%s", keyconfigure.KeyId, timestamp, nonce, method)
|
||
|
// var builder bytes.Buffer
|
||
|
// builder.WriteString(sprintf)
|
||
|
// var keyList []string
|
||
|
// for key := range signParams {
|
||
|
// keyList = append(keyList, key)
|
||
|
// }
|
||
|
//
|
||
|
// sort.Strings(keyList)
|
||
|
//
|
||
|
// for _, key := range keyList {
|
||
|
// builder.WriteString("&")
|
||
|
// builder.WriteString(key)
|
||
|
// builder.WriteString("=")
|
||
|
// builder.WriteString(signParams[key])
|
||
|
// }
|
||
|
//
|
||
|
// user := keyconfigure.KeyId + "-" + timestamp + "_" + nonce
|
||
|
// var pwd string
|
||
|
// if keyconfigure.KeySignType == "SHA256WITHRSA" {
|
||
|
// pwd = util.SignatureByRSA(builder.String(), keyconfigure.PriKey)
|
||
|
// } else {
|
||
|
// pwd = util.SignatureBySM2(builder.String(), keyconfigure.PriKey)
|
||
|
// }
|
||
|
//
|
||
|
// return "Basic " + base64.StdEncoding.EncodeToString([]byte(user+":"+pwd))
|
||
|
//}
|
||
|
//
|
||
|
//func getNetAuthInfo(method string, uri string, commKey string, signParams map[string]string, keyconfigure config.KeyConfigure) string {
|
||
|
// // 获取当前时间
|
||
|
// timestamp := time.Now().Format("yyyyHHddHHmmss")
|
||
|
// nonce := strings.Replace(uuid.New().String(), "-", "", -1)
|
||
|
//
|
||
|
// sprintf := fmt.Sprintf("%s&%s&%s&%s&%s&%s", keyconfigure.KeyId, timestamp, nonce, method, uri, commKey)
|
||
|
// var builder bytes.Buffer
|
||
|
// builder.WriteString(sprintf)
|
||
|
// var keyList []string
|
||
|
// if signParams != nil {
|
||
|
// for key := range signParams {
|
||
|
// keyList = append(keyList, key)
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// sort.Strings(keyList)
|
||
|
//
|
||
|
// if signParams != nil {
|
||
|
// for _, key := range keyList {
|
||
|
// builder.WriteString("&")
|
||
|
// builder.WriteString(key)
|
||
|
// builder.WriteString("=")
|
||
|
// builder.WriteString(signParams[key])
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// // todo sm2公钥加密
|
||
|
// var encCommKey string
|
||
|
// user := keyconfigure.KeyId + "-" + timestamp + "_" + nonce + "_" + encCommKey
|
||
|
// var pwd string
|
||
|
// if keyconfigure.KeySignType == "SMA256WithRSA" {
|
||
|
// pwd = util.SignatureByRSA(builder.String(), keyconfigure.PriKey)
|
||
|
// } else {
|
||
|
// pwd = util.SignatureBySM2(builder.String(), keyconfigure.PriKey)
|
||
|
// }
|
||
|
//
|
||
|
// return "Basic " + base64.StdEncoding.EncodeToString([]byte(user+":"+pwd))
|
||
|
//}
|
||
|
//
|
||
|
//// 加密请求参数
|
||
|
//func GetEncryptBody(bodyParamMap map[string]string, commKey string) (map[string]string, error) {
|
||
|
// bodyParamJsonString, err := json.Marshal(bodyParamMap)
|
||
|
// encryptBodyParamMap := make(map[string]string)
|
||
|
//
|
||
|
// if err != nil {
|
||
|
// return nil, err
|
||
|
// }
|
||
|
//
|
||
|
// encryptBodyParamMap["ENC_DATA"] = util.Sm4Encrypt(string(bodyParamJsonString), commKey)
|
||
|
//
|
||
|
// return encryptBodyParamMap, nil
|
||
|
//}
|