UTF8 Encoded messages broken charecter on php smpp sms sending - php

Hi am using php smpp sms sending package to work on socket sms sending.
$transport = new SocketTransport(array(config('app.smppHost')), config('app.smppPort'));
$transport->setRecvTimeout(10000);
$smpp = new SmppClient($transport);
I am sending with $encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
$smpp->sendSMS($from,$to,$encodedMessage,null,null);
UPDATE
But the sms is receiving with broken character.I am sending in myn language and also tried as suggested
$smpp->sendSMS($from,$to,$encodedMessage,null,null);
But now half broken half proper message is sending. I think some encoded needed ???

This is special language encoded issue you need both override the encoded version in smpp package as well as encode the text itself.
First convert the string
mb_convert_encoding($message,'UCS-2',"utf8");
Then send sms in encoded in type 8. it should work properly
$smpp->sendSMS($from,$to,$encodedMessage,null,8);

Related

PHP imap: how to decode and convert Windows-1252 charset emails?

My PHP app processes incoming emails. The processing code usually works fine, but the app crashed recently with the below exception:
Unexpected encoding - UTF-8 or ASCII was expected (View: /home/customer/www/gonativeguide.com/gng2-core/vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/panel.blade.php) {"exception":"[object] (Facade\\Ignition\\Exceptions\\ViewException(code: 0): Unexpected encoding - UTF-8 or ASCII was expected (View: /home/customer/www/gonativeguide.com/gng2-core/vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/panel.blade.php) at /home/customer/www/gonativeguide.com/gng2-core/vendor/league/commonmark/src/Input/MarkdownInput.php:30)
It seems that there was an incoming email whose text was not properly decoded and this made the app crash later on.
I realized that the email had a Windows-1252 encoding:
Content-Type: text/html; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
The email decoding code looks currently like this:
// DECODE DATA
$data = ($partno)?
imap_fetchbody($mbox,$mid,$partno): // multipart
imap_body($mbox,$mid); // simple
// Any part may be encoded, even plain text messages, so check everything.
if ($p->encoding==4)
$data = quoted_printable_decode($data);
elseif ($p->encoding==3)
$data = base64_decode($data);
I checked this page to understand what I need to change to decode emails with Windows-1252, but it not clear to me which value corresponds to Windows-1252 and how to decode and convert the data to UTF-8. I would highly appreciate any hints, preferably with suggested code on this.
Thanks,
W.
In your case, this line:
$data = quoted_printable_decode($data);
needs to be adapted like this:
$data = mb_convert_encoding(quoted_printable_decode($data), 'UTF-8', 'Windows-1252');
More generally, to cope with non-UTF-8 encodings, you may want to extract the charset of the body part:
from the body part structure, returned by imap_bodystruct(), or
from the body part MIME headers, returned by imap_fetchmime().

Curl troubles sending long encrypted string by URL param

Im trying to send a long encrypted string with curl to an api and it gives me this
curl http://host.net/crypto.php?api=XXXXXXXX\&name=XXXX\&msg=$key
bash: /usr/bin/curl: Argument list too long```
If i try to send a file
curl http://host.net/crypto.php?api=XXXXXXX\&name=XXXX\&msg="#/tmp/.sendenc"
The server just gets #/tmp/.sendenc
The first way works fine with shorter strings but not with longer...
idk if this helps but its sending an encrypted image about 417025 letters :/

How to encode SMS PDU in php

I was trying to apply AT commands on my Huawei modem using gammu. I can use following commands to access USSD from ZTE Modem:
gammu getussd *111#
but in huawei modem, it doesn't work. As per my study, I need to provide PDU instead of text. Then I used this link to encode my code *111# and try following on command line.
gammu getussd AA582C3602
and it works!. Now I need to convert *111# to AA582C3602 using php.
This link describe how to decode PDU Encoded message. but I didn't find any reverse way to convert back the normal text into PDU encoded message.
Badly need your help.
Some Huawei modems don't support USSD... E220 doesn't... I'm using E1550 in Portugal for NOS (old Optimus) operator with no issues, but yes it's PDU encoded.
Tell the modem you will be sending PDU encoded whith AT+CMGF=0.
I use this commands prior to send the USSD
AT+CMGF=0
AT+CSCS="IRA"

Sending compressed text over Amazon SQS from PHP to NodeJS

I seem to be stuck at sending the compressed messages from PHP to NodeJS over Amazon SQS.
Over on the PHP side I have:
$SQS->sendMessage(Array(
'QueueUrl' => $queueUrl,
'MessageBody' => 'article',
'MessageAttributes' => Array(
'json' => Array(
'BinaryValue' => bzcompress(json_encode(Array('type'=>'article','data'=>$vijest))),
'DataType' => 'Binary'
)
)
));
NOTE 1: I also tried putting compressed data directly in the message, but the library gave me an error with some invalid byte data
On the Node side, I have:
body = decodeBzip(message.MessageAttributes.json.BinaryValue);
Where message is from sqs.receiveMessage() call and that part works since it worked for raw (uncompressed messages)
What I am getting is TypeError: improper format
I also tried using:
PHP - NODE
gzcompress() - zlib.inflateraw()
gzdeflate() - zlib.inflate()
gzencode() - zlib.gunzip()
And each of those pairs gave me their version of the same error (essentially, input data is wrong)
Given all that I started to suspect that an error is somewhere in message transmission
What am I doing wrong?
EDIT 1: It seems that the error is somewhere in transmission, since bin2hex() in php and .toString('hex') in Node return totally different values. It seems that Amazon SQS API in PHP transfers BinaryAttribute using base64 but Node fails to decode it. I managed to partially decode it by turning off automatic conversion in amazon aws config file and then manually decoding base64 in node but it still was not able to decode it.
EDIT 2: I managed to accomplish the same thing by using base64_encode() on the php side, and sending the base64 as a messageBody (not using MessageAttributes). On the node side I used new Buffer(messageBody,'base64') and then decodeBzip on that. It all works but I would still like to know why MessageAttribute is not working as it should. Current base64 adds overhead and I like to use the services as they are intended, not by work arounds.
This is what all the SQS libraries do under the hood. You can get the php source code of the SQS library and see for yourself. Binary data will always be base64 encoded (when using MessageAttributes or not, does not matter) as a way to satisfy the API requirement of having form-url-encoded messages.
I do not know how long the data in your $vijest is, but I am willing to bet that after zipping and then base64 encoding it will be bigger than before.
So my answer to you would be two parts (plus a third if you are really stubborn):
When looking at the underlying raw API it is absolutely clear that not using MessageAttributes does NOT add additional overhead from base64. Instead, using MessageAttributes adds some slight additional overhead because of the structure of the data enforced by the SQS php library. So not using MessageAttributes is clearly NOT a workaround and you should do it if you want to zip the data yourself and you got it to work that way.
Because of the nature of a http POST request it is a very bad idea to compress your data inside your application. Base64 overhead will likely nullify the compression advantage and you are probably better off sending plain text.
If you absolutely do not believe me or the API spec or the HTTP spec and want to proceed, then I would advise to send a simple short string 'teststring' in the BinaryValue parameter and compare what you sent with what you got. That will make it very easy to understand the transformations the SQS library is doing on the BinaryValue parameter.
gzcompress() would be decoded by zlib.Inflate(). gzdeflate() would be decoded by zlib.InflateRaw(). gzencode() would be decoded by zlib.Gunzip(). So out of the three you listed, two are wrong, but one should work.

socket_write Php byte[]

i have a code in c# and here use GetBytes(msg) for SSlStream.write, here send and received data correctly, here all work fine, now i want to make the same event in php, but here i cant see a SslSteam or similar(i think no problem, becouse i working with socket_connection, and i think SSL is only for security), now for compare i stop the code in c# for see what data is sending and try to convert in php, for send here, i can see a data byte{} in c# and with $message=unpack('C*',$message); i can convert the string to byte[], comparing with c# value is the same so, here all is ok, my problem is when i try to write the request, becouse in SslStream.write accpet byte[] but socket_write no accept whe i try send socket_write($socket, '\n', strlen($message)) i have a error : socket_write() expects parameter 2 to be string and obvius is becouse socket_write() only accept string, but so.. as i can send my byte[], becouse the server only accept a byte[] please help me
PD> my problem is how i can send the byte[], i dont know if can send eq socket_write($socket, $message[1], strlen($message)), note please byte is array eq with 70 items, etc
When reading you started with:
$message = unpack('C*',$message);
So when writing perform the reverse.
If you're on PHP 5.6 or higher use:
$message = pack('C*', ...$message);
Or for earlier versions, which didn't have splat operator:
$message = call_user_func_array(
"pack",
array_merge(array("C*"), $message)
);

Categories