7
7
"net/http"
8
8
"net/url"
9
9
"strconv"
10
+ "strings"
10
11
"time"
11
12
)
12
13
29
30
var httpClient * http.Client
30
31
31
32
func init () {
32
- httpClient = & http.Client {Timeout : time .Second * 10 }
33
+ httpClient = & http.Client {Timeout : time .Second * 30 }
33
34
registerDriver ("ZTE 8810FT" , newZTE8810FT )
34
35
}
35
36
@@ -48,6 +49,7 @@ func (m *zte8810ft) getNewRequest(method string, url *url.URL) *http.Request {
48
49
URL : url ,
49
50
Header : http.Header {
50
51
"Referer" : {fmt .Sprintf ("http://%s/index.html" , m .ip )},
52
+ "Content"
51
53
},
52
54
}
53
55
}
@@ -194,3 +196,80 @@ func (m *zte8810ft) GetCellConnStatus() (*LinkStatus, error) {
194
196
return nil , ErrUnknown
195
197
}
196
198
}
199
+
200
+ func (m * zte8810ft ) SendSMS (phone string , message string ) error {
201
+ // GET /goform/goform_set_cmd_process?goformId=SEND_SMS
202
+ // Prepare everything to make a request
203
+
204
+ // Encode message into GSM-7
205
+ // encodedMsg, err := gsm7.Encode([]byte(message))
206
+ // if err != nil {
207
+ // return ActionError{"sms send", err}
208
+ // }
209
+
210
+ u := m .getBaseURL ("/goform/goform_set_cmd_process" )
211
+
212
+ // Build body
213
+ query := u .Query ()
214
+ query .Add ("goformId" , "SEND_SMS" )
215
+ query .Add ("ID" , "-1" )
216
+ query .Add ("encode_type" , "GSM7_default" )
217
+ query .Add ("Number" , phone )
218
+ // query.Add("MessageBody", fmt.Sprintf("%X", encodedMsg))
219
+ query .Add ("MessageBody" , "0074006500730074" )
220
+
221
+ // Build send timestamp
222
+ currTime := time .Now ()
223
+ if _ , tz := currTime .Zone (); tz >= 0 {
224
+ query .Add ("sms_time" , currTime .Format ("06;01;02;15;04;05;+" )+ strconv .Itoa (tz / 3600 ))
225
+ } else {
226
+ query .Add ("sms_time" , currTime .Format ("06;01;02;15;04;05;" )+ strconv .Itoa (tz / 3600 ))
227
+ }
228
+
229
+ // data := map[string]string{
230
+ // "goformId": "SEND_SMS",
231
+ // "Number": phone,
232
+ // "sms_time": time.Now().Format("02;01;06;15;04;05;-07"),
233
+ // "MessageBody": string(encodedMsg),
234
+ // "ID": "-1",
235
+ // "encode_type": "GSM7_default",
236
+ // }
237
+
238
+ request := m .getNewRequest ("POST" , u )
239
+
240
+ // Some Go-level string manipulation
241
+ fmt .Println (query .Encode ())
242
+ // stringReader := strings.NewReader(query.Encode())
243
+ stringReader := strings .NewReader ("goformId=SEND_SMS&Number=%2B79124446729&sms_time=24%3B07%3B28%3B19%3B01%3B24%3B%2B4&MessageBody=0074006500730074&ID=-1&encode_type=GSM7_default" )
244
+ stringReadCloser := io .NopCloser (stringReader )
245
+ request .Body = stringReadCloser
246
+
247
+
248
+ resp , err := httpClient .Do (request )
249
+
250
+ // Process errors
251
+ switch {
252
+ case err != nil :
253
+ return ActionError {Action : "sms send" , Err : err }
254
+ case resp .StatusCode != 200 :
255
+ return ActionError {Action : "sms send" , Err : fmt .Errorf ("response status %d" , resp .StatusCode )}
256
+ }
257
+
258
+ // Read the response
259
+ defer resp .Body .Close ()
260
+ body , err := io .ReadAll (resp .Body )
261
+ if err != nil {
262
+ return ErrUnknown
263
+ }
264
+
265
+ result := new (result )
266
+ if err := json .Unmarshal (body , result ); err != nil {
267
+ return ActionError {Action : "sms send" , Err : UnmarshalError {RawData : & body , Err : err }}
268
+ }
269
+
270
+ if result .Result != "success" {
271
+ return ActionError {Action : "sms send" , Err : fmt .Errorf ("result: %s" , result .Result )}
272
+ }
273
+
274
+ return nil
275
+ }
0 commit comments