标签:val encoding public ext unit digest 代码 png get
通过md5加密签名得到 sign 值,前台接口信息头需要此参数
pom文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.hjh</groupId> <artifactId>JmeterSignUtilHjh</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>JmeterSignUtilHjh Maven Webapp</name> <!-- FIXME change it to the project‘s website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.75</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-all</artifactId> <version>1.7.1</version> <type>pom</type> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <!--<scope>provided</scope>--> </dependency> </dependencies> <build> <finalName>JmeterSignUtilHjh</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
新建一个java文件夹
工具类代码
package com.util; import org.apache.shiro.crypto.hash.Md5Hash; import java.util.*; public class JmeterSignUtilHjh { public static void main(String[] args) { Map< String, Object > signMap = new HashMap<>(); signMap.put("parameter1" , "str1"); signMap.put("parameter2" , "str2"); System.out.println("str:" + JmeterSignUtilHjh.getSignStr(signMap,"str3")); } public static String getSignStr(Map < String, Object > paramValues , String secret) { try { StringBuilder sb = new StringBuilder(); List< String > paramNames = new ArrayList<>(); paramNames.addAll(paramValues.keySet()); Collections.sort(paramNames); for (String paramName : paramNames) { sb.append(paramName).append(paramValues.get(paramName)); } sb.append(secret); return MD5Digest(sb.toString()); } catch (Exception e) { throw new RuntimeException("加密签名计算异常!" , e); } } /** * md5工具类 */ private static String MD5Digest(String src){ return new Md5Hash(src).toString(); } }
把jar包放到\apache-jmeter-5.2.1\lib\ext 里面,重启jmeter
import com.util.JmeterSignUtilHjh; Map signMap = new HashMap (); comp = vars.get("compname"); limit = vars.get("limit"); es=vars.get("es"); signMap.put("companyName" , comp); signMap.put("limit" , limit); signMap.put("useES" , es); //sign=SignUtils.getSignStr(signMap,null); sign=JmeterSignUtilHjh.getSignStr(signMap,"fe716cbb-a990-40d4-b7c7-7b9db338c6c8"); vars.put("sign",sign); System.out.println("companyName:" + comp); System.out.println("limit:" + limit); System.out.println("es:" + es); System.out.println("sign:" + sign);
标签:val encoding public ext unit digest 代码 png get
原文地址:https://www.cnblogs.com/hujinhua/p/14759826.html