Documentation
¶
Index ¶
- Variables
- type ConnectionStatusResponse
- type ErrorResponse
- type Huawei
- func (h *Huawei) Connect() error
- func (h *Huawei) DeleteSMS(index int) error
- func (h *Huawei) Disconnect() error
- func (h *Huawei) GetConnectionStatus() ([]string, error)
- func (h *Huawei) GetSmsCount() ([]string, error)
- func (h *Huawei) GetSmsList() ([]SMS, error)
- func (h *Huawei) GetToken() error
- func (h *Huawei) IsConnected() (bool, error)
- func (h *Huawei) Login(username, password string) error
- func (h *Huawei) SendSMS(msg, phone string) error
- type Response
- type SMS
- type SMSCountResponse
- type SMSListResponse
Constants ¶
This section is empty.
Variables ¶
var ERROR_LOGIN_ALREADY_LOGIN = 108003
var ERROR_LOGIN_PASSWORD_WRONG = 108002
var ERROR_LOGIN_USERNAME_PWD_ORERRUN = 108007
var ERROR_LOGIN_USERNAME_PWD_WRONG = 108006
var ERROR_LOGIN_USERNAME_WRONG = 108001
var ERROR_SYSTEM_BUSY = 100004
var ERROR_SYSTEM_NO_RIGHTS = "100003"
var ERROR_SYSTEM_NO_SUPPORT = 100002
var ERROR_VOICE_BUSY = 120001
var ERROR_WRONG_TOKEN = 125001
Functions ¶
This section is empty.
Types ¶
type ConnectionStatusResponse ¶
type ConnectionStatusResponse struct { XMLName xml.Name `xml:"response"` ConnectionStatus string `xml:"ConnectionStatus"` SignalStrength string `xml:"SignalStrength"` SignalIcon string `xml:"SignalIcon"` CurrentNetworkType string `xml:"CurrentNetworkType"` CurrentServiceDomain string `xml:"CurrentServiceDomain"` RoamingStatus string `xml:"RoamingStatus"` BatteryStatus string `xml:"BatteryStatus"` BatteryLevel string `xml:"BatteryLevel"` SimlockStatus string `xml:"SimlockStatus"` WanIPAddress string `xml:"WanIPAddress"` PrimaryDNS string `xml:"PrimaryDns"` SecondaryDNS string `xml:"SecondaryDns"` CurrentWifiUser string `xml:"CurrentWifiUser"` TotalWifiUser string `xml:"TotalWifiUser"` ServiceStatus string `xml:"ServiceStatus"` SimStatus string `xml:"SimStatus"` WifiStatus string `xml:"WifiStatus"` }
type ErrorResponse ¶
type Huawei ¶
type Huawei struct { IP string // contains filtered or unexported fields }
func (*Huawei) Connect ¶
Connect establishes a connection to the Huawei device by sending a POST request to the /api/dialup/dial endpoint with a predefined payload. It returns an error if the request fails or if the response indicates a failure.
Returns:
- error: An error object if the connection attempt fails, otherwise nil.
func (*Huawei) DeleteSMS ¶
DeleteSMS deletes an SMS message from the Huawei device by its index. It sends a POST request to the "/api/sms/delete-sms" endpoint with the specified index.
Parameters:
- index: The index of the SMS message to be deleted.
Returns:
- error: An error if the request fails or if the response indicates a failure.
func (*Huawei) Disconnect ¶
Disconnect sends a request to disconnect the Huawei device. It constructs an XML payload with the action to disconnect, sends the request to the "/api/dialup/dial" endpoint, and checks the response for errors.
Returns an error if the request fails or if the response indicates a failure to disconnect.
func (*Huawei) GetConnectionStatus ¶
GetConnectionStatus retrieves the current connection status from the Huawei device. It sends a GET request to the /api/monitoring/status endpoint and parses the XML response.
Returns a slice of strings containing various connection status details, or an error if the request fails or the response cannot be parsed.
The returned slice contains the following elements in order: - ConnectionStatus - SignalStrength - SignalIcon - CurrentNetworkType - CurrentServiceDomain - RoamingStatus - BatteryStatus - BatteryLevel - SimlockStatus - WanIPAddress - PrimaryDNS - SecondaryDNS - CurrentWifiUser - TotalWifiUser - ServiceStatus - SimStatus - WifiStatus
Returns: - []string: A slice of strings containing the connection status details. - error: An error if the request fails or the response cannot be parsed.
func (*Huawei) GetSmsCount ¶
GetSmsCount retrieves the count of SMS messages from the Huawei device. It sends a GET request to the /api/sms/sms-count endpoint and parses the response.
Returns a slice of strings containing the counts of various SMS categories: - LocalUnread: Count of unread messages in local storage. - LocalInbox: Count of messages in the local inbox. - LocalOutbox: Count of messages in the local outbox. - LocalDraft: Count of draft messages in local storage. - LocalDeleted: Count of deleted messages in local storage. - SimUnread: Count of unread messages on the SIM card. - SimInbox: Count of messages in the SIM card inbox. - SimOutbox: Count of messages in the SIM card outbox. - SimDraft: Count of draft messages on the SIM card. - LocalMax: Maximum number of messages that can be stored locally. - SimMax: Maximum number of messages that can be stored on the SIM card.
Returns an error if the request fails or the response cannot be parsed.
func (*Huawei) GetSmsList ¶
GetSmsList retrieves a list of SMS messages from the Huawei device. It sends a POST request to the /api/sms/sms-list endpoint with the necessary payload. The function returns a slice of SMS messages and an error if any occurred during the process.
Returns:
- []SMS: A slice of SMS messages retrieved from the device.
- error: An error if the request failed or the response could not be unmarshaled.
func (*Huawei) GetToken ¶
GetToken retrieves a token from the Huawei web server. It sends a GET request to the /api/webserver/token endpoint and parses the XML response to extract the token. The token is then stored in the Huawei struct's token field. Returns an error if the request fails, the response cannot be read, or the XML cannot be unmarshaled.
func (*Huawei) IsConnected ¶
IsConnected checks the connection status of the Huawei device. It returns true if the device is connected (status code "901"), otherwise false. If there is an error retrieving the connection status, it returns false along with the error.
func (*Huawei) Login ¶
Login authenticates a user with the provided username and password. It encodes the password in base64, constructs an XML payload, and sends a POST request to the Huawei API endpoint for user login. The function sets necessary headers, including a request verification token obtained from the GetToken method. It reads and parses the XML response to determine the login status and returns an error if authentication fails.
Parameters:
- username: The username for authentication.
- password: The password for authentication.
Returns:
- error: An error if the login process fails, otherwise nil.
func (*Huawei) SendSMS ¶
SendSMS sends an SMS message to a specified phone number using the Huawei API. It constructs an XML payload with the message details and sends an HTTP POST request.
Parameters:
- msg: The message content to be sent.
- phone: The recipient's phone number.
Returns:
- error: An error if the SMS sending fails, otherwise nil.
type SMSCountResponse ¶
type SMSCountResponse struct { XMLName xml.Name `xml:"response"` LocalUnread string `xml:"LocalUnread"` LocalInbox string `xml:"LocalInbox"` LocalOutbox string `xml:"LocalOutbox"` LocalDraft string `xml:"LocalDraft"` LocalDeleted string `xml:"LocalDeleted"` SimUnread string `xml:"SimUnread"` SimInbox string `xml:"SimInbox"` SimOutbox string `xml:"SimOutbox"` SimDraft string `xml:"SimDraft"` LocalMax string `xml:"LocalMax"` SimMax string `xml:"SimMax"` }