Переглянути джерело

澳門國際銀行支付

tags/v1.5.2
jiaoboxiang 2 роки тому
джерело
коміт
9b707b07d0
5 змінених файлів з 174 додано та 34 видалено
  1. +18
    -0
      lib/boc/api_macao.go
  2. +75
    -0
      lib/luso_bank/macao_luso.go
  3. +16
    -0
      md/boc.go
  4. +26
    -34
      test/boc_pay_test.go
  5. +39
    -0
      test/luso_pay_test.go

+ 18
- 0
lib/boc/api_macao.go Переглянути файл

@@ -126,3 +126,21 @@ func CreateQRTradeReq(prd bool, privateKeyStr, merchantId, terminalNo string, cr
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), &param)
send, err := Send(prd, privateKeyStr, param)
if err != nil {
return "", err
}
resp, _ := php2go.URLDecode(send)
return resp, nil
}

+ 75
- 0
lib/luso_bank/macao_luso.go Переглянути файл

@@ -0,0 +1,75 @@
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/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IUUXwGUuM+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) (string, error) {
url := "https://qrpaytest.lusobank.com.mo:443"
if prd {
url = "https://qrpaytest.lusobank.com.mo:8443"
}
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
}

+ 16
- 0
md/boc.go Переглянути файл

@@ -146,3 +146,19 @@ type OfflineResultResponse struct {
Reserved2 string `json:"reserved2" name:"商戶備用字段2" label:"交易成功后原樣返回給商戶"`
Reserved3 string `json:"reserved3" name:"商戶備用字段3" label:"交易成功后原樣返回給商戶"`
}

type OrderQueryReq struct {
MacaoBOCPublicParameter
QueryNo string `json:"queryNo" name:"商戶系統訂單號" label:"商戶系統消費、退款、撤單的訂單號,本欄不可與queryLogNo同時爲空"`
QueryLogNo string `json:"queryLogNo" name:"平臺返回訂單號" label:"原交易中銀智慧付返回訂單號logNo,本欄不可與queryNo同時爲空。都不爲空則以queryLogNo爲准。"`
LogNo string `json:"logNo" name:"系統流水號" label:"該筆交易返回的平臺流水號"`
OrderDate string `json:"orderDate" name:"訂單日期" label:"訂單建立日期,格式yyyyMMdd"`
OrderTime string `json:"orderTime" name:"訂單創建時間" label:"格式:HHmmss"`
TxnFlag string `json:"txnFlag" name:"交易類型" label:"P-消費 R-退款"`
Result string `json:"result" name:"商品描述" label:"S-交易成功
F-交易失敗
A-等待付款
Z-交易未明
W-退款中
D-訂單已撤銷"`
}

+ 26
- 34
test/boc_pay_test.go Переглянути файл

@@ -5,7 +5,7 @@ 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"
"github.com/shopspring/decimal"
"testing"
"time"
)
@@ -16,41 +16,12 @@ func TestJoinStringsInASCII(t *testing.T) {
fmt.Println(ascii)
}

