c0a51c54 by ja

压测写法

1 parent ecb31759
......@@ -4,8 +4,10 @@ import com.example.mapper.ConfigInfoMapper;
import com.example.models.ConfigInfo;
import com.example.models.ScoreLogInfo;
import com.example.service.ScoreLogInfoService;
import com.example.service.http.HttpPostService;
import com.example.support.model.MessageEntity;
import com.example.utils.md5.MD5Utils;
import com.example.utils.thread.TestThread;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -38,6 +40,10 @@ public class ScoreLogInfoController {
@Autowired
private ConfigInfoMapper configInfoMapper;
@Autowired
HttpPostService httpPostService;
@RequestMapping("/save")
public MessageEntity save(HttpServletRequest request, @ModelAttribute ScoreLogInfo scoreLogInfo,
String access_token, String state, String timestamp, String rands, String jsondata, String checksum, String secret) {
......@@ -101,20 +107,50 @@ public class ScoreLogInfoController {
// public static void main(String[] args) {
// String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA";
// String openid="oUmdXt90H2A784gfU7ChtsBsxU48";
// String openid="111";
// String state="xxxx";
// String timestamp="1511923072";
// String rands="KeXxdzc7gQxkw6sE";
// String jsondata="%7B%22gtmc_code%22%3A404%7D";
// jsondata = URLDecoder.decode(jsondata);
// String jsondata=URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}");
// System.out.println(jsondata);
// String checksum="5d179dbfdb49cafd3f27100df12d3b99";
// String secret="digi-campaign-2015";
// System.out.println(URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"));
// String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret);
// System.out.println(checksum);
// System.out.println(checksum1);
// }
@RequestMapping("/test")
public MessageEntity test(HttpServletRequest request,@RequestParam String open) {
MessageEntity.Builder builder = new MessageEntity.Builder(request);
for(int i = 0; i < 20;i++){
String openid = open + i;
String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA";
String state="xxxx";
String timestamp="1511923072";
String rands="KeXxdzc7gQxkw6sE";
String jsondata="{\"gtmc_code\":200,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}";
jsondata = URLDecoder.decode(jsondata);
String secret="digi-campaign-2015";
String checksum = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret);
jsondata = URLEncoder.encode(jsondata);
String url = "http://114.215.122.43:9922/kmr/rank/save";
url = url + "?state="+state;
url = url + "&access_token="+access_token;
url = url + "&openid="+openid;
url = url + "&timestamp="+timestamp;
url = url + "&rands="+rands;
url = url + "&jsondata="+jsondata;
url = url + "&secret="+secret;
url = url + "&checksum="+checksum;
url = url + "&nickname=xxxx";
url = url + "&avater=xxxx";
url = url + "&score=12";
System.out.println(url);
TestThread ds1 = new TestThread(httpPostService,url);
Thread t1 = new Thread(ds1);
t1.start();
}
return builder.success(true).code("2000").create();
}
}
\ No newline at end of file
......
......@@ -53,12 +53,12 @@ public class WxController {
@RequestMapping("/getUser")
public MessageEntity oauth(HttpServletRequest request, @RequestParam String accessToken, String openid) {
public MessageEntity oauth(HttpServletRequest request, @RequestParam String access_token, String openid) {
MessageEntity.Builder builder = new MessageEntity.Builder(request);
ClientConfigService configService = new ClientConfigServiceImpl();
RestClient restClient = new RestClient(configService.getClientConfig());
Resource resource = restClient.resource("https://api.weixin.qq.com/sns/userinfo");
resource.queryParam("access_token", accessToken);
resource.queryParam("access_token", access_token);
resource.queryParam("openid", openid);
resource.queryParam("lang", "zh_CN");
ClientResponse response = resource.get();
......
package com.example.utils.thread;
import com.example.service.http.HttpPostService;
import java.io.IOException;
import java.util.Map;
/**
* Created by JA on 17/12/2.
*/
public class TestThread implements Runnable {
HttpPostService httpPostService;
String url = null;
public TestThread(HttpPostService h,String url){
this.httpPostService = h;
this.url = url;
}
@Override
public void run() {
for(int i = 0;i < 30;i++){
try {
Map<String, Object> map = this.httpPostService.httpPost(url, null);
System.out.println(map);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}