payment gateway for rpn cn
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

checksum_test.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "net/url"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestMD5Sum(t *testing.T) {
  10. var s = "123"
  11. var h = md5.New()
  12. fmt.Printf("md5=%x\n", h.Sum([]byte(s)))
  13. t.Errorf("something is wrong %d ", 1)
  14. }
  15. func TestRequestForm(t *testing.T) {
  16. // receiveUrl= [http://publicapi.lwork.com:8080/notify/default_notify]
  17. // orderAmount= [1200]
  18. // customerId= [123]
  19. // signType= [MD5]
  20. // orderCurrency= [CNY]
  21. // sign= [06bcbd40cf6b914ef8ea6596730571ba]
  22. // orderNo= [200306220049TW002184000000000001]
  23. // pickupUrl= [http://trader.supertraderfx.com/fund/tradingFlow]
  24. // my md5=06bcbd40cf6b914ef8ea6596730571ba
  25. form := url.Values{}
  26. form.Add("pickupUrl", "http://trader.supertraderfx.com/fund/tradingFlow")
  27. form.Add("receiveUrl", "http://publicapi.lwork.com:8080/notify/default_notify")
  28. form.Add("signType", "MD5")
  29. form.Add("orderNo", "200306220049TW002184000000000001")
  30. form.Add("orderAmount", "1200")
  31. form.Add("orderCurrency", "CNY")
  32. form.Add("customerId", "123")
  33. form.Add("sign", "06bcbd40cf6b914ef8ea6596730571ba")
  34. md5key := "492815086935204"
  35. expected := "06bcbd40cf6b914ef8ea6596730571ba"
  36. s := ""
  37. if _, ok := form["pickupUrl"]; ok {
  38. s += form["pickupUrl"][0]
  39. s += form["receiveUrl"][0]
  40. s += form["signType"][0]
  41. s += form["orderNo"][0]
  42. s += form["orderAmount"][0]
  43. s += form["orderCurrency"][0]
  44. s += form["customerId"][0]
  45. s += md5key
  46. }
  47. assert := assert.New(t)
  48. assert.Equal(expected, md5str(s), "the md5 result should be equal")
  49. }