keywords:pbx ip pbx voip gateway gsm gateway

× Questions about G400/G410 Cards.

Sending Chinese SMS via G400P

8 years 5 months ago #6891 by bluemonster
I'm an university student,and I got a G400P card from one of my friends.I can use it to make and answer calls now.
Now I want to use it to send sms and I followed the instructions on http://wiki.openvox.cn/index.php/Troubleshooting_of_GSM_cards_Chinese
and successfully sent English SMS via a shell script
==============================================
# !/bin/bash
asterisk -rx 'gsm send sms 1 159xxxxxxxx "hello"'
==============================================
When I changed the content into Chinese such as “你好”,my cell phone received an empty SMS.I have tried different encodings for the script like ANSI,UTF-8,but it still didn't work.
My software environment is: opvx-bristuff-0.4.0-RC3h + CentOS5.5.
Can you give me some guidances on this problem? Thank you very much!

A student from Huazhong University of Science and Technology
8 years 5 months ago #6892 by lisa.gao
Hi,
Do you understand chinese? You need to send PDU in asterisk: gsm send pdu 1 XXX
The pdu format you can refer the following:
http://blog.csdn.net/CompassButton/archive/2007/02/06/1503801.aspx
Any problem, please contact me.

8 years 5 months ago #6894 by bluemonster
Thank you for your kind instructions
I have learned how to generate PDU format SMS from the url given above.
I also found a very useful online tool
http://smstools3.kekekasvi.com/topic.php?id=288 we can convert text-mode SMS into PDU format very easily here.

I also tried to write a relatively rough script to achieve the convertion.It was written in Python.
Anyone who needs it can freely use and modify the script.
Welcome to communicate with me via This email address is being protected from spambots. You need JavaScript enabled to view it.
# -*- coding: utf-8 -*-
#author's e-mail: bluemonster0808@gmail.com
import os
import codecs
import sys
def expand_to_16(ucode): #将ascii字符扩展到16-bit编码
    for i in range(len(ucode)):
        #print len(ucode[i])
        if (len(ucode[i])==4):
            ucode[i]= ucode[i][0:2]+"00"+ ucode[i][2:]
    return ucode

def ucs2_encode(src): #将字符串转换为ucs2编码,其实就是unicod编码
    decoder=codecs.getdecoder("utf-8")    
    ucs2=decoder(src)
    #print ucs2
    src_len=len(ucs2[0]) #原始字符串的长度,是字符数,而不是字节数
    ucode=[]
    result=""
    for i in range(src_len):
        ucode.append(hex(ord(ucs2[0][i])))
    #print ucode
    ucode=expand_to_16(ucode)
    #print ucode
    for item in ucode:
        result=result+item[2:]
    return result
 
def convertNumber(number): #将手机号码转换,如将8613800270500转为683108200705f0
    number=number[1:]  #去掉前面的“+”
    length=len(number)
    number2=""
    for i in range(length):
        if(i%2):
            continue
        else:
            if(i+1>=length):
                number2+="f" #不足偶数位的补F
            else:
                number2+=number[i+1]
            number2+=number[i]
    return number2
def PDUformat(des,smsc,content): #生成PDU format的短信
    type_of_address="91"  #SMSC和目标地址都默认用国际类型的地址,前面有“+”,中国的是“+86”
    smsc_len="08" #SMSC地址信息的长度  共八字节,包括91
    tp_mti="11" #这个参数我也不懂
    tp_mr="00" #这个参数我也不懂
    tp_pid="00" #默认为普通GSM类型,即点到点方式
    des_len="0d" #目标地址数字个数 共13个十进制数(不包括91和‘F’)
    alphabet_size="08"  #默认用16-bit编码
    validity="ff" #默认有效期为最长
    
    result=""
    result+=smsc_len
    result+=type_of_address    
    smsc=convertNumber(smsc)
    #print smsc
    result+=smsc
    result+=tp_mti
    result+=tp_mr
    result+=des_len
    result+=type_of_address
    des=convertNumber(des)
    #print des
    result+=des
    result+=tp_pid
    result+=alphabet_size
    result+=validity
    content_len=len(content)/2 #这里传进来的content是字符串,len(content)的话结果就是实际字符长度的2倍了
    #比如4f在len(content)算长度2,但是在PDU编码里它是一个字节
    result+=hex(content_len)[2:]
    result+=content
    return result
        
if  __name__=="__main__":   
      
    des="+8615926226759"
    smsc="+8613800270500"
    content="你好啊openvox"
    ucs2_content=ucs2_encode(content)
    #print ucs2_content
    print PDUformat(des,smsc,ucs2_content)

A student from Huazhong University of Science and Technology
Time to create page: 0.019 seconds
Powered by Kunena Forum