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.

72 lignes
1.9KB

  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 buildForm() url.Values {
  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. return form
  35. }
  36. func TestRequestForm(t *testing.T) {
  37. form := buildForm()
  38. md5key := "492815086935204"
  39. expected := "06bcbd40cf6b914ef8ea6596730571ba"
  40. s := ""
  41. if _, ok := form["pickupUrl"]; ok {
  42. s += form["pickupUrl"][0]
  43. s += form["receiveUrl"][0]
  44. s += form["signType"][0]
  45. s += form["orderNo"][0]
  46. s += form["orderAmount"][0]
  47. s += form["orderCurrency"][0]
  48. s += form["customerId"][0]
  49. s += md5key
  50. }
  51. assert := assert.New(t)
  52. assert.Equal(expected, md5str(s), "the md5 result should be equal")
  53. }
  54. func TestMd5Form(t *testing.T) {
  55. form := buildForm()
  56. expected := "06bcbd40cf6b914ef8ea6596730571ba"
  57. expectedkey := "492815086935204"
  58. assert := assert.New(t)
  59. assert.Equal(expectedkey, Config.LeanWork.MD5Key, "md5key should be 492815086935204")
  60. result := md5LeanworkForm(form)
  61. assert.Equal(expected, result, "expected signature should be equal")
  62. }