[Gammu dan VFP] Mengirim dan menerima Pesan lebih dari 160 karakter

OK langsung aja yaa, cara menerima dan mengirim sms dengan gammu yang karakternya lebih dari 160, bagaimana implemntasinya di foxpro, gampang aja

Capture

pertama, untuk kirim sms


lcNope=ALLTRIM(Thisform.text1.Value)
lnSms=Len(Thisform.edit1.Value)

i=0
If lnSms >160
lcPesan =Alltrim(Thisform.edit1.Value)
*total Sms
lnByk = CEILING(lnSms/153)

=SQLExec(Thisform.konek,"SHOW TABLE STATUS LIKE 'outbox'","mOutbox")
Select mOutBox
lcId=VAL(mOutBox.Auto_increment)

For i=1 To lnByk
If i=1
lcPesanSplit = Substr(lcPesan,1,153)
lcPesan=SUBSTR(lcPesan,154)
lcudh= "050003A7"+Padl(Alltrim(Str(lnByk)),2,"0")+Padl(Alltrim(Str(i)),2,"0")

TEXT TO lcsql NOSHOW TEXTMERGE PRETEXT 7
INSERT INTO outbox (DestinationNumber, UDH, TextDecoded,ID, MultiPart,CreatorID)
VALUES ('<<lcnope>>', '<<lcudh>>', '<<lcPesanSplit>>','<<lcID>>', 'true','Gammu')
ENDTEXT

lnh=SQLexec(Thisform.konek,lcsql)
IF lnh <0
AERROR(laerror)
MESSAGEBOX(laerror[1,2])
endi
Else
lcPesanSplit=Substr(lcPesan,1,153)
lcPesan=SUBSTR(lcPesanSplit,154)
lcudh= "050003A7"+Padl(Alltrim(Str(lnByk)),2,"0")+Padl(Alltrim(Str(i)),2,"0")

TEXT TO lcsql NOSHOW TEXTMERGE PRETEXT 7
INSERT INTO outbox_multipart(UDH, TextDecoded, ID, SequencePosition)
VALUES ('<<lcUdh>>', '<<lcPesanSplit>>','<<lcId>>' ,' <<i>>')
ENDTEXT
lnh=SQLexec(Thisform.konek,lcsql)
IF lnh <0
AERROR(laerror)
MESSAGEBOX(laerror[1,2])
ENDIF
Endif
Endf

ENDIF

kedua, menerima/membaca inbox yang lebih dari 160 karakter


SELECT inbox
ZAP

=SQLEXEC(thisform.konek,"select * from inbox","mInbox")
SELECT * FROM mInbox INTO CURSOR TempInbox READWRITE
SELECT mInbox
SCAN
lcNope = SenderNumber
lcUDH = UDH

IF !EMPTY(lcUDH)

*Header UDH
lcHeader = SUBSTR(lcUdh,1,8)

*Total SMS
lcSplit=SUBSTR(lcUDH,9,2)
m=0
i=0
FOR i=1 TO INT(val(lcSplit))
lcUdhx = lcHeader+lcSplit+PADL(ALLTRIM(STR(i)),2,"0")
SELECT * FROM TempInbox WHERE senderNumber=lcNope AND UDH=lcUDHx INTO CURSOR InboxUDH

IF RECCOUNT("InboxUDH")>0
m=m+1
ENDIF
endf
lctext=""
IF m=INT(val(lcSplit))
FOR j=1 TO m
lcUdhx = lcHeader+lcSplit+PADL(ALLTRIM(STR(j)),2,"0")
SELECT * FROM TempInbox WHERE senderNumber=lcNope AND UDH=lcUDHx INTO CURSOR InboxUDH

SELECT inBoxUDH
lcNope = inboxUDH.senderNumber
lcText= lctext+inBoxUDH.Textdecoded
ldTgl=inboxUDH.ReceivingDateTime
lcId=inboxUDH.id
DELETE from TempInbox where id=lcId
* =SQLEXEC(thisform.konek,"DELETE from inbox where id=?lcId")
endf
INSERT INTO Inbox values(lcnope,lctext,ldTgl)

ENDIF
ENDIF
ends
SELECT inbox
GO top
thisform.grid1.Refresh

OK berikut saya sertakan formnya https://www.dropbox.com/s/gmweh2nxg01hayy/SmsGammu.rar?dl=0

 

[Tambahan]

sesuai penjelasan di blog om http://blog.rosihanari.net/teknik-mengirim-long-text-sms-gammu-dengan-query-sql/
yaitu tentang format UDH adalah “AAAAAAAA XX YY”, yang mana “AAAAAAA”  adalah format random hexadecimal, pertanyaannya bagaimana membuat format random hexadecimal?

ok berikut copasnya, bikin function

FUNCTION DecToHex
PARAMETERS liDecNumber
lsHexNumber = ""
IF liDecNumber > 0 && It's not negative, so do a straight TRANSFORM.
lsHexNumber = TRANSFORM(liDecNumber, "@0")
ELSE

*-- The number is negative, so we'll have to do a little more work,
*-- since it's not as straight forward as converting and adding a
*-- minus sign.

*-- Find the length of the resulting hex string.
lsHexNumber = TRANSFORM(ABS(liDecNumber), "@0")
IF SUBSTR(lsHexNumber, 3, 1) = "0" && The number has filled the
&& eight places of DWORD.
liLength = LEN(SUBSTR(lsHexNumber, NotAt("0", lsHexNumber, 2)))
ELSE
*-- Subtract to account for "0x".
liLength = LEN(TRANSFORM(ABS(liDecNumber), "@0")) - 2
ENDIF

lsTempHex = 0xFFFFFFFF
lsHexNumber = TRANSFORM(lsTempHex-ABS(liDecNumber) + 1, "@0")
ENDIF
RETURN lsHexNumber

selanjutnya edit tombol kirim,yang mana sebelumnya cuma statis yaitu “050003A7” , jadi dinamis dengan merubah jadi begini


lcHex =RIGHT(Dectohex(RAND()*100),2)
lcUDH1="050003"+lcHex

...

...

..

for i=1 to lnByk

...

if  i=1

....

lcudh= lcUDH1+Padl(Alltrim(Str(lnByk)),2,"0")+Padl(Alltrim(Str(i)),2,"0")

else

.....

lcudh= lcUDH1+Padl(Alltrim(Str(lnByk)),2,"0")+Padl(Alltrim(Str(i)),2,"0")

....

endif

endfor

Ok, silahkan dicopas aja, mg sukses selalu kawan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: