米大师支付 erlang版

https://developers.weixin.qq.com/minigame/dev/tutorial/open-ability/midas-signature.html

-module(midas).

-export([test/0]).


%% 1ad64e8dcb2ec1dc486b7fdf01f4a15159fc623dc3422470e51cf6870734726b
test() ->
    Key = "zNLgAGgqsEWJOg1nFVaO5r7fAlIQxr1u",
    StringSignTemp = "appid=wx1234567&offer_id=12345678&openid=odkx20ENSNa2w5y3g_qOkOvBNM1g&pf=android&ts=1507530737&zone_id=1&org_loc=/cgi-bin/midas/getbalance&method=POST&secret=zNLgAGgqsEWJOg1nFVaO5r7fAlIQxr1u",
    SignBin = crypto:hmac(sha256, Key, StringSignTemp),
    lists:flatten([io_lib:format("~2.16.0b", [Char]) || <> <= SignBin]).

YSDK支付接口签名说明

-module(midas).

-export([test/0, sign/4]).

test() ->
    sign("GET", "56abfbcd12fe46f5ad85ad9f12345678&", "/v3/r/mpay/get_balance_m", "appid=15499&format=json&openid=00000000000000000000000014BDF6E4&openkey=AB43BF3DC5C3C79D358CC5318E41CF59&pf=myapp_m_qq-00000000-android-00000000-ysdk&pfkey=CA641BC173479B8C0B35BC84873B3DB9&ts=1340880299&userip=112.90.139.30&zoneid=1").

sign(Method, Key, Api, Data) ->
    ApiEncode = http_uri:encode(Api),
    DataEncode = http_uri:encode(Data),
    Data1 = Method ++ "&" ++ ApiEncode ++ "&" ++ DataEncode,
    sign(Key, Data1).


sign(Key, Data) ->
    SignBin = base64:encode(crypto:hmac(sha, Key, Data)),
    http_uri:encode(binary_to_list(SignBin)).

你可能感兴趣的:(米大师支付 erlang版)