Onelink.go 4.0 KB

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