|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package luso_bank
-
- import (
- zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
- "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\neYniSWmj0ku1bSJ7oYb1g4mPf6kCgYEA4n8MKlYIf0JALvMgws78M75JMVpSVgDs\nOngZvMF7z7x4gkBxXxxc5ABe6k/RXCuz59n2IQU3NzS0Y3HxCvZyeJzh1X5ENSdD\nsyJVFkb4oC8nhKvztXT8CwH1vSIGMRUJNE3Gn8IrX8QdEWdvADz/+Iw81HtOh7lr\nAGyreWyLc/UCgYBBFaXuspURdUaAj0gTUlY5Tg1wol+TJD4anSMXqu0RREVrowNY\nQrZa9oLkE14+vDiSEqHbOu1r4AwzBEq9SPyAUp0Vw9df4AILpD7kAAjm59WXcvt6\nhm+d3UGwm7ABOpq4yvNMUsvA7hn9XXtkytrHIUUXwGUuM+wG8Duu/y3p0QKBgQC3\nsZKMQ3pgu7qSWV0YogapcIqsHDTqy5TLVtyI2eMweArEmL9aBAbSY/qWzmVd+5PN\nVljoLvK5M2WZwa9c1MPCTnpaTC3FbjLZ9d5MUwMR5yyFzW+6m0ZPJyfGXPHonMb6\nRJnyt+e1o7hvhRPhfZecXSB4tAjcyuSdU4U+1WnEgQKBgAUZFTYeIyC/bnIca5m8\nzh2wIW0KusCLPa9e3VGTARJG5WP6nx8BPVx71Er/wquBLLquoH0XlTmpdj80QF+s\nHlnKE9CfXVu23ci2S0WalbX/8CYGlO5iCct9o0KR0inrXKfqFzuSKkpg6JyXVMk0\nMT1+EUSD25ATIRsNGFWigNHL\n-----END PRIVATE KEY-----"
- MchtStoreNm = "世寶商城"
- )
-
- 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:"附加数据(附加数据,用于在同步应答或异步通知时原样返回)"`
- } `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")
- 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.GetSign(privateKeyStr, dataParamBase64Str)
- if err != nil {
- return err
- }
- s.PayParam.Sign = signStr
- return nil
- }
-
- func (payParam *PayParam) Send(prd 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"
- }
- headers := map[string]string{
- "Content-Type": "application/json",
- }
- zhios_pay_utils.CurlDebug = true
- res, err := zhios_pay_utils.CurlPost(url, php2go.URLEncode(zhios_pay_utils.SerializeStr(payParam)), headers)
- if err != nil {
- return "", err
- }
- fmt.Println(string(res))
- return string(res), nil
- }
|