Closed Juniornewxt closed 3 years ago
You need to have spec and also understand what kind of software sent data (way4, tieto, something else..)
I just wanted to be able to send an authorization to my payment system, I have here the specification of the data I should put in the field, but I can't assemble the message and send it via tcp ip with moov-io. I am using the ideazxy package today, but it is too old.
Dont understand you problem, fill the data via you spec and call message.Pack()
Do you have any simple examples? With what I got on github I can't get it to work.
main problem that latest release and latest master have very big difference @alovak can you tag new release after fixing binary decoding for way4 ?
I've updated the version in the master branch to v0.3.0
.
nice
@Juniornewxt I would be glad to help you! Not sure I understand what you are trying to achieve. With this package you can only build a "packed" message. You need to describe spec, set values to the message and then "pack" it.
When you have a packed message you can write it into the file and then perform this (taken from https://github.com/juks/iso-8583-socket-queue):
cat ./packed-message.txt - | nc askarov.com 12345
sorry i'm new to "golang". But I thought I'd take the message encapsulated with "moov-io" and send it via net/bufio with the code below that worked well for me in other things...
tcpClientNew(b)
}
func tcpClientNew(b []byte) { tcpAddr, err := net.ResolveTCPAddr("tcp", "192.168.1.110:5001") if err != nil { println("ResolveTCPAddr failed:", err.Error()) os.Exit(1) } conn, err := net.DialTCP("tcp", nil, tcpAddr) if err != nil { println("Dial failed:", err.Error()) os.Exit(1) } timeoutDuration := 15 * time.Second , err = conn.Write(b) if err != nil { println("Write to server failed:", err.Error()) os.Exit(1) } conn.SetReadDeadline(time.Now().Add(timeoutDuration)) bufReader := bufio.NewReader(conn) resp, := bufReader.ReadByte() fmt.Print("Message: " + string(resp)) conn.Close() }
But I can't get the "moov-io" code to work, so I asked if they had an example
@Juniornewxt you can look into our tests here: https://github.com/moov-io/iso8583/blob/master/message_test.go#L52
but in short it should look like this: https://gist.github.com/alovak/a1637a12c5e1c06ad89595effe284408
package main
import (
"github.com/moov-io/iso8583"
"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/field"
"github.com/moov-io/iso8583/prefix"
)
func NewSpec() *iso8583.MessageSpec {
return &iso8583.MessageSpec{
Fields: map[int]field.Field{
0: field.NewString(&field.Spec{
Length: 4,
Description: "Message Type Indicator",
Enc: encoding.ASCII,
Pref: prefix.ASCII.Fixed,
}),
1: field.NewBitmap(&field.Spec{
Description: "Bitmap",
Enc: encoding.Binary,
Pref: prefix.Binary.Fixed,
}),
2: field.NewString(&field.Spec{
Length: 19,
Description: "Primary Account Number",
Enc: encoding.BCD,
Pref: prefix.BCD.LL,
}),
//3: field.NewNumeric(&field.Spec{
// Length: 6,
// Description: "Processing Code",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
//}),
//4: field.NewNumeric(&field.Spec{
// Length: 12,
// Description: "Amount, Transaction",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
// //Pad: padding.Left('0'),
//}),
//6: field.NewNumeric(&field.Spec{
// Length: 12,
// Description: "Amount, Cardholder Billing",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
// Pad: padding.Left('0'),
//}),
//7: field.NewNumeric(&field.Spec{
// Length: 10,
// Description: "Transmission Date and Time",
// Enc: encoding.BCD,
// Pref: prefix.BCD.Fixed,
// Pad: padding.Left('0'),
//}),
// and so on
//
},
}
}
func main() {
spec := NewSpec()
message := iso8583.NewMessage(spec)
message.MTI("0100")
message.Field(2, "4242424242424242")
message.Field(3, "123456")
message.Field(4, "100")
// set your values
packed, err := message.Pack()
if err != nil {
panic(err)
}
// send packed via the network
}
Thank you very much :) But it seems to me that I was doing it correctly, because your code gave the same error as mine
../../pkg/mod/github.com/moov-io/iso8583@v0.2.3/parser.go:81:19: too many arguments in call to NewMessage have (string, interface {}) want (MessageSpec) ../../pkg/mod/github.com/moov-io/iso8583@v0.2.3/parser.go:82:5: msg.MtiEncode undefined (type Message has no field or method MtiEncode) ../../pkg/mod/github.com/moov-io/iso8583@v0.2.3/parser.go:83:17: msg.Load undefined (type *Message has no field or method Load)
Please, do following in terminal:
go get github.com/moov-io/iso8583
to get the latest version of the package.
Fantastic, needed to update, but I still have problem.
package main
import (
"github.com/moov-io/iso8583"
"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/field"
"github.com/moov-io/iso8583/prefix"
"github.com/moov-io/iso8583/padding"
)
func NewSpec() *iso8583.MessageSpec { return &iso8583.MessageSpec{ Fields: map[int]field.Field{ 0: field.NewString(&field.Spec{ Length: 4, Description: "Message Type Indicator", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, }), 1: field.NewBitmap(&field.Spec{ Description: "Bitmap", Enc: encoding.Hex, Pref: prefix.Hex.Fixed, }), 2: field.NewString(&field.Spec{ Length: 19, Description: "Primary Account Number", Enc: encoding.ASCII, Pref: prefix.ASCII.LL, }), 3: field.NewNumeric(&field.Spec{ Length: 6, Description: "Processing Code", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 4: field.NewString(&field.Spec{ Length: 12, Description: "Transaction Amount", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), }, }
}
func main() { spec := NewSpec()
message := iso8583.NewMessage(spec)
message.MTI("0100")
message.Field(2, "4242424242424242")
message.Field(3, "123456")
message.Field(4, "100")
// set your values
err := message.Pack()
if err != nil {
panic(err)
}
// send packed via the network
}
go:61:7: assignment mismatch: 1 variable but message.Pack returns 2 values
Note, I removed the "packed" as it had not been declared, generating an error: go:74:2: packed declared but not used
check godoc, message.Pack() returns two variables []byte and error
I do not understand.
Thanks my friends, now I start to understand, there are the bytes
package main
import ( "fmt" "github.com/moov-io/iso8583" "github.com/moov-io/iso8583/encoding" "github.com/moov-io/iso8583/field" "github.com/moov-io/iso8583/prefix" "github.com/moov-io/iso8583/padding" )
func NewSpec() *iso8583.MessageSpec { return &iso8583.MessageSpec{ Fields: map[int]field.Field{ 0: field.NewString(&field.Spec{ Length: 4, Description: "Message Type Indicator", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, }), 1: field.NewBitmap(&field.Spec{ Description: "Bitmap", Enc: encoding.Hex, Pref: prefix.Hex.Fixed, }), 2: field.NewString(&field.Spec{ Length: 19, Description: "Primary Account Number", Enc: encoding.ASCII, Pref: prefix.ASCII.LL, }), 3: field.NewNumeric(&field.Spec{ Length: 6, Description: "Processing Code", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 4: field.NewString(&field.Spec{ Length: 12, Description: "Transaction Amount", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), }, }
}
func main() { spec := NewSpec()
message := iso8583.NewMessage(spec)
message.MTI("0100")
message.Field(2, "4242424242424242")
message.Field(3, "123456")
message.Field(4, "100")
// set your values
b, err := message.Pack()
if err != nil {
panic(err)
}
fmt.Printf("% x\n", b)
// send packed via the network
}
30 31 30 30 37 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 36 34 32 34 32 34 32 34 32 34 32 34 32 34 32 34 32 31 32 33 34 35 36 30 30 30 30 30 30 30 30 30 31 30 30
@Juniornewxt was you able to make it work for you?
Yes, thank you. You can close the issue
Hello, do you have any example of echo test (0800), sent via tcp ip?
I read the examples but didn't quite understand. My echo test De3 De7 De11 De12 De13 De32 De39 De42 De61 De70