tahoangminh269 / apns-php

Automatically exported from code.google.com/p/apns-php
0 stars 0 forks source link

Patch: Fix long UTF-8 messages exceeding max bytes and not able to truncate #22

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. put a long UTF-8 encoded string in a payload, for example, in 
$message->setText()

What is the expected output? What do you see instead?
Expected Results:
apns-php should be able to send it regardless of how big the string is, as long 
as it's UTF-8 encoded. If it's very long, it should be truncated 
(auto-adjusted) before it gets sent.

Current Results:
Fatal error: Uncaught exception 'ApnsPHP_Message_Exception' with message 'JSON 
Payload is too long: <n> bytes. Maximum size is <max> bytes. The message text 
can not be auto-adjusted.

What version of the product are you using? On what operating system?
r104

Please provide any additional information below.
By default, json_encode escapes UTF-8 encoded string to "\uxxxx". This is fine, 
however, it makes the string very big. Apple's servers accept both formats, 
escaped and unescaped UTF-8 strings.

For PHP < 5.4 there's no easy option as including JSON_UNESCAPED_UNICODE. 
Therefore, I have included a patch which should solve this issue.

Original issue reported on code.google.com by abdulrah...@gmail.com on 23 Feb 2012 at 7:28

Attachments:

GoogleCodeExporter commented 8 years ago
Here's a much improved version of the patch. I've added support for people who 
have mb_convert_encoding disabled.

Original comment by abdulrah...@gmail.com on 26 Feb 2012 at 11:43

Attachments:

GoogleCodeExporter commented 8 years ago
Thank you, this helped me out.

Original comment by primeh...@gmail.com on 4 Jul 2012 at 12:03

GoogleCodeExporter commented 8 years ago
The fix doesn't work on PHP 5.2 because of the anonymous function. I had to 
create an actual function then pass it in as a parameter like so: array($this, 
'convertMsgEncoding'),

Original comment by primeh...@gmail.com on 4 Jul 2012 at 11:27

GoogleCodeExporter commented 8 years ago
Thank you for your comment. The reason I've added it as anonymous function was 
because the requirements allowed me to do it. If you take a look at the 
requirements you will see that PHP should be 5.3.0 or later 
http://code.google.com/p/apns-php/#Requirements.

I appreciate your feedback, and this patch has been sitting here for almost 5 
months now without the maintainer's comments...

Original comment by abdulrah...@gmail.com on 4 Jul 2012 at 3:33

GoogleCodeExporter commented 8 years ago
When I first looked into using apns-php I noted that server did not meet the 
php 5.3.0 requirement, but I tried it anyway and it seemed to work fine. You 
don't need to update your patch, I was just stating what I had to do to get it 
working in case anyone else ran into the same problem.

This project hasn't been updated in over a year so I'm pretty sure it's no 
longer going to be. Too bad really, as I've found it to be quite useful.

Original comment by primeh...@gmail.com on 4 Jul 2012 at 9:09

GoogleCodeExporter commented 8 years ago
Dear,

The project source code has moved to github; if your issue is still valid, 
please open it on github page https://github.com/duccio/ApnsPHP/issues

Thanks.

Original comment by aldo.arm...@gmail.com on 26 Oct 2012 at 11:46