func TestBocSend(t *testing.T) {
var createBocPayAppTradeReq md.CreateBocPayAppTradeReq
//基础信息,必填
createBocPayAppTradeReq.Version = boc.Version
createBocPayAppTradeReq.Service = boc.CreateBocPayAppTrade
createBocPayAppTradeReq.SignType = boc.SignType
createBocPayAppTradeReq.MerchantId = boc.MerchantId
createBocPayAppTradeReq.TerminalNo = boc.TerminalNo
createBocPayAppTradeReq.RequestId = "2022101401" + 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), &param)
send, err := boc.Send(false, boc.PrivateKeyStr, param)
if err != nil {
t.Error(err)
}
t.Logf("回调信息1:%s", send)
resp, _ := php2go.URLDecode(send)
t.Logf("回调信息:%s", resp)
}
func TestCreateBocPayAppTradeReq(t *testing.T) {
var createBocPayAppTradeReq md.CreateBocPayAppTradeReq
//按照接口类型选填信息
createBocPayAppTradeReq.Amount = "100"
createBocPayAppTradeReq.OriginalAmount = "100"
createBocPayAppTradeReq.MercOrderNo = "2022101404"
createBocPayAppTradeReq.MercOrderNo = "2022102102"
createBocPayAppTradeReq.OrderDate = time.Now().Format("20060102")
createBocPayAppTradeReq.OrderTime = time.Now().Format("150105")
createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
@@ -69,7 +40,7 @@ func TestCreateWeChatTradeReq(t *testing.T) {
//按照接口类型选填信息
CreateWeChatTradeReqReq.Amount = "100"
CreateWeChatTradeReqReq.OriginalAmount = "100"
CreateWeChatTradeReqReq.MercOrderNo = "2022101404"
CreateWeChatTradeReqReq.MercOrderNo = "2022101405"
CreateWeChatTradeReqReq.OrderDate = time.Now().Format("20060102")
CreateWeChatTradeReqReq.OrderTime = time.Now().Format("150105")
CreateWeChatTradeReqReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
@@ -93,14 +64,14 @@ func TestCreateQRTradeReq(t *testing.T) {
createQRTradeReq.OriginalAmount = "100"
createQRTradeReq.PayChannel = "WECHATPAY"
createQRTradeReq.ProductCode = "PCWEB"
createQRTradeReq.MercOrderNo = "2022101405"
createQRTradeReq.MercOrderNo = "2022102101"
createQRTradeReq.OrderDate = time.Now().Format("20060102")
createQRTradeReq.OrderTime = time.Now().Format("150105")
createQRTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
createQRTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
"mid": "123456",
})
createQRTradeReq.Supplier = "澳門世寶一人有限公司"
createQRTradeReq.Supplier = "测试"
createQRTradeReq.ReferUrl = "https://www.baidu.com"
createQRTradeReq.BusinessType = "4"
createQRTradeReq.GoodsInfo = "测试商品^1"
@@ -111,3 +82,24 @@ func TestCreateQRTradeReq(t *testing.T) {
}
t.Logf("回调信息:%s", send)
}
func TestOrderQueryReq(t *testing.T) {
var orderQueryReq md.OrderQueryReq
//按照接口类型选填信息
orderQueryReq.QueryNo = "100173316661476707"
send, err := boc.OrderQueryReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &orderQueryReq)
if err != nil {
t.Error(err)
}
t.Logf("回调信息:%s", send)
}

func TestFloat(t *testing.T) {
rateD, _ := decimal.NewFromString("155")
rateD = rateD.Div(decimal.NewFromInt(100))
rateF, exact := rateD.Float64()
t.Logf("数目:%g", rateF)
if !exact {
rateF = 0.5
}
t.Logf("数目:%g", rateF)
}

+ 39
- 0
test/luso_pay_test.go Переглянути файл

@@ -0,0 +1,39 @@
package test

import (
luso "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/luso_bank"
zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
"testing"
)

func TestLusoPay(t *testing.T) {
var (
payParam luso.PayParam
dataParam luso.DataParam
)
req := map[string]string{
"mchtOrderId": "202211041102",
"payScene ": "AS_MWEB",
"mdseDesc ": "澳门世寶-自營購物",
"transAmount ": "100",
"transCur ": "MOP",
"subMchtNm ": "世寶商城",
"notifyUrl ": "http://inapi.izhyin.cn:80/pay/boc/callback",
"extMsg ": zhios_pay_utils.SerializeStr(map[string]string{
"mid": "123456",
"ord_type": "mall_goods",
}),
}
dataParam.Head.MchtNo = luso.MerchantId
dataParam.ReqBody = req
client := payParam.SetData(dataParam)
err := client.SetSign(luso.PrivateKeyStr)
if err != nil {
t.Error(err)
}
resp, err := client.PayParam.Send(false)
if err != nil {
t.Error(err)
}
t.Logf("回調信息:%s", resp)
}

Завантаження…
Відмінити
Зберегти