在GCM POST请求中解析除英语文字之外的所有语言

时间:2015-06-22 13:13:44

标签: android erlang xmpp google-cloud-messaging ejabberd

部分解决方案由:

Parsing ASCII characters with Erlang

案例1:这适用于印地语文本

mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrep39uT92AFuQ1ILouWkfPq52GgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([224,164,181,224,164,191,224,164,149,224,164,191,224,164,
                    170,224,165,128,224,164,161,224,164,191,224,
                    164,175,224,164,190]),
    "9@devlan/sd","asas"). 

结果:

{ok,"{\"multicast_id\":7485677963483149262,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1434977706573613%38d7c464f9fd7ecd\"}]}"}

案例2:英文字母(ASCII值100,101等)

(ejabberd@localhost)3> mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrep39uT92AMQ1ILouWkfPq52GgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([100,101,102,103]),
    "9@devlan/sd","asas").    

{error,{"HTTP/1.1", "JSON_PARSING_ERROR: Unexpected token END OF FILE at position 402.\n"}}

案例3:抛出异常

(ejabberd@localhost)4> mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrLouWkfPq52GgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([224,164,100,101,102,103]),
    "9@devlan/sd","asas").
** exception exit: {ucs,{bad_utf8_character_code}}
     in function  xmerl_ucs:from_utf8/1 (xmerl_ucs.erl, line 185)
     in call from mochijson2:json_encode_string/2 (mochijson2.erl, line 218)
     in call from mochijson2:'-json_encode_proplist/2-fun-0-'/3 (mochijson2.erl, line 199)
     in call from lists:foldl/3 (lists.erl, line 1248)
     in call from mochijson2:json_encode_proplist/2 (mochijson2.erl, line 202)
     in call from mochijson2:'-json_encode_proplist/2-fun-0-'/3 (mochijson2.erl, line 199)
     in call from lists:foldl/3 (lists.erl, line 1248)
     in call from mochijson2:json_encode_proplist/2 (mochijson2.erl, line 202)

案例4:如果字符值是0填充

(ejabberd@localhost)7> mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrep39uT92AM7asrqGgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([097,098]),
    "9@devlan/sd","asas").

{error,{"HTTP/1.1",
    [60,33,68,79,67,84,89,80,69,32,104,116,109,108,62,10,60,104,
     116,109,108,32,108,97,110|...]}}

此用户的GCM用户注册名称应以何种格式发送? 我觉得mochijson可能出错了,但是所有其他语言都运行良好,并且无法发送英文文字。

任何指针?

0 个答案:

没有答案