package card_pay import ( zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" "crypto" "crypto/rand" "crypto/rsa" "encoding/base64" "fmt" "golang.org/x/crypto/ssh" mathRand "math/rand" "time" ) // //const ( // PrivateKeyStr = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCVaPSBsm6j+kRm\n4v+oy2b6hn3xt1czBcgUGhy00i97fccfOZI42FXr1dF+Y5EKefvcPSjiJZHezQyb\n/e6D9DIATF95r71cyLbmbxzb4PaDkVUuHYM1XeQSkTAD6kp3KAN8q6svxWYRkBaj\nq0CZ359zT+Py8lKkfCXpj6mx6XlUrbmORPaRTu9m0V08Mg+hCOXiPXXLCxBpx+Sj\nWHSvqgxqqo5R+Ks7Gjqtb0UJs0xE43w3Iuwpo4If/Bv4ScZ25RyhvL8v30x8kp2H\nI8z/BgXom6OrpMp/RBr27asXS/2TbIUFr3uLgG4mAysy/JYRIQU/mzneH59/7vRU\n8lt8C44TAgMBAAECggEAeRTYaa8nuN3dxx+ZHrrQFqEdueDh2uiJj7jloKhhcIuq\n7iQi2sx/PSNHpkycQ0g+EurBkhvuTggQeu5b+DXSu6kpCp2gMWw7xR0w3wQ94rvJ\nsxiZt4sChQWCSvn5JP2ZbdRVY95ubDdAEZ18Ofce6j1JNx6oWMJ/mvshA5x5BmSS\nZ7VJ/2MSLwknTWAzzEDdRpm9mDrF7paDSCtVnBjfUyhkrh5FkswFGbX7Jtg9TLP6\n3g1+Gy9Q0bi0khaOa4eUTmUdy1fKun2rUqbgo0CTO3pvvWX7TkSxcP2Mz+Rmpv1Z\nFNScT32+5G9yu1klYKQxztVf4sdRRDuQC/l5ZbiACQKBgQDE4ZnRHAcHb8jUdKH3\nIsoABLmObTJlN8MprXFYSz3YCwCbv/C8Nd3YboApUZBMNq/uTcbH2WS7fITtWaPq\n4xzfe5dL14gDSfRMyX6y/jY0Mi+EjVsZfB5RHtaxPh/aEC1dEtQZeCVPvq/Xim7C\nRPLKL3wCK1XlIy/sly6LJCHnZwKBgQDCRjRXkcMyUHziiWo7phIo+mC9gRRYdOyO\n5FhTiq1sWWsam8XLOKYh3rXIl8DhtphG736CI10AskZx2fQl5xe6UnhHNIyHQUxr\nBy3ncdAjyfR4qDxHT65aTcgygt9XpRpg3kgOZzJFfSdwZFhvvP/VzChhxbI9TCgB\ndoHG2glUdQKBgQCf9egiZNI1MZaLP2Pkxmg20Z/tXz0lzcOMVjYUFbXelTneUXmH\ngYCIe2c3quRBd+FDDgAmmbNlPQtHSKCMlA/+Z40KesgwW+LYjJGbXj2t9OR0nuDY\neOas5BBtG1uHscMZrtWTB/HQs85sojXRM3HL4f6wSINWU1t5r2+Kb0X4mwKBgH8O\nx0DWdiE7/tFyKeZlEM94ITkPaK0Jm4VA1nuc4RtRx/iZFF166TyRmbZdeaqlbyZF\nkCmw0yyXa/ceIs1/PEeBlGSNe7MiA8aj5WPPTd96P8eB0BqbhF5PLLXMXiHGO2BL\nQDkbSQeleNvK5QP/Shsb8PUxBQeN/UQnq2zQQPXZAoGBALcEWSE0pjJTI36isHPz\n005GVe4TTyIzXDQ24I8JP7nMg+Z+zyjcAePmcg49vvmMD32rrSynb+CqeL8RUD3N\nkDU1KZ8HgKOOapub1YP6KqWfKX5nN1id70voVefNeKxnOcyk09KNT32TTguo6WQs\nDWxJI9MWHEeoHXLOT5K0FVpP\n-----END PRIVATE KEY-----" // SignNo = "562265003122220003" // CustomerCode = "562265003122220" // PublicKeyStr = "MIID0jCCArqgAwIBAgIJAP7Hut/02gF6MA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV\nBAYTAkdaMQswCQYDVQQIDAJHRDELMAkGA1UEBwwCR1oxDTALBgNVBAoMBEVQQVkx\nEjAQBgNVBAsMCWVwYXlsaW5rczENMAsGA1UEAwwEeWlscjEjMCEGCSqGSIb3DQEJ\nARYUeWlsaXJlbkBlcGF5bGlua3MuY24wHhcNMjMwNDEz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ytLbIW0ibmQV+\ntpiZYSSfN6lzzX9NnQk3zGLv+UfIag==" //) func CardPaySend(method string, keyArr map[string]string, param map[string]string) (string, error) { url := "http://test-efps.epaylinks.cn/" + method //https://efps.epaylinks.cn/ for key, value := range param { if value == "" { delete(param, key) } } param["customerCode"] = keyArr["customerCode"] param["nonceStr"] = randomString(32) data := zhios_third_party_utils.SerializeStr(param) sign, err := CardPayGetSign(keyArr["privateKeyStr"], data) if err != nil { return "", err } headers := map[string]string{ "Content-Type": "application/json", "x-efps-sign-no": keyArr["signNo"], "x-efps-sign-type": "SHA256withRSA", "x-efps-sign": sign, "x-efps-timestamp": time.Now().Format("20060102150405"), } fmt.Println("参数:", zhios_third_party_utils.SerializeStr(param)) zhios_third_party_utils.CurlDebug = true res, err := zhios_third_party_utils.CurlPost(url, data, headers) if err != nil { return "", err } fmt.Println(string(res)) return string(res), nil } func CardPaySendSecond(method string, keyArr map[string]string, param map[string]interface{}) (string, error) { url := "http://test-efps.epaylinks.cn/" + method //https://efps.epaylinks.cn/ for key, value := range param { if value == "" { delete(param, key) } } param["customerCode"] = keyArr["customerCode"] param["nonceStr"] = randomString(32) data := zhios_third_party_utils.SerializeStr(param) sign, err := CardPayGetSign(keyArr["privateKeyStr"], data) if err != nil { return "", err } headers := map[string]string{ "Content-Type": "application/json", "x-efps-sign-no": keyArr["signNo"], "x-efps-sign-type": "SHA256withRSA", "x-efps-sign": sign, "x-efps-timestamp": time.Now().Format("20060102150405"), } fmt.Println("参数:", zhios_third_party_utils.SerializeStr(param)) zhios_third_party_utils.CurlDebug = true res, err := zhios_third_party_utils.CurlPost(url, data, headers) if err != nil { return "", err } fmt.Println(string(res)) return string(res), nil } func CardPayApplySend(method string, keyArr map[string]string, param map[string]string) (string, error) { url := "http://test-efps.epaylinks.cn/" + method //https://efps.epaylinks.cn/ for key, value := range param { if value == "" { delete(param, key) } } data := zhios_third_party_utils.SerializeStr(param) sign, err := CardPayGetSign(keyArr["privateKeyStr"], data) if err != nil { return "", err } headers := map[string]string{ "Content-Type": "application/json", "x-efps-sign-no": keyArr["signNo"], "x-efps-sign-type": "SHA256withRSA", "x-efps-sign": sign, "x-efps-timestamp": time.Now().Format("20060102150405"), } fmt.Println("参数:", zhios_third_party_utils.SerializeStr(param)) zhios_third_party_utils.CurlDebug = true res, err := zhios_third_party_utils.CurlPost(url, data, headers) if err != nil { return "", err } fmt.Println(string(res)) return string(res), nil } func randomString(ln int) string { letters := []rune("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") b := make([]rune, ln) r := mathRand.New(mathRand.NewSource(time.Now().UnixNano())) for i := range b { b[i] = letters[r.Intn(len(letters))] } return string(b) } func CardPayGetSign(privateKeyStr string, data string) (string, error) { privateKey, err := ssh.ParseRawPrivateKey([]byte(privateKeyStr)) if err != nil { return "", err } fmt.Println(privateKey.(*rsa.PrivateKey)) fmt.Println(data) h := crypto.Hash.New(crypto.SHA256) h.Write([]byte(data)) hashed := h.Sum(nil) sign, err := rsa.SignPKCS1v15(rand.Reader, privateKey.(*rsa.PrivateKey), crypto.SHA256, hashed) if err != nil { return "", nil } return base64.StdEncoding.EncodeToString(sign), nil }