package luso_bank import ( zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils" "crypto" "encoding/base64" "fmt" "github.com/syyongx/php2go" "math/rand" "time" ) const ( MerchantId = "30010" TerminalNo = "98036140" PrivateKeyStr = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDSYivjR7nXUazy\nf+F1i/nvuy/doiHRsiTSwavHIwKF88kzM95Eh5wGiXq6TXwFPhB5yeV8l3tFQxeu\nPycZeKmp0VBge+U+/UhR1rQwEX9U9LeKhVdjbNU0U8kNpO8qX/QqHSS7MCRILL2a\nS4F5U/wvYGkbqJ+qMUNmEMGwEkiVuDaO/Q4I3lMPNtLO+mizgq9jggEkVh+xG50p\nFATWd6CJh0mddBBgGG3/aG1ybV/IYRRP0sS+dbYKmKghbK2d/LztIM8ba7lA16H9\nxLY8oy8SvwGqkq2Gea9K2AIEjociac4i0Q/Ka2U881rJCrDUMg3gDhIundaa971M\nglS5cRe9AgMBAAECggEBALe9P6FHIlqYHZjI8QqtToL+E6bYk/rFP/3FYZYQ0IJW\n0NDkKunlGfJnnYUaaQdXFiKXntJ6phFusD7hLu/C/0Kt6Snq6uNhaAj5n/MfRPrY\no3faTuEpyubhigVdl/eFSASD4XGOcRGL6afY6+If5G8oH4QleBS246s/VTnGLhh6\n7cWv2PvFQOU6WzayYzs+8wIYPlVlhKIfuU7vbQF7sWIFfJg8zqVFe2lNXwGS3D2f\ns8AjjN9lMemWF/t9OIA4l9b/Mr2D1wc71AznTUXgBWqm747tWAYyEQ+r1PimbPMB\nEUi6qllpB0qhoEmSVQxONcR3GIep0IwDj8PHQtP55qECgYEA7cnP0yNcc1if7Dd/\nBh0xWGafMVkHIPbbBVOgR3FakaTuC5g0OQ7LP5O8OCW1pchyJY0HXLCEiRVSj5O7\n3MY59eIbdqpcBI7a+ZxOyBHEN2IqZ4EVZmkCxd7w7XA12D+mT19rc//F03FT78e5\neYniSWm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\niYdJnXQQYBht/2htcm1fyGEUT9LEvnW2CpioIWytnfy87SDPG2u5QNeh/cS2PKMv\nEr8BqpKthnmvStgCBI6HImnOItEPymtlPPNayQqw1DIN4A4SLp3Wmve9TIJUuXEX\nvQIDAQAB\n-----END PUBLIC KEY-----" ) type PayParam struct { Data string `json:"data"` Sign string `json:"sign"` } type DataParam struct { Head struct { MchtNo string `json:"mchtNo" explain:"商户编号"` ReqTime string `json:"reqTime" explain:"请求时间戳(yyyyMMddHHmmss)"` MsgId string `json:"msgId" explain:"请求消息唯一编号"` Attach string `json:"attach" explain:"附加数据(附加数据,用于在同步应答或异步通知时原样返回)"` CertId string `json:"certId" explain:"数字证书 ID(默认 01)"` Version string `json:"version" explain:"版本号(默认 1.0.0)"` } `json:"head"` ReqBody map[string]string `json:"reqBody"` } type signParam struct { PayParam *PayParam } func (payParam *PayParam) SetData(dataParam DataParam) *signParam { now := time.Now() rand.Seed(now.UnixNano()) randomInt := rand.Intn(100) dataParam.Head.MsgId = zhios_pay_utils.AnyToString(randomInt) + dataParam.Head.MchtNo + now.Format("20060102150405") dataParam.Head.ReqTime = now.Format("20060102150405") dataParam.Head.CertId = "01" dataParam.Head.Version = "1.0.0" if dataParam.ReqBody["mchtOrderId"] != "" { dataParam.Head.MsgId = dataParam.ReqBody["mchtOrderId"] + now.Format("20060102150405") } payParam.Data = zhios_pay_utils.SerializeStr(dataParam) var signs signParam signs.PayParam = payParam return &signs } func (s *signParam) SetSign(privateKeyStr string) error { dataParamBase64Str := base64.StdEncoding.EncodeToString([]byte(s.PayParam.Data)) signStr, err := zhios_pay_utils.GetSignV2(privateKeyStr, dataParamBase64Str, crypto.SHA1) if err != nil { return err } s.PayParam.Sign = signStr s.PayParam.Data = dataParamBase64Str return nil } func (payParam *PayParam) Send(prd, isNeedEncode bool, method string) (string, error) { url := "https://qrpaytest.lusobank.com.mo:443" if prd { url = "https://qrpaytest.lusobank.com.mo:8443" } switch method { case "create": url = url + "/upcp-iap-pps-lqrp/libQrPay/json/create" case "pay": url = url + "/upcp-iap-pps-lqrp/libQrPay/json/pay" case "revoke": url = url + "/upcp-iap-pps-lqrp/libQrPay/json/revoke" case "refund": url = url + "/upcp-iap-pps-lqrp/libQrPay/json/refund" case "query": url = url + "/upcp-iap-pps-lqrp/libQrPay/json/query" } headers := map[string]string{ "Content-Type": "application/json", } zhios_pay_utils.CurlDebug = true body := zhios_pay_utils.SerializeStr(payParam) if isNeedEncode { body = php2go.URLEncode(body) } res, err := zhios_pay_utils.CurlPost(url, body, headers) if err != nil { return "", err } fmt.Println(string(res)) return string(res), nil }