私はアーランで作業しており、私のPCに関連するモデムを使用しています
モデムから自分の電話番号にメッセージを送信したい
私はこの機能を開発しましたが、完全に機能します
send(To) ->
Message =http_urii:encode("Vous n'avez pas d'écheance à payer."),
Url = io_lib:format("http://192.168.1.5:9998/sendsms?tel=~s&text=~s", [To, Message]),
http:request(lists:flatten(Url), sms).
私の問題は、 é 、 àなどの分音記号を含む記号に関連しています。
携帯電話で SMS を受信しましたが、特殊文字が正しい形式で表示されないため、éが別の文字になり、àが別の文字になりました。
携帯電話に次のメッセージを受け取りたい: Vous n'avez pas d'écheance à payer.
send のソースコードを修正します
send(To) ->
Message =http_urii:encode("Vous n'avez pas d'%E9cheance %EA payer."),
Url = io_lib:format("http://192.168.1.5:9998/sendsms?tel=~s&text=~s", [To, Message]),
http:request(lists:flatten(Url), sms).
しかし、私の電話では、Vous n'avez pas d'%E9cheance %EA payer.というメッセージが表示されます。特殊文字のエンコードなし
http_urii.erlのソース コードは次のとおりです。
-module(http_urii).
-export([parse/1, encode/1, decode/1]).
%%%=========================================================================
%%% API
%%%=========================================================================
parse(AbsURI) ->
case parse_scheme(AbsURI) of
{error, Reason} ->
{error, Reason};
{Scheme, Rest} ->
case (catch parse_uri_rest(Scheme, Rest)) of
{UserInfo, Host, Port, Path, Query} ->
{Scheme, UserInfo, Host, Port, Path, Query};
_ ->
{error, {malformed_url, AbsURI}}
end
end.
encode(URI) ->
Reserved = sets:from_list([$;, $:, $@, $&, $=, $+, $,, $/, $?,
$#, $[, $], $<, $>, $\", ${, $}, $|,
$\\, $', $^, $%, $ ]),
lists:append(lists:map(fun(Char) ->
uri_encode(Char, Reserved)
end, URI)).
decode([$%,Hex1,Hex2|Rest]) ->
[hex2dec(Hex1)*16+hex2dec(Hex2)|decode(Rest)];
decode([First|Rest]) ->
[First|decode(Rest)];
decode([]) ->
[].
%%%========================================================================
%%% Internal functions
%%%========================================================================
parse_scheme(AbsURI) ->
case split_uri(AbsURI, ":", {error, no_scheme}, 1, 1) of
{error, no_scheme} ->
{error, no_scheme};
{StrScheme, Rest} ->
case list_to_atom(http_util:to_lower(StrScheme)) of
Scheme when Scheme == http; Scheme == https ->
{Scheme, Rest};
Scheme ->
{error, {not_supported_scheme, Scheme}}
end
end.
parse_uri_rest(Scheme, "//" ++ URIPart) ->
{Authority, PathQuery} =
case split_uri(URIPart, "/", URIPart, 1, 0) of
Split = {_, _} ->
Split;
URIPart ->
case split_uri(URIPart, "\\?", URIPart, 1, 0) of
Split = {_, _} ->
Split;
URIPart ->
{URIPart,""}
end
end,
{UserInfo, HostPort} = split_uri(Authority, "@", {"", Authority}, 1, 1),
{Host, Port} = parse_host_port(Scheme, HostPort),
{Path, Query} = parse_path_query(PathQuery),
{UserInfo, Host, Port, Path, Query}.
parse_path_query(PathQuery) ->
{Path, Query} = split_uri(PathQuery, "\\?", {PathQuery, ""}, 1, 0),
{path(Path), Query}.
parse_host_port(Scheme,"[" ++ HostPort) -> %ipv6
DefaultPort = default_port(Scheme),
{Host, ColonPort} = split_uri(HostPort, "\\]", {HostPort, ""}, 1, 1),
{_, Port} = split_uri(ColonPort, ":", {"", DefaultPort}, 0, 1),
{Host, int_port(Port)};
parse_host_port(Scheme, HostPort) ->
DefaultPort = default_port(Scheme),
{Host, Port} = split_uri(HostPort, ":", {HostPort, DefaultPort}, 1, 1),
{Host, int_port(Port)}.
split_uri(UriPart, SplitChar, NoMatchResult, SkipLeft, SkipRight) ->
case inets_regexp:first_match(UriPart, SplitChar) of
{match, Match, _} ->
{string:substr(UriPart, 1, Match - SkipLeft),
string:substr(UriPart, Match + SkipRight, length(UriPart))};
nomatch ->
NoMatchResult
end.
default_port(http) ->
80;
default_port(https) ->
443.
int_port(Port) when is_integer(Port) ->
Port;
int_port(Port) when is_list(Port) ->
list_to_integer(Port).
path("") ->
"/";
path(Path) ->
Path.
uri_encode(Char, Reserved) ->
case sets:is_element(Char, Reserved) of
true ->
[ $% | http_util:integer_to_hexlist(Char)];
false ->
[Char]
end.
hex2dec(X) when (X>=$0) andalso (X=<$9) -> X-$0;
hex2dec(X) when (X>=$A) andalso (X=<$F) -> X-$A+10;
hex2dec(X) when (X>=$a) andalso (X=<$f) -> X-$a+10.
今、http_uriiを標準のhttp_uriで変更します
しかし、プロジェクトのerlangを実行すると
このエラーがあります: Erlang R13B03 (erts-5.7.4) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.7.4 (abort with ^G)
1> exception: [{http_uri,encode,
["Vous n'avez pas d'écheance à payer."]},
{sms_alert,send,1},
{webrpc_api,build_response,2},
{webrpc_api,format_response,2},
{webrpc_api,process_command,2},
{httpd_response,traverse_modules,2},
{httpd_response,generate_and_send_response,1},
{httpd_request_handler,handle_response,1}]
私は erlang バージョン 13 で作業していることを知っていますが、プロジェクトの src でモジュール http_uri.erl を作成しているので、通常は動作するはずです。