@@ -3,12 +3,14 @@ module code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git | |||||
go 1.15 | go 1.15 | ||||
require ( | require ( | ||||
github.com/forgoer/openssl v1.2.1 | |||||
github.com/gin-gonic/gin v1.8.0 | github.com/gin-gonic/gin v1.8.0 | ||||
github.com/go-redis/redis v6.15.9+incompatible | github.com/go-redis/redis v6.15.9+incompatible | ||||
github.com/go-sql-driver/mysql v1.6.0 | github.com/go-sql-driver/mysql v1.6.0 | ||||
github.com/gomodule/redigo v1.8.8 | github.com/gomodule/redigo v1.8.8 | ||||
github.com/iGoogle-ink/gopay v1.5.36 | github.com/iGoogle-ink/gopay v1.5.36 | ||||
github.com/pkg/errors v0.9.1 | github.com/pkg/errors v0.9.1 | ||||
github.com/syyongx/php2go v0.9.7 | |||||
go.uber.org/zap v1.16.0 | go.uber.org/zap v1.16.0 | ||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 | ||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 | gopkg.in/natefinch/lumberjack.v2 v2.0.0 | ||||
@@ -0,0 +1,202 @@ | |||||
package pay | |||||
import ( | |||||
zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils" | |||||
"crypto" | |||||
"crypto/md5" | |||||
"crypto/rand" | |||||
"crypto/rsa" | |||||
"crypto/x509" | |||||
"encoding/base64" | |||||
"encoding/json" | |||||
"encoding/pem" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/forgoer/openssl" | |||||
"github.com/syyongx/php2go" | |||||
"golang.org/x/crypto/ssh" | |||||
mathRand "math/rand" | |||||
"sort" | |||||
"time" | |||||
) | |||||
/*** | |||||
method fastPay.agreement.signSms | |||||
data 请求交易的数据,具体参数见下表 | |||||
mch_no 商户在支付平台系统的唯一身份标识。(注:商户编号和商户密钥在汇聚商户后台获取) | |||||
pub_key 公钥 | |||||
pri_key 私钥 | |||||
*/ | |||||
func GetSms(pubKey, platformKey, priKey, mch_no string, args map[string]string) (string, error) { | |||||
param := map[string]string{ | |||||
"mch_no": mch_no, | |||||
} | |||||
param["sec_key"] = randomString(16) | |||||
args["payer_name"] = AesEncryptECB([]byte(args["payer_name"]), []byte(param["sec_key"])) | |||||
args["id_no"] = AesEncryptECB([]byte(args["id_no"]), []byte(param["sec_key"])) | |||||
args["bank_card_no"] = AesEncryptECB([]byte(args["bank_card_no"]), []byte(param["sec_key"])) | |||||
args["mobile_no"] = AesEncryptECB([]byte(args["mobile_no"]), []byte(param["sec_key"])) | |||||
data, _ := json.Marshal(args) | |||||
param["data"] = string(data) | |||||
send, err := Send("fastPay.agreement.signSms", platformKey, priKey, param) | |||||
return send, err | |||||
} | |||||
func SignContract(pubKey, platformKey, priKey, mch_no string, args map[string]string) (string, error) { | |||||
param := map[string]string{ | |||||
"mch_no": mch_no, | |||||
} | |||||
param["sec_key"] = randomString(16) | |||||
data, _ := json.Marshal(args) | |||||
param["data"] = string(data) | |||||
send, err := Send("fastPay.agreement.smsSign", platformKey, priKey, param) | |||||
return send, err | |||||
} | |||||
func UnSignContract(pubKey, platformKey, priKey, mch_no string, args map[string]string) (string, error) { | |||||
param := map[string]string{ | |||||
"mch_no": mch_no, | |||||
} | |||||
param["sec_key"] = randomString(16) | |||||
args["sign_no"] = AesEncryptECB([]byte(args["sign_no"]), []byte(param["sec_key"])) | |||||
data, _ := json.Marshal(args) | |||||
param["data"] = string(data) | |||||
send, err := Send("fastPay.agreement.unSign", platformKey, priKey, param) | |||||
return send, err | |||||
} | |||||
func GetPaySms(pubKey, platformKey, priKey, mchNo string, args map[string]string) (string, error) { | |||||
param := map[string]string{ | |||||
"mch_no": mchNo, | |||||
} | |||||
param["sec_key"] = randomString(16) | |||||
args["sign_no"] = AesEncryptECB([]byte(args["sign_no"]), []byte(param["sec_key"])) | |||||
data, _ := json.Marshal(args) | |||||
param["data"] = string(data) | |||||
send, err := Send("fastPay.agreement.paySms", platformKey, priKey, param) | |||||
return send, err | |||||
} | |||||
func PayDoing(pubKey, platformKey, priKey, mchNo string, args map[string]string) (string, error) { | |||||
param := map[string]string{ | |||||
"mch_no": mchNo, | |||||
} | |||||
param["sec_key"] = randomString(16) | |||||
data, _ := json.Marshal(args) | |||||
param["data"] = string(data) | |||||
send, err := Send("fastPay.agreement.smsPay", platformKey, priKey, param) | |||||
return send, err | |||||
} | |||||
func Send(method, platformKey, priKey string, param map[string]string) (string, error) { | |||||
//priKey = strings.ReplaceAll(priKey, "+", "\n") | |||||
//priKey = "-----BEGIN PRIVATE KEY-----\n" + priKey + "\n-----END PRIVATE KEY-----" | |||||
router := "https://api.joinpay.com/fastpay" | |||||
param["method"] = method | |||||
param["version"] = "1.0" | |||||
param["rand_str"] = randomString(32) | |||||
param["sign_type"] = "2" | |||||
sign, err := GetSign(priKey, param) | |||||
if err != nil { | |||||
return "", err | |||||
} | |||||
param["sign"] = sign | |||||
if param["sec_key"] != "" { //rsa加密 | |||||
encrypts, err := RsaEncrypts([]byte(param["sec_key"]), []byte(platformKey)) | |||||
if err != nil { | |||||
return "", err | |||||
} | |||||
param["sec_key"] = string(encrypts) | |||||
} | |||||
post, err := zhios_pay_utils.CurlPost(router, param, nil) | |||||
fmt.Println(string(post)) | |||||
fmt.Println(err) | |||||
return string(post), nil | |||||
} | |||||
func GetSign(privateKeyStr string, param map[string]string) (string, error) { | |||||
privateKey, err := ssh.ParseRawPrivateKey([]byte(privateKeyStr)) | |||||
if err != nil { | |||||
return "", err | |||||
} | |||||
keys := make([]string, 0, len(param)) | |||||
for k := range param { | |||||
keys = append(keys, k) | |||||
} | |||||
sort.Strings(keys) | |||||
data := "" | |||||
for _, v := range keys { | |||||
if v == "sign" || v == "sec_key" { | |||||
continue | |||||
} | |||||
if data != "" { | |||||
data += "&" + v + "=" + param[v] | |||||
} else { | |||||
data += v + "=" + param[v] | |||||
} | |||||
} | |||||
fmt.Println("md5 before2:>>>>", data) | |||||
hashMd5 := md5.Sum([]byte(data)) | |||||
fmt.Println("md5 before2:>>>>", hashMd5) | |||||
hashed := hashMd5[:] | |||||
fmt.Println("hashed:>>>>", hashed) | |||||
fmt.Println("hashed_string:>>>>", string(hashed)) | |||||
sign, err := rsa.SignPKCS1v15(rand.Reader, privateKey.(*rsa.PrivateKey), crypto.MD5, hashed) | |||||
if err != nil { | |||||
return "", err | |||||
} | |||||
return base64.StdEncoding.EncodeToString(sign), nil | |||||
} | |||||
// 公钥加密 | |||||
func RsaEncrypts(data, keyBytes []byte) (string, error) { | |||||
var ciphertext string | |||||
//解密pem格式的公钥 | |||||
block, _ := pem.Decode(keyBytes) | |||||
if block == nil { | |||||
return ciphertext, errors.New("公钥错误") | |||||
} | |||||
// 解析公钥 | |||||
pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes) | |||||
if err != nil { | |||||
return ciphertext, err | |||||
} | |||||
// 类型断言 | |||||
pub := pubInterface.(*rsa.PublicKey) | |||||
//加密 | |||||
ciphertext1, err := rsa.EncryptPKCS1v15(rand.Reader, pub, data) | |||||
if err != nil { | |||||
return ciphertext, err | |||||
} | |||||
return base64.StdEncoding.EncodeToString(ciphertext1), 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 AesEncryptECB(origData []byte, key []byte) string { | |||||
str, _ := openssl.AesECBEncrypt(origData, key, openssl.PKCS7_PADDING) | |||||
value := php2go.Base64Encode(string(str)) | |||||
return value | |||||
} | |||||
func generateKey(key []byte) (genKey []byte) { | |||||
genKey = make([]byte, 16) | |||||
copy(genKey, key) | |||||
for i := 16; i < len(key); { | |||||
for j := 0; j < 16 && i < len(key); j, i = j+1, i+1 { | |||||
genKey[j] ^= key[i] | |||||
} | |||||
} | |||||
return genKey | |||||
} |
@@ -7,20 +7,8 @@ import ( | |||||
"time" | "time" | ||||
) | ) | ||||
func TestPay(t *testing.T) { | |||||
err := Init("119.23.182.117:3306", "zyos_website", "root", "Fnuo123com@") | |||||
if err != nil { | |||||
t.Errorf("Reverse == %s", err) | |||||
} | |||||
channel, err := JudgePayChannel("35618318", "mall") | |||||
if err != nil { | |||||
t.Errorf("Reverse == %s", err) | |||||
} | |||||
fmt.Println(channel.AppId) | |||||
t.Log(channel.MasterNickname) | |||||
} | |||||
func TestIcbc(t1 *testing.T) { | func TestIcbc(t1 *testing.T) { | ||||
t:=time.Now() | |||||
t := time.Now() | |||||
stime := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05") | stime := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05") | ||||
fmt.Println(stime) | fmt.Println(stime) | ||||
} | } | ||||
@@ -34,7 +22,7 @@ func TestIcbcShow(t *testing.T) { | |||||
"cardNo": "5305068200048153", | "cardNo": "5305068200048153", | ||||
"cardType": "C", | "cardType": "C", | ||||
} | } | ||||
integral, err := icbc.ShowIntegral("10000000000000203505", "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCZBYj5SOjewCZ+\nGx2dAj/Lvp/TlDeVseoUl7V1X4K0jzAyo8kwYzMip5SPKj64zbkydyxqUOdEI5vk\nhfUtnZcb8PI7+lhgoBc6nv7Po+pZuP+0OkxhRvgbL+b0O/e2I3dQJOmfafQNLU1x\n3Nf3uqHtLbFuzrGKmG7zrP6to+tqY7+a+mq/o59ZSkDTWFH094jsrLtngu85hKSf\n0N7moxak+LWJF0Czqd4xI8kXfIW5O3t/jaWJPomm1fZSjlbf4VvPXVahkLOV4+Tk\naTlbMrc7ouGPVTGQo0UtWX4CVy30/QvDMfUuhTSw7S/xMO+u7r4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2J\nsASo+t6VOoLwraZwO/ki7p9DDb+iAfjo1UboyqW5iQKBgQCzXyhRfacrW0kgmEp6\nCWR0oQgD54aXj1JjUkEe+gE6E7LY9Cl+yAdHBYmyCzS014jNX93+Bpg1XhoR1knO\n78A8Q7sPCrP908ycKul668daDXHp55CGpScxsx3z9jJs5ori+ZncSDAnHf0T0OjX\n+nDJPGN/gp9/WqApT1L4SLlDxg==\n-----END PRIVATE KEY-----", param) | |||||
integral, err := icbc.ShowIntegral("011904180095001", "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDFaVbTHQF1WNlz\n0ZFgioxApDFBtwlVsoJ8Ov6WdfKLO5aikZjZJNcR2dhtgFSCvpLx/L6p/v+Jv6kl\nnJ6ZGdH1e8Yy7zcrOZd20KNawfsVYfbMFZ0yqygAfif96Uw0k2qwpXLZ6KSlV/PT\nA900571+yv2o4mu7fyHTimojwcrfVIKu+6kgidlHd7usciEvvcplV7xafZmzpG+h\n+qlF8iQ9hxou85dvF9HBox8ZkFay0xMy/QqXRYxzIaZgfAF0io/tuthol+6WUZ/M\nLzzkAwn9E4/YM1GE3qzXXE5TZmyEOV/pE+VKzfhj5sMrO1EnzLAsWGWXNd4ISKsV\noeGmtnFpAgMBAAECggEBAL7fOQnqc6yIecgYCt4zV6RwnQeS+D2Z2bxQNjQ4Wojw\n1pbc+9KIYkJqRW6qtAuuQ9ohrCAl4+HGJL+vDVGuu2kFgf9heBAdISvKUwe/owtr\nqvpss494GbdQQ06nsfzrxC6D6eZzoC4WOjP++nTa1Eex8UzHj668H3Kv1Cw6hfMj\nymxsjvV6X6a0Dp2IXiqzDlWRYPzrj3TLxz1AOLyNJP1VaVHaizTL45AT5+9dtkNc\n0kF4KTCfYLMZK9BjlgtgL4dTVun/MVuVeYb2xYUUdJ/lZ501xnwc/OG1zRPmmnIe\nPC8d6kr1VqvODL2xsPZFjha+oIhkVQPvOyjqfNLtBRkCgYEA49TsSdj8wC8iGXs7\nhXTCylH28Fomx1DITujYabhYtfmDD0IIBUU3drOtl8VHDby7wX7pDgCT8JEvbPLQ\n3FlxEgw6YWfhkOo/64MMK6hE9f0VQh2vnWL3S/5zpll5r2ZHkib4SkjWSC2q9qNA\n30lsdCAIJk3xuv6plv+9Q/0M6WsCgYEA3dGWk/o2MU589j4UspWjPSBAMyI/thzX\nYGn73jvk+RAPOxwXkAA0A9azqwvE8YfoQSNe8128OpSvcnmreXc4HphLCeR/Fbls\nDxI/f8C3Qn/LmGK8P795kQaZRDzHw1gBRpshGjEuQy7m7psR14o8gM7cof73d71W\nMzvGEPeioXsCgYEAmQpzOtv2VEaU+lbsUaZwHqXWYfe86tBZ7Z+9l66McJjNr9ck\nOh4XtrXVmwiaxSCNYtoURSKgPc3Y9K9bG1k9eeka4kl8nPKtw08BQuZChJbfy8zT\nJb7P7Y1cNFcQRYFH/GYPDR9GSa/bktdxAUx5/Ltznf9nrLvaQaNCiMQYA0cCgYA0\nomoHnQTE+GngiGSi56z/cSqqt4LEtN1KbHuuhSnVC8GBdi4FJncxPf4OJVHLOkOb\nSUhbmS9z+xoSoNpWjTqMz/hmVYjuX7xLazoUF2ek6Ownsa4XtlijWByAO6fvK2/K\nED9vlqHyoSt9DODT82Jd8jgaXITeLdhJefKKzigSBwKBgH7miTS77XP1n5nMMlbp\nNVPWF40CB7bt4VBslrJA/u0dmEfEKAhRBh6Cg1+l88Q4o/eWR/RjzqTR1Q3XaS3d\nQcwMzAiA+4aqtywStD8v6iRsA/p9A5QYjPsKze3B6urNgzGz8hMqsRLL3NyeYS+3\nCtK4zuKHZKPLivbxALqfJKkH\n-----END PRIVATE KEY-----", param) | |||||
fmt.Println(integral) | fmt.Println(integral) | ||||
fmt.Println(err) | fmt.Println(err) | ||||
} | } | ||||