支付模块
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.

boc_pay_test.go 3.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/shopspring/decimal"
  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 TestCreateBocPayAppTradeReq(t *testing.T) {
  17. var createBocPayAppTradeReq md.CreateBocPayAppTradeReq
  18. //按照接口类型选填信息
  19. createBocPayAppTradeReq.Amount = "100"
  20. createBocPayAppTradeReq.OriginalAmount = "100"
  21. createBocPayAppTradeReq.MercOrderNo = "2022102102"
  22. createBocPayAppTradeReq.OrderDate = time.Now().Format("20060102")
  23. createBocPayAppTradeReq.OrderTime = time.Now().Format("150105")
  24. createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  25. createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  26. "mid": "123456",
  27. })
  28. send, err := boc.CreateBocPayAppTradeReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &createBocPayAppTradeReq)
  29. if err != nil {
  30. t.Error(err)
  31. }
  32. t.Logf("回调信息:%s", send)
  33. }
  34. func TestCreateWeChatTradeReq(t *testing.T) {
  35. var CreateWeChatTradeReqReq md.CreateWeChatTradeReq
  36. //按照接口类型选填信息
  37. CreateWeChatTradeReqReq.Amount = "100"
  38. CreateWeChatTradeReqReq.OriginalAmount = "100"
  39. CreateWeChatTradeReqReq.MercOrderNo = "2022101405"
  40. CreateWeChatTradeReqReq.OrderDate = time.Now().Format("20060102")
  41. CreateWeChatTradeReqReq.OrderTime = time.Now().Format("150105")
  42. CreateWeChatTradeReqReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  43. CreateWeChatTradeReqReq.SubAppId = "wx987580a9437354d1"
  44. CreateWeChatTradeReqReq.SubOpenId = "oEk7V5hNLxQXoTpOcvzRdGJQKnjM"
  45. CreateWeChatTradeReqReq.TransWay = "B3"
  46. CreateWeChatTradeReqReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  47. "mid": "123456",
  48. })
  49. send, err := boc.CreateWeChatTradeReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &CreateWeChatTradeReqReq)
  50. if err != nil {
  51. t.Error(err)
  52. }
  53. t.Logf("回调信息:%s", send)
  54. }
  55. func TestCreateQRTradeReq(t *testing.T) {
  56. var createQRTradeReq md.CreateQRTradeReq
  57. //按照接口类型选填信息
  58. createQRTradeReq.Amount = "100"
  59. createQRTradeReq.OriginalAmount = "100"
  60. createQRTradeReq.PayChannel = "WECHATPAY"
  61. createQRTradeReq.ProductCode = "PCWEB"
  62. createQRTradeReq.MercOrderNo = "2022102101"
  63. createQRTradeReq.OrderDate = time.Now().Format("20060102")
  64. createQRTradeReq.OrderTime = time.Now().Format("150105")
  65. createQRTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  66. createQRTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  67. "mid": "123456",
  68. })
  69. createQRTradeReq.Supplier = "测试"
  70. createQRTradeReq.ReferUrl = "https://www.baidu.com"
  71. createQRTradeReq.BusinessType = "4"
  72. createQRTradeReq.GoodsInfo = "测试商品^1"
  73. createQRTradeReq.TotalQuantity = "1"
  74. send, err := boc.CreateQRTradeReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &createQRTradeReq)
  75. if err != nil {
  76. t.Error(err)
  77. }
  78. t.Logf("回调信息:%s", send)
  79. }
  80. func TestOrderQueryReq(t *testing.T) {
  81. var orderQueryReq md.OrderQueryReq
  82. //按照接口类型选填信息
  83. orderQueryReq.QueryNo = "100173316661476707"
  84. send, err := boc.OrderQueryReq(false, boc.PrivateKeyStr, boc.MerchantId, boc.TerminalNo, &orderQueryReq)
  85. if err != nil {
  86. t.Error(err)
  87. }
  88. t.Logf("回调信息:%s", send)
  89. }
  90. func TestFloat(t *testing.T) {
  91. rateD, _ := decimal.NewFromString("155")
  92. rateD = rateD.Div(decimal.NewFromInt(100))
  93. rateF, exact := rateD.Float64()
  94. t.Logf("数目:%g", rateF)
  95. if !exact {
  96. rateF = 0.5
  97. }
  98. t.Logf("数目:%g", rateF)
  99. }