0
API permission design summary system sign verification rules
Http://my.oschina.net/anziguoer/blog/624840
1.
[File]Receive. php
600) {echo 'verification invalid. Please resend the request'; die () ;}$ sign = $ data ['sign']; unset ($ data ['sign']); ksort ($ data); $ params = http_build_query ($ data); $ sign2 = md5 ($ params. $ secret); if ($ sign = $ sign2) {die ('verification passed ');} else {die ('request invalid') ;}}?>
2.
[File]Request. php
'Anziguoer @ sina.com ', 'sex' => 'mal', 'age' => '12', 'addr' => 'haidian district, Beijing '); // The passed parameters must contain key, sign, timestamp $ postData = array ("key" => $ key, "timestamp" => time ()); $ psotData = array_merge ($ postData, $ data); $ sign = getSign ($ secret, $ psotData); $ postData ['sign'] = $ sign; // Obtain signfunction getSign ($ secret, $ data) {// sort the values of the array by key ($ data ); // Generate the url in the form of $ params = http_build_query ($ data); // Generate sign $ sign = md5 ($ params. $ secret); return $ sign;} $ postData = array_merge ($ postData, $ data); request ($ postData ); /*** send server data * @ param [type] $ postData [description] * @ return [type] [description] */function request ($ postData) {$ curl = curl_init ('http: // host/receive. php '); curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ curl, CURLOPT_POST, TRUE); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ postData ); $ info = curl_exec ($ curl); curl_close ($ curl); print_r ($ info );}