|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package boc
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
- zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
- "fmt"
- "github.com/syyongx/php2go"
- "time"
- )
-
- const (
- MerchantId = "888007050019400"
- TerminalNo = "98036140"
- PrivateKeyStr = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCSJk259Gd9IuvG\nRxYOma5vjo0+x2CTyP7m3uJ/epf+mwp/4XySbjVharBFmKk0XoSnZz/X/cYOgQXH\nPWPnBd0Y4qTl3xVf+DdZHF035KNG0LJPqvzqOSCuD5w32BHN0o9wFaR75PbWfsUl\nn2XqLVRFdv3IaKJYVWb8fM7VLT0aA+Rk81GXGfAbmXzNqX3lbOkqlTcBdzMHdE94\nqpAxtppVJ8JQqRJsWwzqJHo2koN+/kb3vL9IxeABJGUgU4Fy53MuC7JcvdYUoE7V\n92eD6A9g6ctSHP5y7olx9T7uMAaHk/TDv3+QNk6rI54cif7V7C5ykhtH5ZfHQ27C\nx929l7LZAgMBAAECggEAVZfVQajfyyvehbswMdDTlkYYdsHxz9uRXcj/QcWcquJG\nXerDOEcPQERpg/kKb79DVX9kpqzbh7cMmUlc7vpCKMbj6DSkohYO5EN2XLus3FZx\nd7MeeFaIyygdR59lnfNJSk2CjYTlA24vK/+UgneVuTEdJHgTTESIEitOPw9Fj6v+\n/+vRwuT6PVDm1FDUxFcYmJYzdMwJZoH0wDymofiEdn6beaHkqDXakrdY307cHOlq\ncrVQJKSybLwcBsbk9pgGrh6lCQLtQ8pHNtf6rE5FkEesO/VmdRFDGAK/9cuXEJ7u\nICdSESdfvnKl9BeN3MzSaeDSnh2IPoz13VVxXuJF+QKBgQDfHBVA/e1XFrLDM5IW\nO6nIxZeeZSufITDKHi7qRoS2mlOwjpMoIVAHCxlpnWd89YQ7NPdScEi6Z7l2sEET\n0vKfWsJ3ltowj5QUXS0XuJeAhkmK66lBNrICkatoAGeWxDrraCgkqLPNe40ydQ6h\nT2c3nR8tf++U2TzCpCXxzj6pgwKBgQCnsdTIWKwhRIltTgEzXTh3+JMQ36MH3sVt\nP14bxRN1hlR59yQvx0IEToXOHASSRU0fWxj3H8UewobYmE+2Ro+qNHFY7Do7Ypum\nIM7In00Tx4CKOVOkMZtNtR9hPk2/JUKpPSQBl7dSysBDngAwGhBhpwutWDpEiIfL\n+P4pAFuvcwKBgDrPUT7ncDdjkU1o+5oGshNtGjEzY9M3UYAFgsJYQkVL2sGQY3PR\njCG/KDyxtAS5RtjAdmzxkgooqzeA8DaEhVXB+77AMdVZE2RmxysYij7jpuEKi3vY\nKgYJVdA9QxD3urwwoVxAZ9zDM43YUznsDz4WmZBJx+JJfP2lfScHAXd3AoGAMpRR\noKgWKuaYKM7JT+vDF3RzLzi03K/VjnD5epjDmMQOgMcJNBv+jnv8ocETo+ahL17z\ntb3wX6m+sF+oU0sPFABDW9XMbpL8bWwh0qMxxVB8NbS6xKBtvk9uCo+XNZsQcylM\nzeor0h3zRbHHTrrdzAZtYDhnQrqHcv9D8av4+38CgYEAgyn1h+EompwBF4hKo6Dx\nVL/ZZYcE1E+XMzmHvP8C1sOVBSPZuCAnCx43cZiJZ94/5v8V3+4nKuWbeN1ar9BK\nXXSAVkk21qM8cv2IoDwi/DdBLXD302KMReAOWfJnQ+sbU1v2B2VPJoCwd4lSqauj\nVE4PCFhhrsou1VM1XbP8XsM=\n-----END PRIVATE KEY-----"
- )
-
- func Send(prd bool, privateKeyStr string, param map[string]string) (string, error) {
- for key, value := range param {
- if value == "" {
- delete(param, key)
- }
- }
- data := zhios_pay_utils.JoinStringsInASCII(param, "", "", true, false)
- sign, err := zhios_pay_utils.GetSign(privateKeyStr, data)
- if err != nil {
- return "", err
- }
- url := "https://cuaas.bocmacau.com/w/rsa/mercapi_ol"
- if prd {
- url = "https://aas.bocmacau.com/w/rsa/mercapi_ol"
- }
- headers := map[string]string{
- "Content-Type": "application/json",
- }
- param["merchantSign"] = sign
- fmt.Println("参数:", zhios_pay_utils.SerializeStr(param))
- zhios_pay_utils.CurlDebug = true
- res, err := zhios_pay_utils.CurlPost(url, php2go.URLEncode(zhios_pay_utils.SerializeStr(param)), headers)
- if err != nil {
- return "", err
- }
- fmt.Println(string(res))
- return string(res), nil
- }
-
- func CreateBocPayAppTradeReq(prd bool, privateKeyStr, merchantId, terminalNo string, createBocPayAppTradeReq *md.CreateBocPayAppTradeReq) (string, error) {
- //基础信息,必填
- createBocPayAppTradeReq.Version = Version
- createBocPayAppTradeReq.Service = CreateBocPayAppTrade
- createBocPayAppTradeReq.SignType = SignType
- createBocPayAppTradeReq.MerchantId = merchantId
- createBocPayAppTradeReq.TerminalNo = terminalNo
- createBocPayAppTradeReq.RequestId = createBocPayAppTradeReq.MercOrderNo + zhios_pay_utils.AnyToString(time.Now().Unix())
- //按照接口类型选填信息
- //createBocPayAppTradeReq.Amount = "100"
- //createBocPayAppTradeReq.OriginalAmount = "100"
- //createBocPayAppTradeReq.MercOrderNo = "2022101401"
- //createBocPayAppTradeReq.OrderDate = "20221013"
- //createBocPayAppTradeReq.OrderTime = "175600"
- //createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
- //createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
- // "mid":"123456",
- //})
- param := make(map[string]string)
- zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(createBocPayAppTradeReq), ¶m)
- send, err := Send(prd, privateKeyStr, param)
- if err != nil {
- return "", err
- }
- resp, _ := php2go.URLDecode(send)
- return resp, nil
- }
-
- func CreateWeChatTradeReq(prd bool, privateKeyStr, merchantId, terminalNo string, createWeChatTradeReq *md.CreateWeChatTradeReq) (string, error) {
- //基础信息,必填
- createWeChatTradeReq.Version = Version
- createWeChatTradeReq.Service = CreateWeChatTrade
- createWeChatTradeReq.SignType = SignType
- createWeChatTradeReq.MerchantId = merchantId
- createWeChatTradeReq.TerminalNo = terminalNo
- createWeChatTradeReq.RequestId = createWeChatTradeReq.MercOrderNo + zhios_pay_utils.AnyToString(time.Now().Unix())
- //按照接口类型选填信息
- //createBocPayAppTradeReq.Amount = "100"
- //createBocPayAppTradeReq.OriginalAmount = "100"
- //createBocPayAppTradeReq.MercOrderNo = "2022101401"
- //createBocPayAppTradeReq.OrderDate = "20221013"
- //createBocPayAppTradeReq.OrderTime = "175600"
- //createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
- //createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
- // "mid":"123456",
- //})
- param := make(map[string]string)
- zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(createWeChatTradeReq), ¶m)
- send, err := Send(prd, privateKeyStr, param)
- if err != nil {
- return "", err
- }
- resp, _ := php2go.URLDecode(send)
- return resp, nil
- }
-
- func CreateQRTradeReq(prd bool, privateKeyStr, merchantId, terminalNo string, createQRTradeReq *md.CreateQRTradeReq) (string, error) {
- //基础信息,必填
- createQRTradeReq.Version = Version
- createQRTradeReq.Service = CreateQRTrade
- createQRTradeReq.SignType = SignType
- createQRTradeReq.MerchantId = merchantId
- createQRTradeReq.TerminalNo = terminalNo
- createQRTradeReq.RequestId = createQRTradeReq.MercOrderNo + zhios_pay_utils.AnyToString(time.Now().Unix())
- //按照接口类型选填信息
- //createBocPayAppTradeReq.Amount = "100"
- //createBocPayAppTradeReq.OriginalAmount = "100"
- //createBocPayAppTradeReq.MercOrderNo = "2022101401"
- //createBocPayAppTradeReq.OrderDate = "20221013"
- //createBocPayAppTradeReq.OrderTime = "175600"
- //createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
- //createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
- // "mid":"123456",
- //})
- param := make(map[string]string)
- zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(createQRTradeReq), ¶m)
- send, err := Send(prd, privateKeyStr, param)
- if err != nil {
- return "", err
- }
- resp, _ := php2go.URLDecode(send)
- return resp, nil
- }
-
- func OrderQueryReq(prd bool, privateKeyStr, merchantId, terminalNo string, orderQueryReq *md.OrderQueryReq) (string, error) {
- //基础信息,必填
- orderQueryReq.Version = Version
- orderQueryReq.Service = OrderQuery
- orderQueryReq.SignType = SignType
- orderQueryReq.MerchantId = merchantId
- orderQueryReq.TerminalNo = terminalNo
- orderQueryReq.RequestId = zhios_pay_utils.AnyToString(time.Now().Unix())
- param := make(map[string]string)
- zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(orderQueryReq), ¶m)
- send, err := Send(prd, privateKeyStr, param)
- if err != nil {
- return "", err
- }
- resp, _ := php2go.URLDecode(send)
- return resp, nil
- }
|