The solution of emoji expression garbled in push

Source: Internet
Author: User
Push content If it contains a emoji expression, you need to make the following changes
1 MySQL to use 5.5.3 or more (if not upgrade, please save with Base64, push and then Transcode)
2 Modify the table and push content field to the UTF8MB4_UNICODE_CI encoding format (no need to change the system's MY.CNF, do not need to restart MySQL)

If you use apnsphp to push, there may still be problems sending emoji emoticons:
Please find the Getpayload method of message.php, and add "false &&" to the convert-transcoding judgment to prohibit execution. Because this code will truncate part of the emoji expression.

$sJSON = Json_encode ($this->_getpayload (), defined (' Json_unescaped_unicode ')? json_unescaped_unicode:0); if (false &&!defined (' Json_unescaped_unicode ') && function_exists (' Mb_ Convert_encoding ') {$sJSON = Preg_replace_callback (' ~\\\\u ([0-9a-f]{4}) ~i ', create_function (' $aMatches ', ' return MB _convert_encoding (Pack ("h*", $aMatches [1]), "UTF-8", "UTF-16"); '), $sJSON);}

At this point, the problem is solved.

Later, a problem was found:
When you push a message, the message length of the push is limited because APNs supports only 256 bytes in the following versions of iOS8. Messages that are correctly push under the test environment (php5.5), push messages under the formal environment (php5.3) are truncated. After a code check, it is found that the json_encode is done before push, which is the first line of the above code, and if it is php5.4 the following version, defined (' Json_unescaped_unicode ') equals false. Therefore, the following if judgment will be executed, in order to support the emoji expression, ignoring the execution of the judgment, resulting in the message length after Json_encode 256 bytes, so some messages can be sent before, and now cannot be sent out. In order to completely solve the problem of emoji and message truncation, or to upgrade PHP to more than 5.4 version of it.

It is also recommended that the automatic truncation of messages over length be turned off:

protected $_bautoadjustlongpayload = false; /**< @type Boolean If the JSON payload is longer than maximum allowed size, Shorts message text. */

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.