1、域名配置
postman发送请求 http://sky.bi.test.litb.com/config/api/validation/client/validation-result?tester=zhangsan&testTimeStart=2021-11-12
/config/api/在nginx配置中指向某一个appkey,所以请求该域名的子路径的请求会打到对应的服务器上。
BA配置如下:
//设置id和secrent var client_secret='eb83092f9b8a5d5da84bdf1003f00ab8'; var client_id = 'eco' //获取http时间 var timespan = new Date().toUTCString(); //通过request.data获取body的内容,这个是postman内置变量 var method = request.method; var uri = pm.request.url.getPath(); string_to_sign = method + " " + uri + "\n" + timespan; console.log(string_to_sign); //使用CryptoJS,postman的内置js库加密 var hash = CryptoJS.HmacSHA1(string_to_sign, client_secret); console.log(hash); var signature = CryptoJS.enc.Base64.stringify(hash); console.log(signature); var Authorization = "MWS" + " " + client_id + ":" + signature; console.log(Authorization); //设置环境变量 postman.setEnvironmentVariable("Authorization", Authorization.toString()); postman.setEnvironmentVariable("Date", timespan);
Pre-req脚本中语句var uri = pm.request.url.getPath(); 获取到的值是/config/api/validation/client/validation-result(注意 1、开头带/ 2、不含问号及其后面的内容)
nginx的规则配置
matches: ^/config/api/(.*)$ target-pattern: /api/$1
意味着config会被丢弃掉,这个时候后端服务执行String serverInfo = SignatureUtil.getSignature(clientSecret, request.getMethod(), URLDecoder.decode(uri,"UTF-8"), requestDate); 校验计算之前,需要在uri之前增加"/config"。