model.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package model
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "fmt"
  6. "strconv"
  7. xtime "go-common/library/time"
  8. )
  9. const (
  10. // EmptyFace empty face
  11. EmptyFace = "http://static.hdslb.com/images/member/noface.gif"
  12. _cloudSalt = "bi_clould_tencent_01"
  13. _leak = 1
  14. )
  15. // FullFace account full face.
  16. func (m *Info) FullFace() string {
  17. if m.Face == "" {
  18. return EmptyFace
  19. }
  20. return fmt.Sprintf("http://i%d.hdslb.com%s", m.Mid%3, m.Face)
  21. }
  22. // Token token resp.
  23. type Token struct {
  24. Mid int64 `json:"mid"`
  25. AppID int32 `json:"appid"`
  26. AccessToken string `json:"access_key"`
  27. CreateAt int64 `json:"create_at"`
  28. UserID string `json:"userid"`
  29. Uname string `json:"uname"`
  30. Expires int64 `json:"expires"`
  31. Permission string `json:"permission"`
  32. }
  33. // LoginToken login token.
  34. type LoginToken struct {
  35. Mid int64 `json:"mid"`
  36. AccessKey string `json:"access_key"`
  37. Expires int64 `json:"expires"`
  38. }
  39. // RSAKey rsa key.
  40. type RSAKey struct {
  41. Hash string `json:"hash"`
  42. Key string `json:"key"`
  43. }
  44. // RenewToken renew token resp.
  45. type RenewToken struct {
  46. Expires int64 `json:"expires"`
  47. }
  48. // AsoAccount aso account.
  49. type AsoAccount struct {
  50. Mid int64 `json:"mid"`
  51. UserID string `json:"userid"`
  52. Uname string `json:"uname"`
  53. Pwd string `json:"pwd"`
  54. Salt string `json:"salt"`
  55. Email *string `json:"email"`
  56. Tel *string `json:"tel"`
  57. CountryID int64 `json:"country_id"`
  58. MobileVerified int8 `json:"mobile_verified"`
  59. Isleak int8 `json:"isleak"`
  60. Ctime xtime.Time `json:"-"`
  61. Mtime xtime.Time `json:"-"`
  62. }
  63. // ResRegV3 ResRegV3
  64. type ResRegV3 struct {
  65. Mid int `json:"mid"`
  66. }
  67. // ResRegV2 ResRegV2
  68. type ResRegV2 struct {
  69. Mid int `json:"mid"`
  70. AccessKey string `json:"accessKey"`
  71. }
  72. // ResReg ResReg
  73. type ResReg struct {
  74. Mid int `json:"mid"`
  75. }
  76. // ResByTel ResByTel
  77. type ResByTel struct {
  78. Mid int `json:"mid"`
  79. AccessKey string `json:"accessKey"`
  80. }
  81. // ResCaptcha ResCaptcha
  82. type ResCaptcha struct {
  83. Code int `json:"code"`
  84. Message string `json:"message"`
  85. Data CaptchaData `json:"data"`
  86. }
  87. // CaptchaData CaptchaData
  88. type CaptchaData struct {
  89. Token string `json:"token"`
  90. URL string `json:"url"`
  91. }
  92. // ArgRegV3 ArgRegV3
  93. type ArgRegV3 struct {
  94. User string `form:"user" validate:"required"`
  95. Pwd string `form:"pwd" validate:"required"`
  96. Captcha string `form:"captcha"`
  97. Ctoken string `form:"ctoken"`
  98. }
  99. // ArgRegV2 ArgRegV2
  100. type ArgRegV2 struct {
  101. Captcha string `form:"captcha"`
  102. Ctoken string `form:"ctoken"`
  103. }
  104. // ArgReg ArgReg
  105. type ArgReg struct {
  106. Email string `form:"email" validate:"required"`
  107. Userpwd string `form:"pwd" validate:"required"`
  108. User string `form:"user" validate:"required"`
  109. }
  110. // ArgByTel ArgByTel
  111. type ArgByTel struct {
  112. Tel string `form:"tel" validate:"required"`
  113. Uname string `form:"user" validate:"required"`
  114. Userpwd string `form:"pwd" validate:"required"`
  115. CountryID string `form:"country_id" validate:"required"`
  116. Captcha string `form:"captcha" validate:"required"`
  117. }
  118. // SendSms SendSms
  119. type SendSms struct {
  120. Tel string `form:"tel" validate:"required"`
  121. CountryID string `form:"country_id" validate:"required"`
  122. Captcha string `form:"captcha" `
  123. Ctoken string `form:"ctoken" `
  124. ResetPwd bool `form:"reset_pwd" `
  125. }
  126. // TdoRegV3 TdoRegV3
  127. type TdoRegV3 struct {
  128. Arg ArgRegV3
  129. Cookie string
  130. IP string
  131. }
  132. // TdoRegV2 TdoRegV2
  133. type TdoRegV2 struct {
  134. Arg ArgRegV2
  135. Cookie string
  136. IP string
  137. }
  138. // TdoReg TdoReg
  139. type TdoReg struct {
  140. Arg ArgReg
  141. Cookie string
  142. IP string
  143. }
  144. // TdoByTel TdoByTel
  145. type TdoByTel struct {
  146. Arg ArgByTel
  147. Cookie string
  148. IP string
  149. }
  150. // TdoSendSms TdoSendSms
  151. type TdoSendSms struct {
  152. Arg SendSms
  153. Cookie string
  154. IP string
  155. }
  156. // Leak leak.
  157. func (a *AsoAccount) Leak() bool {
  158. return a.Isleak == _leak
  159. }
  160. // DefaultHash hash a plain text using default salt.
  161. func DefaultHash(plaintext string) string {
  162. return doHash(plaintext, _cloudSalt)
  163. }
  164. func doHash(plaintext, salt string) string {
  165. if plaintext == "" {
  166. return ""
  167. }
  168. hash := md5.New()
  169. hash.Write([]byte(plaintext))
  170. hash.Write([]byte(salt))
  171. md := hash.Sum(nil)
  172. return hex.EncodeToString(md)
  173. }
  174. // DefaultUserID get default user id.
  175. func DefaultUserID(mid int64) string {
  176. return "用户" + strconv.FormatInt(mid, 10)
  177. }
  178. // DefaultUname get default uname.
  179. func DefaultUname(mid int64) string {
  180. return "用户" + strconv.FormatInt(mid, 10)
  181. }