Automatic work with SMS on the ZTE-MF823 modem

This modem is not a modem as such. This is a router with a Linux-based arm v7 processor, it is displayed in the system as a network card, and it starts up without problems in Linux (usb0 network interface, 192.168.0.0 subnet).

You can connect to the device via telnet (ip: 192.168.0.1, login: root, password: zte9x15), then deploy your iptables, hang scripts in crontab and much more, even install your own software, but this is not about that today.

To perform operations with the modem, you need to perform CGI requests to the web interface, wget or curl is suitable. In the modem from the megaphone there is no web muzzle, but in the Beeline there is. The web muzzle is a browser-based JavaScript application that sends the same CGI requests ajax, I could not find any suitable documentation for working with sms on the Internet, so I decided to fill in the web muzzle and catch the requests.

To work with SMS, you need to send POST requests to the address 192.168.0.1/goform/goform_set_cmd_process .

SMS sending:
goformId = SEND_SMS
notCallback = true
Number = subscriber number
sms_time = date in the format y; m; d; h; i; s
MessageBody = message text
ID = -1
encode_type = UNICODE

Delete SMS:
goformId = DELETE_SMS
msg_id = message id list separated by semicolon
notCallback = true

Receiving SMS:
To receive all messages in json format, you need to contact the address: 192.168.0.1/goform/goform_get_cmd_process?cmd=sms_data_total&page=0&data_per_page=5000&mem_store=1&tags=10&order_by=order+by+id+desc

All we will receive in response SMS in JSON format.

With sms removal, everything is simple, but the next trouble with receiving and sending is that each character is encoded with a UTF HEX code, we get the character code with the ord () function, translate what happened into a hexadecimal number system and finish it with zeros up to 4 characters, for the reverse decoding messages we divide the text into 4 characters, translate into a decimal number system and get the character by its number with the chr () function. It would seem that everything is so simple, but php doesn’t work very well with Unicode, so I had to invent some kind of bikes and quickly code, as a result of 3 hours of experiments, I got a PHP class for working with sms on this modem.

ip.'/goform/goform_set_cmd_process';
		$post='isTest=false&';
		$post.= 'goformId=SEND_SMS&';
		$post.= 'notCallback=true&';
		$post.= 'Number='.urlencode($number).'&';
		$date = gmdate('y;m;d;h;i;s;'.$this->tz,time()+($this->tz*3600));
		$post.= 'sms_time='.urlencode($date).'&';
		$post.= 'MessageBody='.($this->utf2hex($text)).'&';
		$post.= 'ID=-1&';
		$post.= 'encode_type=UNICODE';
		return $this->url($url,$post);
	}
	//возвращает массив всех смсок
	public function get_sms()
	{
		$cont=$this->url('http://'.$this->ip.'/goform/goform_get_cmd_process?cmd=sms_data_total&page=0&data_per_page=5000&mem_store=1&tags=10&order_by=order+by+id+desc');
		$cont = json_decode($cont,true);
		$cont = $cont['messages'];
		foreach ($cont as $id => $arr) $cont[$id]['content']=$this->hex2utf(($cont[$id]['content']));
		return $cont;
	}
	//удаляет все смс
	public function clear_sms($cont=0)
	{
		if ($cont===0) $cont=$this->get_sms();
		$list_id='';
		$url = 'http://'.$this->ip.'/goform/goform_set_cmd_process';
		foreach ($cont as $id => $arr) $list_id.=$cont[$id]['id'].';';
		$post='isTest=false&goformId=DELETE_SMS&msg_id='.urlencode($list_id).'¬Callback=true';
		return $this->url($url,$post);
	}
}
$zte = new ZTE_WEB;
//отправка $zte->send("+79220000000","проверка");
//чистка $zte->clear_sms($zte->get_sms());
//получение $zte->get_sms();
?>

It is assumed that scripts in php will receive all messages, and then do a cleaning of the modem's memory. This modem is connected to the Raspberry Pi, various sms handlers and a bot will hang in the crontab, which will respond to commands sent from trusted numbers and make certain decisions.

Also popular now: