E
E
eskrano2015-08-01 02:38:35
Classmates
eskrano, 2015-08-01 02:38:35

How to sign a request?

Goodnight! I connect the game of a friend (mobile) to classmates. Authorization and registration he did. All that's left is the payment, but I can't generate the sig correctly. I read the documentation for the 2nd day, there is absolutely no example of how to sign the request correctly ... When you click on the link

<a href="http://m.odnoklassniki.ru/api/show_payment?application_key=CBAQOQGFEBABABABA&session_key=2d30a5d5e03710d0d594b19870b349de42231ae265b6021a0582.7feca3&sig=98ce5ccbf6c5b3c372f3750cb3581876&name=gold&code=1&price=1"></a>
returns an error that the signature is not correct. I can't generate it in any way. Who connected sites to classmates? How did you generate the signature?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vjacheslav Kanivetc, 2015-08-10
@eskrano

The signature is generated as usual in api calls - for all parameters except sig and access_token

function calcSignature(query) {
        var i, keys = [];
        for (i in query) {
            keys.push(i.toString());
        }
        keys.sort();
        var sign = "";
        for (i = 0; i < keys.length; i++) {
            var key = keys[i];
            if (("sig" != key) && ("access_token" != key)) {
                sign += keys[i] + '=' + query[keys[i]];
            }
        }
        sign += SESSION_SECRET_KEY;
        sign = encodeUtf8(sign);
        return md5(sign);
    }
        var params = {};
        params['name'] = NAME;
        params['price'] = PRICE;
        params['code'] = CODE;
        params["application_key"] = APPKEY;
        if (SESSION_KEY) {
            params["session_key"] = SESSION_KEY;
        } else {
            params["access_token"] = ACCESS_TOKEN;
        }
        params['sig'] = calcSignature(params, SESSION_SECRET_KEY);

        var query = 'https://m.ok.ru/api/show_payment?';
        for (var key in params) {
            if (params.hasOwnProperty(key)) {
                query += key + "=" + encodeURIComponent(params[key]) + "&";
            }
        }

        window.open(query);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question