压测写法
Showing
3 changed files
with
76 additions
and
8 deletions
| ... | @@ -4,8 +4,10 @@ import com.example.mapper.ConfigInfoMapper; | ... | @@ -4,8 +4,10 @@ import com.example.mapper.ConfigInfoMapper; |
| 4 | import com.example.models.ConfigInfo; | 4 | import com.example.models.ConfigInfo; |
| 5 | import com.example.models.ScoreLogInfo; | 5 | import com.example.models.ScoreLogInfo; |
| 6 | import com.example.service.ScoreLogInfoService; | 6 | import com.example.service.ScoreLogInfoService; |
| 7 | import com.example.service.http.HttpPostService; | ||
| 7 | import com.example.support.model.MessageEntity; | 8 | import com.example.support.model.MessageEntity; |
| 8 | import com.example.utils.md5.MD5Utils; | 9 | import com.example.utils.md5.MD5Utils; |
| 10 | import com.example.utils.thread.TestThread; | ||
| 9 | import com.fasterxml.jackson.databind.ObjectMapper; | 11 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 10 | import org.apache.commons.lang3.StringUtils; | 12 | import org.apache.commons.lang3.StringUtils; |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | @@ -38,6 +40,10 @@ public class ScoreLogInfoController { | ... | @@ -38,6 +40,10 @@ public class ScoreLogInfoController { |
| 38 | @Autowired | 40 | @Autowired |
| 39 | private ConfigInfoMapper configInfoMapper; | 41 | private ConfigInfoMapper configInfoMapper; |
| 40 | 42 | ||
| 43 | @Autowired | ||
| 44 | HttpPostService httpPostService; | ||
| 45 | |||
| 46 | |||
| 41 | @RequestMapping("/save") | 47 | @RequestMapping("/save") |
| 42 | public MessageEntity save(HttpServletRequest request, @ModelAttribute ScoreLogInfo scoreLogInfo, | 48 | public MessageEntity save(HttpServletRequest request, @ModelAttribute ScoreLogInfo scoreLogInfo, |
| 43 | String access_token, String state, String timestamp, String rands, String jsondata, String checksum, String secret) { | 49 | String access_token, String state, String timestamp, String rands, String jsondata, String checksum, String secret) { |
| ... | @@ -101,20 +107,50 @@ public class ScoreLogInfoController { | ... | @@ -101,20 +107,50 @@ public class ScoreLogInfoController { |
| 101 | 107 | ||
| 102 | // public static void main(String[] args) { | 108 | // public static void main(String[] args) { |
| 103 | // String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; | 109 | // String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; |
| 104 | // String openid="oUmdXt90H2A784gfU7ChtsBsxU48"; | 110 | // String openid="111"; |
| 105 | // String state="xxxx"; | 111 | // String state="xxxx"; |
| 106 | // String timestamp="1511923072"; | 112 | // String timestamp="1511923072"; |
| 107 | // String rands="KeXxdzc7gQxkw6sE"; | 113 | // String rands="KeXxdzc7gQxkw6sE"; |
| 108 | // String jsondata="%7B%22gtmc_code%22%3A404%7D"; | 114 | // String jsondata=URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"); |
| 109 | // jsondata = URLDecoder.decode(jsondata); | ||
| 110 | // System.out.println(jsondata); | 115 | // System.out.println(jsondata); |
| 111 | // String checksum="5d179dbfdb49cafd3f27100df12d3b99"; | ||
| 112 | // String secret="digi-campaign-2015"; | 116 | // String secret="digi-campaign-2015"; |
| 113 | // System.out.println(URLEncoder.encode("{\"gtmc_code\":404,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}")); | ||
| 114 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); | 117 | // String checksum1 = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); |
| 115 | // System.out.println(checksum); | ||
| 116 | // System.out.println(checksum1); | 118 | // System.out.println(checksum1); |
| 117 | // } | 119 | // } |
| 118 | 120 | ||
| 121 | @RequestMapping("/test") | ||
| 122 | public MessageEntity test(HttpServletRequest request,@RequestParam String open) { | ||
| 123 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | ||
| 124 | for(int i = 0; i < 20;i++){ | ||
| 125 | String openid = open + i; | ||
| 126 | String access_token="4_ei8KYHlVKGE8zLguYGl7iHLEBf28u4nAzxocOMXGvzKoPxpU3Dxr_kq8cQlfDD34qFiJWgQpYxj3k3gobg0hyA"; | ||
| 127 | String state="xxxx"; | ||
| 128 | String timestamp="1511923072"; | ||
| 129 | String rands="KeXxdzc7gQxkw6sE"; | ||
| 130 | String jsondata="{\"gtmc_code\":200,\"gtmc_uid\":\"gtmc_uid\",\"gtmc_department\":\"gtmc_department\",\"gtmc_name\":\"gtmc_name\"}"; | ||
| 131 | jsondata = URLDecoder.decode(jsondata); | ||
| 132 | String secret="digi-campaign-2015"; | ||
| 133 | String checksum = MD5Utils.hash(access_token +openid +state +timestamp +rands +jsondata +secret); | ||
| 134 | jsondata = URLEncoder.encode(jsondata); | ||
| 135 | String url = "http://114.215.122.43:9922/kmr/rank/save"; | ||
| 136 | url = url + "?state="+state; | ||
| 137 | url = url + "&access_token="+access_token; | ||
| 138 | url = url + "&openid="+openid; | ||
| 139 | url = url + "×tamp="+timestamp; | ||
| 140 | url = url + "&rands="+rands; | ||
| 141 | url = url + "&jsondata="+jsondata; | ||
| 142 | url = url + "&secret="+secret; | ||
| 143 | url = url + "&checksum="+checksum; | ||
| 144 | url = url + "&nickname=xxxx"; | ||
| 145 | url = url + "&avater=xxxx"; | ||
| 146 | url = url + "&score=12"; | ||
| 147 | System.out.println(url); | ||
| 148 | TestThread ds1 = new TestThread(httpPostService,url); | ||
| 149 | Thread t1 = new Thread(ds1); | ||
| 150 | t1.start(); | ||
| 151 | } | ||
| 152 | return builder.success(true).code("2000").create(); | ||
| 153 | } | ||
| 154 | |||
| 119 | 155 | ||
| 120 | } | 156 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -53,12 +53,12 @@ public class WxController { | ... | @@ -53,12 +53,12 @@ public class WxController { |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | @RequestMapping("/getUser") | 55 | @RequestMapping("/getUser") |
| 56 | public MessageEntity oauth(HttpServletRequest request, @RequestParam String accessToken, String openid) { | 56 | public MessageEntity oauth(HttpServletRequest request, @RequestParam String access_token, String openid) { |
| 57 | MessageEntity.Builder builder = new MessageEntity.Builder(request); | 57 | MessageEntity.Builder builder = new MessageEntity.Builder(request); |
| 58 | ClientConfigService configService = new ClientConfigServiceImpl(); | 58 | ClientConfigService configService = new ClientConfigServiceImpl(); |
| 59 | RestClient restClient = new RestClient(configService.getClientConfig()); | 59 | RestClient restClient = new RestClient(configService.getClientConfig()); |
| 60 | Resource resource = restClient.resource("https://api.weixin.qq.com/sns/userinfo"); | 60 | Resource resource = restClient.resource("https://api.weixin.qq.com/sns/userinfo"); |
| 61 | resource.queryParam("access_token", accessToken); | 61 | resource.queryParam("access_token", access_token); |
| 62 | resource.queryParam("openid", openid); | 62 | resource.queryParam("openid", openid); |
| 63 | resource.queryParam("lang", "zh_CN"); | 63 | resource.queryParam("lang", "zh_CN"); |
| 64 | ClientResponse response = resource.get(); | 64 | ClientResponse response = resource.get(); | ... | ... |
| 1 | package com.example.utils.thread; | ||
| 2 | |||
| 3 | import com.example.service.http.HttpPostService; | ||
| 4 | |||
| 5 | import java.io.IOException; | ||
| 6 | import java.util.Map; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * Created by JA on 17/12/2. | ||
| 10 | */ | ||
| 11 | public class TestThread implements Runnable { | ||
| 12 | |||
| 13 | HttpPostService httpPostService; | ||
| 14 | String url = null; | ||
| 15 | |||
| 16 | public TestThread(HttpPostService h,String url){ | ||
| 17 | this.httpPostService = h; | ||
| 18 | this.url = url; | ||
| 19 | } | ||
| 20 | |||
| 21 | @Override | ||
| 22 | public void run() { | ||
| 23 | for(int i = 0;i < 30;i++){ | ||
| 24 | try { | ||
| 25 | Map<String, Object> map = this.httpPostService.httpPost(url, null); | ||
| 26 | System.out.println(map); | ||
| 27 | } catch (IOException e) { | ||
| 28 | e.printStackTrace(); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } |
-
Please register or sign in to post a comment