spgateway

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MIT Imports: 8 Imported by: 0

README

go-spgateway

GoDoc Run Tests codecov Go Report Card

智付通金流串接

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(s string, key, iv []byte) ([]byte, error)

Decrypt string

func Encrypt

func Encrypt(key, plaintext, iv []byte) ([]byte, error)

Encrypt string

func PKCS5Padding

func PKCS5Padding(src []byte, blockSize int) []byte

PKCS5Padding is described in RFC 5652.

func PKCS5UnPadding

func PKCS5UnPadding(src []byte) []byte

PKCS5UnPadding is described in RFC 5652.

Types

type Config

type Config struct {
	HashKey    string
	HashIV     string
	MerchantID string
}

Config provides spgateway config.

type Credit

type Credit struct {
	Date       string
	UseInfo    string
	CreditInst string
	CreditRed  string
	MerchantID string
}

Credit provides credit config.

type Invoice

type Invoice struct {
	InvoiceTransNo  string
	MerchantOrderNo string
	RandomNum       string
	TotalAmt        int
	MerchantID      string
}

Invoice provides invoice check code config.

type OrderCheckCode

type OrderCheckCode struct {
	Amt             int
	MerchantOrderNo string
	MerchantID      string
	TradeNo         string
}

OrderCheckCode provides order config.

type OrderCheckValue

type OrderCheckValue struct {
	Amt             int
	MerchantOrderNo string
	MerchantID      string
	TimeStamp       string
	Version         string
}

OrderCheckValue provides order config.

type Store

type Store struct {
	HashKey    string
	HashIV     string
	MerchantID string
}

Store provides spgateway config.

func New

func New(config Config) *Store

New returns a new empty handler.

func (*Store) CreditCheckCode

func (s *Store) CreditCheckCode(credit Credit) string

CreditCheckCode return spgateway check value for post data.

func (*Store) InvoiceCheckCode

func (s *Store) InvoiceCheckCode(invoice Invoice) string

InvoiceCheckCode return spgateway check value for post data.

func (*Store) OrderCheckCode

func (s *Store) OrderCheckCode(order OrderCheckCode) string

OrderCheckCode return spgateway check value for post data.

Example

CheckCode 產生規則

排序欄位字串並用&符號串聯起來將回傳資料其中的四個欄位,分別是 Amt(金額)、MerchantID(商店代號)、 MerchantOrderNo(商店訂單編號)、TradeNo(智付通交易序號),且參數需照英文字母 A~Z 排序,若第一 字母相同比較第二字母,以此類推。將串聯後的字串前後加上商店專屬加密 HashIV 值與商店專屬加密 HashKey 值。 將串聯後的字串用 SHA256 壓碼後轉大寫。

store := New(Config{
	MerchantID: "1422967",
	HashKey:    "abcdefg",
	HashIV:     "1234567",
})

order := OrderCheckCode{
	Amt:             100,
	MerchantOrderNo: "840f022",
	TradeNo:         "14061313541640927",
}

fmt.Println(store.OrderCheckCode(order))
Output:

62C687AF6409E46E79769FAF54F54FE7E75AAE50BAF0767752A5C337670B8EDB

func (*Store) OrderCheckValue

func (s *Store) OrderCheckValue(order OrderCheckValue) string

OrderCheckValue return spgateway check value for post data.

Example

CheckValue 組合及加密方法

排序欄位字串並用&符號串聯起來將回傳資料其中的五個欄位,分別是訂單金額(Amt)、商店代號(MerchantID)、 商店自訂單號(MerchantOrderNo)、時間戳記(TimeStamp)、程式串接版本(Version),且參數需照英文字母 A~Z 排序 若第一字母相同比較第二字母,以此類推。將串聯後的字串前後加上商店專屬加密 HashKey 與商店專屬加密 HashIV。 將串聯後的字串用 SHA256 壓碼後轉大寫。

store := New(Config{
	MerchantID: "123456",
	HashKey:    "1A3S21DAS3D1AS65D1",
	HashIV:     "1AS56D1AS24D",
})

order := OrderCheckValue{
	Amt:             200,
	MerchantOrderNo: "20140901001",
	TimeStamp:       "1403243286",
	Version:         "1.1",
}

fmt.Println(store.OrderCheckValue(order))
Output:

841F57D750FB4B04B62DDC3ECDC26F1F4028410927DD28BD5B2E34791CC434D2

func (*Store) TradeInfoDecrypter

func (s *Store) TradeInfoDecrypter(data string) (string, error)

TradeInfoDecrypter decrypt trade info data

func (*Store) TradeInfoEncrypter

func (s *Store) TradeInfoEncrypter(tradeInfo interface{}) (string, error)

TradeInfoEncrypter encrypt trade info data

func (*Store) TradeSha

func (s *Store) TradeSha(tradeInfo string) string

TradeSha return spgateway trade sha 256 encrypt.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL