Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to concatenate a string md5 encrypted signature using the format of url key-value pairs in lexicographical order

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use the format of url key-value pairs in dictionary order to concatenate a string md5 encrypted signature, the editor thinks it is very practical, so I share it for you to learn. I hope you can get something after reading this article, without saying much, let's take a look at it.

Concatenate all incoming non-null parameters into the string string1 in lexicographical order using the format of url key-value pairs

String string1 = key1=value1&key2=value2..

The string string2 is obtained by splicing the signature at the end of the string string1.

String string2 = string2 + & key name = 8934e7d15453e97507ef794cf7b0519d

Then encrypt the string2 with MD5, and convert the encrypted 32-bit string to uppercase. The resulting value is key_sign.

$payConfig = array ('pay_ver' = >' 1009, '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); / / signed 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));} / / submit 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;} above is how to use the format of url key-value pairs in lexicographical order to assemble a string md5 encrypted signature. Xiaobian believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report