支付模块
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
4.4 KiB

  1. package test
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/boc"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
  5. zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
  6. "fmt"
  7. "github.com/syyongx/php2go"
  8. "testing"
  9. "time"
  10. )
  11. func TestJoinStringsInASCII(t *testing.T) {
  12. ascii := zhios_pay_utils.JoinStringsInASCII(map[string]string{"apam": "value1", "cpam": "value2", "Bpam": "value3"},
  13. "", "", false, false)
  14. fmt.Println(ascii)
  15. }
  16. func TestBocSend(t *testing.T) {
  17. var createBocPayAppTradeReq md.CreateBocPayAppTradeReq
  18. //基础信息,必填
  19. createBocPayAppTradeReq.Version = boc.Version
  20. createBocPayAppTradeReq.Service = boc.CreateBocPayAppTrade
  21. createBocPayAppTradeReq.SignType = boc.SignType
  22. createBocPayAppTradeReq.MerchantId = boc.MerchantId
  23. createBocPayAppTradeReq.TerminalNo = boc.TerminalNo
  24. createBocPayAppTradeReq.RequestId = "2022101401" + zhios_pay_utils.AnyToString(time.Now().Unix())
  25. //按照接口类型选填信息
  26. createBocPayAppTradeReq.Amount = "100"
  27. createBocPayAppTradeReq.OriginalAmount = "100"
  28. createBocPayAppTradeReq.MercOrderNo = "2022101401"
  29. createBocPayAppTradeReq.OrderDate = "20221013"
  30. createBocPayAppTradeReq.OrderTime = "175600"
  31. createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  32. createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  33. "mid": "123456",
  34. })
  35. param := make(map[string]string)
  36. zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(createBocPayAppTradeReq), &param)
  37. send, err := boc.Send(false, boc.PrivateKeyStr, param)
  38. if err != nil {
  39. t.Error(err)
  40. }
  41. t.Logf("回调信息1:%s", send)
  42. resp, _ := php2go.URLDecode(send)
  43. t.Logf("回调信息:%s", resp)
  44. }
  45. func TestCreateBocPayAppTradeReq(t *testing.T) {
  46. var createBocPayAppTradeReq md.CreateBocPayAppTradeReq
  47. //按照接口类型选填信息
  48. createBocPayAppTradeReq.Amount = "100"
  49. createBocPayAppTradeReq.OriginalAmount = "100"
  50. createBocPayAppTradeReq.MercOrderNo = "2022101404"
  51. createBocPayAppTradeReq.OrderDate = time.Now().Format("20060102")
  52. createBocPayAppTradeReq.OrderTime = time.Now().Format("150105")
  53. createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  54. createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  55. "mid": "123456",
  56. })
  57. send, err := boc.CreateBocPayAppTradeReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &createBocPayAppTradeReq)
  58. if err != nil {
  59. t.Error(err)
  60. }
  61. t.Logf("回调信息:%s", send)
  62. }
  63. func TestCreateWeChatTradeReq(t *testing.T) {
  64. var CreateWeChatTradeReqReq md.CreateWeChatTradeReq
  65. //按照接口类型选填信息
  66. CreateWeChatTradeReqReq.Amount = "100"
  67. CreateWeChatTradeReqReq.OriginalAmount = "100"
  68. CreateWeChatTradeReqReq.MercOrderNo = "2022101404"
  69. CreateWeChatTradeReqReq.OrderDate = time.Now().Format("20060102")
  70. CreateWeChatTradeReqReq.OrderTime = time.Now().Format("150105")
  71. CreateWeChatTradeReqReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  72. CreateWeChatTradeReqReq.SubAppId = "wx987580a9437354d1"
  73. CreateWeChatTradeReqReq.SubOpenId = "oEk7V5hNLxQXoTpOcvzRdGJQKnjM"
  74. CreateWeChatTradeReqReq.TransWay = "B3"
  75. CreateWeChatTradeReqReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  76. "mid": "123456",
  77. })
  78. send, err := boc.CreateWeChatTradeReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &CreateWeChatTradeReqReq)
  79. if err != nil {
  80. t.Error(err)
  81. }
  82. t.Logf("回调信息:%s", send)
  83. }
  84. func TestCreateQRTradeReq(t *testing.T) {
  85. var createQRTradeReq md.CreateQRTradeReq
  86. //按照接口类型选填信息
  87. createQRTradeReq.Amount = "100"
  88. createQRTradeReq.OriginalAmount = "100"
  89. createQRTradeReq.PayChannel = "WECHATPAY"
  90. createQRTradeReq.ProductCode = "PCWEB"
  91. createQRTradeReq.MercOrderNo = "2022101405"
  92. createQRTradeReq.OrderDate = time.Now().Format("20060102")
  93. createQRTradeReq.OrderTime = time.Now().Format("150105")
  94. createQRTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  95. createQRTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  96. "mid": "123456",
  97. })
  98. createQRTradeReq.Supplier = "澳門世寶一人有限公司"
  99. createQRTradeReq.ReferUrl = "https://www.baidu.com"
  100. createQRTradeReq.BusinessType = "4"
  101. createQRTradeReq.GoodsInfo = "测试商品^1"
  102. createQRTradeReq.TotalQuantity = "1"
  103. send, err := boc.CreateQRTradeReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &createQRTradeReq)
  104. if err != nil {
  105. t.Error(err)
  106. }
  107. t.Logf("回调信息:%s", send)
  108. }