按字典序使用url键值对的格式拼接成字符串md5加密签名
对所有的传入的非空参数进行按字典序使用url键值对的格式拼接成字符串string1
String string1 = key1=value1&key2=value2..
在字符串string1最后拼接上签名所得的令得到字符串string2
String string2 = string2 + &密钥名称=8934e7d15453e97507ef794cf7b0519d
然后对string2进行MD5加密,再将加密所得到的32位字符串转换为大写,所得到的值即为key_sign
$payConfig = array(
"pay_ver" => "100",
"pay_type" => "010",
"service_id" => "015",
"merchant_no" => "",
"terminal_id" => "",
"terminal_trace" => $orderInfo["order_id"],
"terminal_time" => date("YmdHis"),
"total_fee" => $totalFee,
"sub_appid" => "",
"open_id" => $openid,
"notify_url" => "http://www.demo.com"
);
$access_token = "da3c47c2a8cd47e9be0868712dae0000";
$payConfig["key_sign"] = self::getSign($payConfig, $access_token);
//签名
function getSign($payConfig, $key) {
ksort($payConfig);
$str = "";
foreach ($payConfig as $k => $v) {
$str =$str. $k . "=" . $v."&";
}
$str=$str."access_token=".$key;
return strtoupper(md5($str));
}
//提交
function postPay($post_data) {
$postUrl = "";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $postUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($post_data),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
var_dump($response);
curl_close($curl);
return $response;
}
以上是 按字典序使用url键值对的格式拼接成字符串md5加密签名 的全部内容, 来源链接: utcz.com/z/510279.html