Onelink.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package lib
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. )
  8. func yidong_token() (string, bool) {
  9. url := "https://api.iot.10086.cn/v5/ec/get/token?transid=851AIOT202204251553361888100000003&password=L44tB,J5EQhj&appid=851AIOT2022042515533618881&refresh=0"
  10. method := "GET"
  11. client := &http.Client{}
  12. req, err := http.NewRequest(method, url, nil)
  13. if err != nil {
  14. fmt.Println(err)
  15. return "", false
  16. }
  17. res, err := client.Do(req)
  18. if err != nil {
  19. fmt.Println(err)
  20. return "", false
  21. }
  22. defer res.Body.Close()
  23. body, err := ioutil.ReadAll(res.Body)
  24. if err != nil {
  25. fmt.Println(err)
  26. return "", false
  27. }
  28. fmt.Println(string(body))
  29. type Token struct {
  30. Token string `json:"token"`
  31. }
  32. type TestJson struct {
  33. Result []Token `json:"result"`
  34. }
  35. var c TestJson
  36. err = json.Unmarshal(body, c)
  37. if err := json.Unmarshal([]byte(body), &c); err != nil {
  38. fmt.Println("Error =", err)
  39. }
  40. fmt.Println("bodyjson:", c)
  41. //dd := c["result"]
  42. if len(c.Result) == 0 {
  43. return "", false
  44. }
  45. fmt.Println("Token:", c.Result[0].Token)
  46. return c.Result[0].Token, true
  47. }
  48. // 实时查询群组本月套餐内GPRS流量使用量信息。
  49. type FlowPoolSharingInfo struct {
  50. TotalAmount string `json:"totalAmount"`
  51. RemainAmount string `json:"remainAmount"`
  52. UseAmount string `json:"useAmount"`
  53. }
  54. func Yidong_group_data_margin() (FlowPoolSharingInfo, bool) {
  55. token, token_is := yidong_token()
  56. if !token_is {
  57. return FlowPoolSharingInfo{}, false
  58. }
  59. url := "https://api.iot.10086.cn/v5/ec/query/group-data-margin?transid=851AIOT202204251553361888100000003&token=" + token + "&groupId=9921000021089000"
  60. method := "GET"
  61. client := &http.Client{}
  62. req, err := http.NewRequest(method, url, nil)
  63. if err != nil {
  64. fmt.Println(err)
  65. return FlowPoolSharingInfo{}, false
  66. }
  67. res, err := client.Do(req)
  68. if err != nil {
  69. fmt.Println(err)
  70. return FlowPoolSharingInfo{}, false
  71. }
  72. defer res.Body.Close()
  73. body, err := ioutil.ReadAll(res.Body)
  74. if err != nil {
  75. fmt.Println(err)
  76. return FlowPoolSharingInfo{}, false
  77. }
  78. fmt.Println(string(body))
  79. type List_data struct {
  80. FlowPoolSharingInfo []FlowPoolSharingInfo `json:"flowPoolSharingInfo"`
  81. }
  82. type TestJson struct {
  83. Result []List_data `json:"result"`
  84. }
  85. var c TestJson
  86. err = json.Unmarshal(body, c)
  87. if err := json.Unmarshal([]byte(body), &c); err != nil {
  88. fmt.Println("Error =", err)
  89. }
  90. fmt.Println("bodyjson:", c)
  91. //dd := c["result"]
  92. if len(c.Result) == 0 {
  93. return FlowPoolSharingInfo{}, false
  94. }
  95. //fmt.Println("Token:",c.Result[0].UseAmount)
  96. return c.Result[0].FlowPoolSharingInfo[0], true
  97. }
  98. // 实时查询物联卡本月套餐内流量使用量。
  99. func yidong_sim_data_usage(msisdn string) (string, bool) {
  100. token, token_is := yidong_token()
  101. if !token_is {
  102. return "", false
  103. }
  104. url := "https://api.iot.10086.cn/v5/ec/query/sim-data-usage?transid=851AIOT202204251553361888100000003&token=" + token + "&msisdn=" + msisdn
  105. method := "GET"
  106. client := &http.Client{}
  107. req, err := http.NewRequest(method, url, nil)
  108. if err != nil {
  109. fmt.Println(err)
  110. return "", false
  111. }
  112. res, err := client.Do(req)
  113. if err != nil {
  114. fmt.Println(err)
  115. return "", false
  116. }
  117. defer res.Body.Close()
  118. body, err := ioutil.ReadAll(res.Body)
  119. if err != nil {
  120. fmt.Println(err)
  121. return "", false
  122. }
  123. fmt.Println(string(body))
  124. type List_data struct {
  125. DataAmount string `json:"dataAmount"`
  126. }
  127. type TestJson struct {
  128. Result []List_data `json:"result"`
  129. }
  130. var c TestJson
  131. err = json.Unmarshal(body, c)
  132. if err := json.Unmarshal([]byte(body), &c); err != nil {
  133. fmt.Println("Error =", err)
  134. }
  135. fmt.Println("bodyjson:", c)
  136. //dd := c["result"]
  137. if len(c.Result) == 0 {
  138. return "", false
  139. }
  140. //fmt.Println("Token:",c.Result[0].UseAmount)
  141. return c.Result[0].DataAmount, true
  142. }
  143. //
  144. //
  145. //flowPoolSharingInfo,_ := yidong_group_data_margin()
  146. //println("总量:",flowPoolSharingInfo.RemainAmount)
  147. //println("使用:",flowPoolSharingInfo.RemainAmount)
  148. //println("剩余:",flowPoolSharingInfo.RemainAmount)
  149. //
  150. //sim_data_usage,_ := yidong_sim_data_usage("1440761145498")
  151. //println("单卡使用量:",sim_data_usage)