models.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. package downloader
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "time"
  7. )
  8. // rawCertificate 微信支付平台证书信息
  9. type rawCertificate struct {
  10. // 证书序列号
  11. SerialNo *string `json:"serial_no"`
  12. // 证书有效期开始时间
  13. EffectiveTime *time.Time `json:"effective_time"`
  14. // 证书过期时间
  15. ExpireTime *time.Time `json:"expire_time"`
  16. // 为了保证安全性,微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密
  17. EncryptCertificate *encryptCertificate `json:"encrypt_certificate"`
  18. }
  19. // MarshalJSON 自定义JSON序列化
  20. func (o rawCertificate) MarshalJSON() ([]byte, error) {
  21. toSerialize := map[string]interface{}{}
  22. if o.SerialNo == nil {
  23. return nil, fmt.Errorf("field `SerialNo` is required and must be specified in rawCertificate")
  24. }
  25. toSerialize["serial_no"] = o.SerialNo
  26. if o.EffectiveTime == nil {
  27. return nil, fmt.Errorf("field `EffectiveTime` is required and must be specified in rawCertificate")
  28. }
  29. toSerialize["effective_time"] = o.EffectiveTime.Format(time.RFC3339)
  30. if o.ExpireTime == nil {
  31. return nil, fmt.Errorf("field `ExpireTime` is required and must be specified in rawCertificate")
  32. }
  33. toSerialize["expire_time"] = o.ExpireTime.Format(time.RFC3339)
  34. if o.EncryptCertificate == nil {
  35. return nil, fmt.Errorf("field `encryptCertificate` is required and must be specified in rawCertificate")
  36. }
  37. toSerialize["encrypt_certificate"] = o.EncryptCertificate
  38. return json.Marshal(toSerialize)
  39. }
  40. // String 自定义字符串表达
  41. func (o rawCertificate) String() string {
  42. var ret string
  43. if o.SerialNo == nil {
  44. ret += "SerialNo:<nil>, "
  45. } else {
  46. ret += fmt.Sprintf("SerialNo:%v, ", *o.SerialNo)
  47. }
  48. if o.EffectiveTime == nil {
  49. ret += "EffectiveTime:<nil>, "
  50. } else {
  51. ret += fmt.Sprintf("EffectiveTime:%v, ", *o.EffectiveTime)
  52. }
  53. if o.ExpireTime == nil {
  54. ret += "ExpireTime:<nil>, "
  55. } else {
  56. ret += fmt.Sprintf("ExpireTime:%v, ", *o.ExpireTime)
  57. }
  58. ret += fmt.Sprintf("encryptCertificate:%v", o.EncryptCertificate)
  59. return fmt.Sprintf("rawCertificate{%s}", ret)
  60. }
  61. type downloadCertificatesResponse struct {
  62. // 平台证书列表
  63. Data []rawCertificate `json:"data,omitempty"`
  64. }
  65. // MarshalJSON 自定义JSON序列化
  66. func (o downloadCertificatesResponse) MarshalJSON() ([]byte, error) {
  67. toSerialize := map[string]interface{}{}
  68. if o.Data != nil {
  69. toSerialize["data"] = o.Data
  70. }
  71. return json.Marshal(toSerialize)
  72. }
  73. // String 自定义字符串表达
  74. func (o downloadCertificatesResponse) String() string {
  75. var ret string
  76. ret += fmt.Sprintf("Data:%v", o.Data)
  77. return fmt.Sprintf("downloadCertificatesResponse{%s}", ret)
  78. }
  79. // encryptCertificate 为了保证安全性,微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密
  80. type encryptCertificate struct {
  81. // 加密所使用的算法,目前可能取值仅为 AEAD_AES_256_GCM
  82. Algorithm *string `json:"algorithm"`
  83. // 加密所使用的随机字符串
  84. Nonce *string `json:"nonce"`
  85. // 附加数据包(可能为空)
  86. AssociatedData *string `json:"associated_data"`
  87. // 证书内容密文,解密后会获得证书完整内容
  88. Ciphertext *string `json:"ciphertext"`
  89. }
  90. // MarshalJSON 自定义JSON序列化
  91. func (o encryptCertificate) MarshalJSON() ([]byte, error) {
  92. toSerialize := map[string]interface{}{}
  93. if o.Algorithm == nil {
  94. return nil, fmt.Errorf("field `Algorithm` is required and must be specified in encryptCertificate")
  95. }
  96. toSerialize["algorithm"] = o.Algorithm
  97. if o.Nonce == nil {
  98. return nil, fmt.Errorf("field `Nonce` is required and must be specified in encryptCertificate")
  99. }
  100. toSerialize["nonce"] = o.Nonce
  101. if o.AssociatedData == nil {
  102. return nil, fmt.Errorf("field `AssociatedData` is required and must be specified in encryptCertificate")
  103. }
  104. toSerialize["associated_data"] = o.AssociatedData
  105. if o.Ciphertext == nil {
  106. return nil, fmt.Errorf("field `Ciphertext` is required and must be specified in encryptCertificate")
  107. }
  108. toSerialize["ciphertext"] = o.Ciphertext
  109. return json.Marshal(toSerialize)
  110. }
  111. // String 自定义字符串表达
  112. func (o encryptCertificate) String() string {
  113. var ret string
  114. if o.Algorithm == nil {
  115. ret += "Algorithm:<nil>, "
  116. } else {
  117. ret += fmt.Sprintf("Algorithm:%v, ", *o.Algorithm)
  118. }
  119. if o.Nonce == nil {
  120. ret += "Nonce:<nil>, "
  121. } else {
  122. ret += fmt.Sprintf("Nonce:%v, ", *o.Nonce)
  123. }
  124. if o.AssociatedData == nil {
  125. ret += "AssociatedData:<nil>, "
  126. } else {
  127. ret += fmt.Sprintf("AssociatedData:%v, ", *o.AssociatedData)
  128. }
  129. if o.Ciphertext == nil {
  130. ret += "Ciphertext:<nil>"
  131. } else {
  132. ret += fmt.Sprintf("Ciphertext:%v", *o.Ciphertext)
  133. }
  134. return fmt.Sprintf("encryptCertificate{%s}", ret)
  135. }