The following is a development document for the OpenID provided by kaixin.com written in PHP. I am not familiar with PHP,

Source: Internet
Author: User
Tags openid
? Php $ api_keyxxx; $ secretxxx; $ urlrest. kaixin001.comapirest. php; $ session_key $ _ GET [session_key]; if (empty ($ session_key) {$ session_key $ _ COOKIE [kx_connect_session_key];} else {setcookie (kx_connect_sess

? Php $ api_key = 'xxx'; $ secret = 'xxx'; $ url = 'HTTP: // rest.kaixin001.com/api/rest.php'; $ session_key = $ _ GET ['session _ key']; if (empty ($ session_key) {$ session_key = $ _ COOKIE ["kx_connect_session_key"];} else {setcookie ("kx_connect_sess

$ Api_key = 'xxx ';

$ Secret = 'xxx ';

$ Url = 'HTTP: // rest.kaixin001.com/api/rest.php ';

$ Session_key = $ _ GET ['session _ key'];

If (empty ($ session_key )){

$ Session_key = $ _ COOKIE ["kx_connect_session_key"];

} Else {

Setcookie ("kx_connect_session_key", $ session_key, time () + 3600*4 );

}

$ Param = array ('api _ key' => $ api_key, 'method' => 'users. getinfo', 'uid' => '100 100', 'format' => 'json', 'session _ key' => $ session_key ,);

$ Query = buildQuery ($ param, $ secret );

$ Result = postRequest ($ url, $ query );

$ Result = json_decode ($ result );

Function buildQuery ($ param, $ secret ){

$ Param ['call _ id'] = microtime (true );

$ Param ['V'] = '1. 0 ';

Ksort ($ param );

$ Request_str = '';

Foreach ($ param as $ key => $ value ){

$ Request_str. = $ key. '='. $ value; // No delimiter

}

$ Sig = $ request_str. $ secret;

$ Sig = md5 ($ sig );

$ Param ['sig '] = $ sig;

$ Query = http_build_query ($ param );

Return $ query;

}

Function postRequest ($ url, $ post_string ){
$ Useragent = 'kaixin001. com API PHP5 Client 1.1 (curl) '. phpversion (); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url );

If (strlen ($ post_string)> = 3 ){

Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_string );

}

Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );

Curl_setopt ($ ch, CURLOPT_USERAGENT, $ useragent );

Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 10 );

Curl_setopt ($ ch, CURLOPT_TIMEOUT, 30 );

$ Result = curl_exec ($ ch );

Curl_close ($ ch );

Return $ result;

}

Function url_base64_encode ($ str ){

$ Search = array ('+ ','/');

$ Replace = array ('*','-');

$ Basestr = base64_encode ($ str );

Return str_replace ($ search, $ replace, $ basestr );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.