epay_util (erlang_pay v0.3.2)

View Source

通用工具:URL 编码 / 表单编码 / JSON / 类型转换 / 金额换算。

Summary

Functions

分 → 元字符串(两位小数,供支付宝 total_amount 等用)。

把 [{Key, Value}] 编码为 urlencoded 表单串(值做百分号编码,键原样)。

RFC3986 application/x-www-form-urlencoded 百分号编码。 不编码的非保留字符:A-Z a-z 0-9 - _ . ~;其余按 %HH 编码(空格→%20)。

元 → 分 安全换算(整数运算避浮点误差)。

Functions

fen_to_yuan_bin(Fen)

-spec fen_to_yuan_bin(integer()) -> binary().

分 → 元字符串(两位小数,供支付宝 total_amount 等用)。

form_encode(Pairs)

-spec form_encode([{binary() | string(), term()}]) -> binary().

把 [{Key, Value}] 编码为 urlencoded 表单串(值做百分号编码,键原样)。

json_decode(Bin)

-spec json_decode(binary()) -> {ok, term()} | {error, atom()}.

json_encode(Term)

-spec json_encode(term()) -> binary().

to_bin/1

-spec to_bin(term()) -> binary().

urlencode(V)

-spec urlencode(binary() | string() | integer()) -> binary().

RFC3986 application/x-www-form-urlencoded 百分号编码。 不编码的非保留字符:A-Z a-z 0-9 - _ . ~;其余按 %HH 编码(空格→%20)。

yuan_to_fen/1

-spec yuan_to_fen(term()) -> integer().

元 → 分 安全换算(整数运算避浮点误差)。