Signature Rules:
The first step,
Parameter name ASCII code from small to large sort (dictionary order);
When a validation call returns or proactively notifies the signature, the routed sign parameter does not participate in the signature, and the generated signature is verified with the sign Value.
Step two,
in the Stringa final stitching on App_secret get stringsigntemp string, and stringsigntemp MD5 operation, get sign
Code:
function Make_sign ($data, $Secret) {
Ksort ($data);
$KV _arr = Array ();
foreach ($data as $key = = $val) {
if ($key = = "sign" | | $val = = ') {
Continue
}
Array_push ($kv _arr, $key. ' = '. $val);
}
$MD 5_string = implode (' & ', $kv _arr);
$key _str = $md 5_string. ' &key= '. $Secret;
return strtolower (md5 ($key _str));
To receive a JSON parameter request:
$req _param = Json_decode (file_get_contents (' php://input '), true);
Send post JSON data request:
function Curljson ($url, $params =array ())
{
$query = Json_encode ($params);
$header = Array (
' Content-type:application/json ',
' Content-length: '. Strlen ($query)
);
$bin = Fetch_curl ($url, Array (
Curlopt_post = true,
Curlopt_postfields = $query,//note That curl cannot convert an array into a name[]=value& format
Curlopt_timeout = 60,
Curlopt_httpheader = $header,
), $http _code);
Return $bin;
}
/**
* @static
* Gets the content returned by a URL address
* @param string $url
* @param array $other _curl_opt Set curl options
* @return Mixed Success returns string, otherwise false
*/
function Fetch_curl ($url, $other _curl_opt = array (), & $http _code = 0)
{
$curl _opt = Array (
Curlopt_url = $url,
curlopt_autoreferer = True,//add Referer link automatically
Curlopt_returntransfer = true,//true:curl_exec Assignment method, false:curl_exec Direct output result
Curlopt_followlocation = False,//auto-trace 301,302 Jump
Curlopt_httpget = TRUE,//default is get, no setting required
Curlopt_post = TRUE,
Curlopt_postfields = ' Username=abc&passwd=bcd ',//can also array array (' username ' = ' abc ', ' passwd ' = ' BCD ')
Curlopt_connecttimeout = 15,//sec
Curlopt_useragent = self::http_agent,
Curlopt_cookie = ",
);
If ($other _curl_opt)
foreach ($other _curl_opt as $key = $val)
$curl _opt[$key] = $val;
$ch = Curl_init ();
Curl_setopt_array ($ch, $curl _opt);
$contents = curl_exec ($ch);
$http _code = Curl_getinfo ($ch, curlinfo_http_code);
Curl_close ($ch);
Return $contents;
}
function Curlpost ($url, $params =array ())
{
$query = Http_build_query ($params);
$header = Array (
' Content-type:application/x-www-form-urlencoded ',
' Content-length: '. Strlen ($query)
);
$bin = Net::fetch ($url, Array (
Curlopt_post = true,
Curlopt_postfields = $query,//note That curl cannot convert an array into a name[]=value& format
Curlopt_timeout = 60,
), $http _code);
Return $bin;
}
function Curlhttps ($url, $params =array (), $method = ' GET ')
{
$header = Array (
' Content-type:application/x-www-form-urlencoded;charset=utf-8 ',
);
$curl = Curl_init (); Start a Curl session
curl_setopt ($curl, curlopt_url, $url); The address to be accessed
curl_setopt ($curl, curlopt_ssl_verifypeer, false); Examination of the source of the certification certificate
curl_setopt ($curl, curlopt_ssl_verifyhost, false); Check that the SSL encryption algorithm exists from the certificate
curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
curl_setopt ($curl, curlopt_autoreferer, 1); Set Referer automatically
if ($method = = ' POST ') {
curl_setopt ($curl, curlopt_post, 1); Send a regular POST request
curl_setopt ($curl, curlopt_httpheader, $header);
If ($params) {
$query = Http_build_query ($params);
curl_setopt ($curl, curlopt_postfields, $query); Post-submitted Packets
}
}
curl_setopt ($curl, curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
curl_setopt ($curl, curlopt_header, 0); Displays the contents of the header area returned
curl_setopt ($curl, curlopt_returntransfer, 1); Gets the information returned as a file stream
$tmpInfo = curl_exec ($curl); Perform actions
Curl_close ($curl); Turn off the Curl session
Return $tmpInfo; Return data
}
function Curlheaderhttps ($url, $params =array (), $method = ' GET ')
{
$header [] = ' Content-type:multipart/form-data;charset=utf-8 ';
foreach ($params as $k = = $val) {
$header [] = "$k: $val";
}
$curl = Curl_init (); Start a Curl session
curl_setopt ($curl, curlopt_url, $url); The address to be accessed
curl_setopt ($curl, curlopt_ssl_verifypeer, false); Examination of the source of the certification certificate
curl_setopt ($curl, curlopt_ssl_verifyhost, false); Check that the SSL encryption algorithm exists from the certificate
curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
curl_setopt ($curl, curlopt_autoreferer, 1); Set Referer automatically
if ($method = = ' POST ') {
curl_setopt ($curl, curlopt_post, 1); Send a regular POST request
curl_setopt ($curl, curlopt_httpheader, $header);
If ($params) {
$query = Http_build_query ($params);
curl_setopt ($curl, curlopt_postfields, $query); Post-submitted Packets
}
}
curl_setopt ($curl, curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
curl_setopt ($curl, curlopt_header, 0); Displays the contents of the header area returned
curl_setopt ($curl, curlopt_returntransfer, 1); Gets the information returned as a file stream
$tmpInfo = curl_exec ($curl); Perform actions
Curl_close ($curl); Turn off the Curl session
Return $tmpInfo; Return data
}
function Curlfilepost ($url, $header =array (), $fp, $size)
{
If (! $FP) exit (' file is empty ');
If (! $header) {
$header = Array (
' Content-type:application/x-www-form-urlencoded ',
' Content-length: '. Strlen ($query)
);
}
$bin = Net::fetch ($url, Array (
Curlopt_post = true,
Curlopt_timeout = 60,
Curlopt_upload = 1,
Curlopt_infile = $fp,
Curlopt_infilesize = $size,
Curlopt_httpheader = $header,
), $http _code);
Return $bin;
}
Curl Request/signature