API permission design summary system sign verification rules-PHP source code

Source: Internet
Author: User
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 );}

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.