Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
联路控制台
https://www.shlianlu.com/console/document
Admin
联路控制台是一个为开发者提供国内短信和语音通信服务的平台,支持API调用进行短信签名、模板管理、消息发送、报告拉取与推送等功能。
Tokens:
3,755
Snippets:
13
Trust Score:
2.6
Update:
10 months ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Signature Generation Process Source: https://www.shlianlu.com/console/document/Signature Detailed explanation of how to generate the signature for API requests, including parameter sorting, filtering, string concatenation, and MD5 encryption. ```APIDOC ## Signature Generation Process ### Description This section details the steps required to generate a valid signature for API requests. The process involves sorting parameters, filtering specific fields, concatenating the remaining parameters with a key, and then MD5 encrypting the resulting string. ### Steps 1. **Sort Parameters**: Sort all parameter names in the request alphabetically. 2. **Filter Parameters**: Remove specific parameters from the signature calculation (e.g., "PhoneNumberSet", "SessionContext", "Signature"). Also, remove parameters with empty values. 3. **Concatenate Parameters**: Concatenate the remaining parameters in their sorted order into a single string, appending the platform secret key (`key`) at the end. 4. **MD5 Encryption**: Encrypt the concatenated string using MD5. 5. **Convert to Uppercase**: Convert the resulting MD5 hash to uppercase. ### Parameter Sorting Example For the SMS sending API, the sorted parameter names are: `AppId`, `MchId`, `PhoneNumberSet`, `SessionContext`, `SignName`, `SignType`, `Signature`, `Tag`, `TaskTime`, `TimeStamp`, `Type`, `Version`. ### Parameters to Exclude from Signature Calculation - `PhoneNumberSet` - `SessionContext` - `SessionContextSet` - `ContextParamSet` - `TemplateParamSet` - `Signature` - `PhoneList` - `phoneSet` ### Concatenated String Example (before encryption) `AppId=1001xxx&MchId=1xxx9&SignName=【联麓】&SignType=MD5&Tag=123&TimeStamp=1694159054&Type=1&Version=1.2.0&key=6fxxxx50` ### Final Signature Example (after MD5 encryption and uppercase conversion) `666849EC085DEC88C096B2943B8A0AC1` ### Code Examples #### Java ```java public String sign(Map<String, Object> params, String appKey) throws NoSuchAlgorithmException { // Sort parameters by key, filter out excluded fields, and join with '&' String str = params.entrySet().stream() .filter(e -> (!e.getKey().equals("Signature") && !e.getKey().equals("SessionContext") && !e.getKey().equals("PhoneNumberSet") && !e.getKey().equals("SessionContextSet") && !e.getKey().equals("ContextParamSet") && !e.getKey().equals("TemplateParamSet") && !e.getKey().equals("PhoneList") && !e.getKey().equals("phoneSet") && e.getValue() != null && !e.getValue().toString().isEmpty() )) .sorted(Map.Entry.comparingByKey()) .map(e -> e.getKey() + "=" + e.getValue()) // Append appKey at the end .collect(Collectors.joining("&")) + "&key=" + appKey; // MD5 encrypt the string and convert to uppercase MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes("UTF-8")); byte[] digest = md.digest(); StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("%02x", b & 0xff)); } return sb.toString().toUpperCase(); } ``` #### PHP ```php // Calculate digital signature $key = '3b8ee580a83549248e69d09591f8caef'; // Replace with your actual appkey // Sort parameters by key kksort($params); // Exclude specific parameters $noSignKey = array("Signature", "ContextParamSet", "TemplateParamSet", "SessionContextSet", "PhoneNumberSet", "SessionContext", "PhoneList", "phoneSet"); $signStr = ''; // Concatenate remaining parameters foreach ($params as $k => $value) { if(!in_array($k, $noSignKey)) { $signStr .= "{$k}={$value}&"; } } // Append appkey at the end $signStr .= "key={$key}"; print_r($signStr); // MD5 encrypt and convert to uppercase $signature = strtoupper(md5($signStr)); $params['Signature'] = $signature; ``` #### C# ```csharp static string GetSignature(var payload, string key){ // Sort parameters var signParams = new SortedDictionary<string, string>(StringComparer.Ordinal); // Iterate through all request parameters and filter foreach (KeyValuePair<string, object> item in payload) { if (!new List<string> { "PhoneNumberSet", "SessionContext", "SessionContextSet", "ContextParamSet", "TemplateParamSet", "Signature", "PhoneList", "phoneSet" }.Contains(item.Key)) { signParams.Add(item.Key, item.Value.ToString()); } } var signStr = new StringBuilder(); // Concatenate filtered request parameters in order foreach (var pair in signParams) { signStr.Append(pair.Key).Append("=").Append(pair.Value).Append("&"); } // Append AppKey to the end of the string // ... rest of the C# implementation would follow here ... } ``` ``` -------------------------------- ### Generate Signature with MD5 (C#) Source: https://www.shlianlu.com/console/document/Signature This C# code snippet illustrates how to generate an MD5 signature for API requests. It uses a SortedDictionary to order parameters, filters out excluded keys, concatenates them with the app key, and then computes the uppercase MD5 hash. ```csharp static string GetSignature(var payload, string key){ // 参数排序 var signParams = new SortedDictionary<string, string>(StringComparer.Ordinal); // 遍历请求中所有参数名并过滤 foreach (KeyValuePair<string, object> item in payload) { if (!new List<string> { "PhoneNumberSet", "SessionContext", "SessionContextSet", "ContextParamSet", "TemplateParamSet", "Signature", "PhoneList", "phoneSet" }.Contains(item.Key)) { signParams.Add(item.Key, item.Value.ToString()); } } var signStr = new StringBuilder(); // 拼接过滤后请求参数 foreach (var pair in signParams) { signStr.Append(pair.Key).Append("=").Append(pair.Value).Append("&"); } // 字符串结尾拼接上AppKey ``` -------------------------------- ### Python MD5 Signature Generation with Parameter Filtering Source: https://www.shlianlu.com/console/document/Signature This Python snippet calculates an MD5 signature. It iterates through parameters, sorts them by key, filters out specific keys and empty values, and concatenates them into a string, appending an AppKey at the end. The resulting string is then MD5 hashed using the `hashlib` module and returned in uppercase. It relies on the `hashlib` library. ```python # 参数md5计算 def getMD5(params, AppKey): signStr = '' # 参数名排序,参数名过滤,按顺序拼接 for key in sorted(params): if str(params[key]) == '': continue if key in ["Signature", "PhoneNumberSet", "SessionContext", "TemplateParamSet", "SessionContextSet", "ContextParamSet", "PhoneList", "phoneSet"]: continue signStr += key + '=' + str(params[key]) + '&' # 结尾拼接上AppKey signStr += 'key=' + AppKey # MD5加密字符串后大写 m = hashlib.md5() b = signStr.encode(encoding='utf-8') m.update(b) return (m.hexdigest()).upper() ``` -------------------------------- ### C# MD5 Signature Generation Source: https://www.shlianlu.com/console/document/Signature This C# snippet generates an MD5 signature. It constructs a string by appending a key-value pair, computes the MD5 hash of the UTF-8 encoded string, and returns the hexadecimal representation in uppercase. It utilizes the `System.Security.Cryptography.MD5` class. ```csharp public static string GenerateSignature(string key) { var signStr = new System.Text.StringBuilder(); signStr.Append("key=").Append(key); // MD5加密并大写 using var md5 = MD5.Create(); var inputBytes = Encoding.UTF8.GetBytes(signStr.ToString()); var hashBytes = md5.ComputeHash(inputBytes); var signature = BitConverter.ToString(hashBytes).Replace("-", "").ToUpper(); return signature; } ``` -------------------------------- ### Generate Signature with MD5 (Java) Source: https://www.shlianlu.com/console/document/Signature This Java code snippet demonstrates how to generate an MD5 signature for API requests. It filters out specific parameters, sorts the remaining ones, concatenates them with the app key, and then calculates the uppercase MD5 hash. ```java public String sign(Map<String, Object> params, String appKey) throws NoSuchAlgorithmException { // 请求中所有参数名排序,参数过滤后按顺序拼接 String str = params.entrySet().stream() .filter(e -> (!e.getKey().equals("Signature") && !e.getKey().equals("SessionContext") && !e.getKey().equals("PhoneNumberSet") && !e.getKey().equals("SessionContextSet") && !e.getKey().equals("ContextParamSet") && !e.getKey().equals("TemplateParamSet") && !e.getKey().equals("PhoneList") && !e.getKey().equals("phoneSet") && e.getValue() != null && !e.getValue().toString().isEmpty() )) .sorted(Map.Entry.comparingByKey()) .map(e -> e.getKey() + "=" + e.getValue()) // 结尾拼接上appkey .collect(Collectors.joining("&")) + "&key=" + appKey; // 拼接后字符串MD5加密 MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes("UTF-8")); byte[] digest = md.digest(); StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("%02x", b & 0xff)); } // 加密后大写 return sb.toString().toUpperCase(); } ``` -------------------------------- ### Generate Signature with MD5 (PHP) Source: https://www.shlianlu.com/console/document/Signature This PHP code snippet shows how to calculate an MD5 signature for API requests. It sorts parameters by key, filters out specific keys, concatenates the remaining key-value pairs with the app key, and then returns the uppercase MD5 hash. ```php // 计算数字签名 $key = '3b8ee580a83549248e69d09591f8caef'; // 这里替换为实际的 appkey // 按照请求中的参数名排序 ksort($params); //去除相关参数 $noSignKey = array("Signature", "ContextParamSet", "TemplateParamSet", "SessionContextSet", "PhoneNumberSet", "SessionContext", "PhoneList", "phoneSet"); $signStr = ''; //按顺序拼接 foreach ($params as $k => $value) { if(!in_array($k, $noSignKey)) { $signStr .= "{$k}={$value}&"; } } //最后拼接上appkey $signStr .= "key={$key}"; print_r($signStr); //MD5加密后大写 $signature = strtoupper(md5($signStr)); $params['Signature'] = $signature; ``` -------------------------------- ### POST /sms/product/balance Source: https://www.shlianlu.com/console/document/Signature This endpoint is used for sending ordinary SMS messages. It requires a signature to be included in the request for security purposes. The signature is generated based on the request parameters and a platform key. ```APIDOC ## POST /sms/product/balance ### Description This endpoint is for sending ordinary SMS messages. A signature must be included in the request for security. ### Method POST ### Endpoint `/sms/product/balance` ### Parameters #### Query Parameters None #### Request Body - **AppId** (string) - Required - Your application ID. - **MchId** (string) - Required - Your merchant ID (enterprise ID). - **SignType** (string) - Required - The type of signature algorithm used (e.g., "MD5"). - **SignName** (string) - Required - The name associated with the signature. - **TimeStamp** (string) - Required - The timestamp of the request. - **Type** (string) - Required - The type of SMS service. - **Version** (string) - Required - The API version. - **PhoneNumberSet** (array of string) - Required - A list of phone numbers to send the SMS to. - **SessionContext** (string) - Required - The context of the SMS session, often containing the verification code and instructions. - **Signature** (string) - Required - The generated signature for the request. - **Tag** (string) - Optional - A tag for the request. - **TaskTime** (string) - Optional - The scheduled time for the task. ### Request Example ```json { "AppId":"1001xxx", "MchId":"1xxx9", "SignType":"MD5", "SignName":"【联麓】", "TimeStamp":"1694157097", "Type":"1", "Version":"1.2.0", "PhoneNumberSet":["13***601"], "SessionContext":"您的短信验证码:123456,请在10分钟内输入。", "Signature":"666849EC085DEC88C096B2943B8A0AC1", "Tag":"123", "TaskTime":"" } ``` ### Response #### Success Response (200) Details of the success response are not provided in the documentation. #### Response Example (No example provided) ``` -------------------------------- ### JavaScript MD5 Signature Generation with Parameter Sorting Source: https://www.shlianlu.com/console/document/Signature This JavaScript snippet generates an MD5 signature for API requests. It sorts request parameters alphabetically, filters out specific keys, concatenates them with a secret key, and then computes the MD5 hash using CryptoJS. The resulting signature is added to the parameters object. It depends on the CryptoJS library. ```javascript // 替换为真实的AppKey const appKey = "3b8ee580a83549248e**"; // 请求参数排序,过滤参数 const sortedParams = Object.keys(params).sort().reduce((result, key) => { if (!["PhoneNumberSet", "SessionContext", "SessionContextSet", "ContextParamSet", "TemplateParamSet", "Signature", "PhoneList", "phoneSet"].includes(key)) { result[key] = params[key]; } return result; }, {}); // 将参数按顺序拼接,最后拼接上appkey const stringToSign = Object.entries(sortedParams).map(([key, value]) => `${key}=${value}`).join("&") + `&key=${appKey}`; // 拼接字符串MD5加密后大写 const signature = CryptoJS.MD5(stringToSign).toString().toUpperCase(); params.Signature = signature; ```