Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

shell - Sending and receiving SMS by command line with Huawei E3131 and HiLink on a debian system

I long time searched the internet for a guide how to send sms by command line with Huawei E3131 and HiLink on a debian based linux system. All of them not worked. It seems, that there was an update on the software.


HiLink shows the following versions to me:

  • Device-Name: E3131
  • Hardware-Version: CU1E3131IM
  • Software-Version: 22.521.23.00.00
  • Web-Frontend-Version: 17.100.08.00.03

Following the question: How to send / receive sms by command line on a debian based linux system with E3131?


There is a follow up question for setting up the hardware on a headless system on superuser

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

3 steps are necessary:

  1. Get session id
  2. Get token
  3. Send / receive sms

Step 1 - Get session id

For getting the session id I use the following command in an own shell script:

#!/bin/bash

curl -b session.txt -c session.txt http://192.168.8.1/html/index.html > /dev/null 2>&1

Step 2 - Get token

For getting the token I use the following commands, also in an own shell script:

#!/bin/bash

TOKEN=$(curl -s -b session.txt -c session.txt http://192.168.8.1/html/smsinbox.html)
TOKEN=$(echo $TOKEN | cut -d'"' -f 10)

echo $TOKEN > token.txt

Step 3 Part A - Send SMS

Finally a third shell script for sending the sms, which also invokes the two other scripts:

#!/bin/bash

NUMBER=$1
MESSAGE=$2

./session.sh
./token.sh

LENGTH=${#MESSAGE}
TIME=$(date +"%Y-%m-%d %T")
TOKEN=$(<token.txt)

SMS="<request><Index>-1</Index><Phones><Phone>$NUMBER</Phone></Phones><Sca/><Content>$MESSAGE</Content><Length>$LENGTH</Length><Reserved>1</Reserved><Date>$TIME</Date></request>"

echo $SMS

curl -v -b session.txt -c session.txt -H "X-Requested-With: XMLHttpRequest" --data "$SMS" http://192.168.8.1/api/sms/send-sms --header "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml"

Usage is:

command phonenumber "text"

Step 3 Part B - Receive SMS

And for receiving the last unread sms (or, if not avaiable, the last read sms) I use the following script:

#!/bin/bash

./session.sh
./token.sh

TOKEN=$(<token.txt)

DATA="<request><PageIndex>1</PageIndex><ReadCount>1</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>"

curl -b session.txt -c session.txt -H "X-Requested-With: XMLHttpRequest" --data "$DATA" http://192.168.8.1/api/sms/sms-list --header "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml"

This is maybe not very good coding, but it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...