2

the problem that i have is when i execute the scripts below for sending the message it shows me an ok response and the message will get saved in the draft section not actually being sent

#! /bin/bash
[[ ! -f ~/.config/hilink.conf ]] && printf "HILINK_PROTO=http\nHILINK_HOST=192.168.8.1\nHILINK_PORT=80\nHILINK_USER=user\nHILINK_PASSWORD=password\n" >~/.config/hilink.conf



source ~/.config/hilink.conf

SesTokInfo=$(curl -s \
--url     "$HILINK_PROTO://$HILINK_HOST:$HILINK_PORT/api/webserver/SesTokInfo" \
--header  "Host:$HILINK_HOST" \
--user    "$HILINK_USER:$HILINK_PASSWORD" 
)
HILINK_COOKIE=$(echo "$SesTokInfo"|grep SessionID=|cut -b 10-147)
HILINK_TOKEN=$(echo "$SesTokInfo"|grep TokInfo|cut -b 10-41)

CONTENT=$1
PHONE=$2
DATE=$(date '+%Y-%m-%d %T')
LENGTH=${#CONTENT}

curl -fSs $HILINK_PROTO://$HILINK_HOST:$HILINK_PORT/api/sms/send-sms \
--header "Host:$HILINK_HOST" \
--header "Cookie:$HILINK_COOKIE" \
--header "__RequestVerificationToken:$HILINK_TOKEN" \
--user   "$HILINK_USER:$HILINK_PASSWORD" \
--data   "<request><Index>1</Index><Phones><Phone>$PHONE</Phone></Phones><Sca>0220227672</Sca><Content>$CONTENT</Content><Length>$LENGTH</Length><Reserved>1</Reserved><Date>$DATE</Date></request>"

this the drafts section image

med mansouri
  • 21
  • 1
  • 3
  • Does a simple version of this command (with no variables being used) work from the command line? Good luck. – shellter Jul 05 '20 at 17:51
  • Does this answer your question? [Sending and receiving SMS by command line with Huawei E3131 and HiLink on a debian system](https://stackoverflow.com/questions/38016641/sending-and-receiving-sms-by-command-line-with-huawei-e3131-and-hilink-on-a-debi) – alecxs Jul 05 '20 at 23:08

1 Answers1

0

After a bit of tinkering, and realising that my E3372h-320 was returning different XML tags to the ones your using, I came up with the code below which seems to work.

You'll need to install the xmlstarlet package from your repo.

#!/bin/bash

DATA=`curl --noproxy "*" http://192.168.8.1/api/webserver/SesTokInfo`
SESSION_ID=`echo "$DATA" | xmlstarlet sel -t -v '//SesInfo' -n`
TOKEN=`echo "$DATA" | xmlstarlet sel -t -v '//TokInfo' -n`

curl --noproxy "*" http://192.168.8.1/api/sms/send-sms -H "Cookie: $SESSION_ID" -H "__RequestVerificationToken: $TOKEN" --data "<?xml version='1.0' encoding='UTF-8'?
><request><Index>-1</Index><Phones><Phone>$1</Phone></Phones><Sca></Sca><Content>$2</Content><Length>-1</Length><Reserved>1</Reserved><Date>-1</Date></request>"
Graham
  • 1