当前位置:网站首页>Get the third-party interface
Get the third-party interface
2022-06-11 05:22:00 【Bug repair robot】
Get the third-party interface
1.HttpUtils Tool class
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.util.*;
public class HttpUtils {
public static String doPost(String url, Map<String,String> map, String charset){
CloseableHttpClient httpClient = null;
HttpPost httpPost = null;
String result = null;
try{
httpClient = HttpClients.createDefault();
httpPost = new HttpPost(url);
// Set parameters
List<NameValuePair> list = new ArrayList<NameValuePair>();
Iterator iterator = map.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry<String,String> elem = (Map.Entry<String, String>) iterator.next();
list.add(new BasicNameValuePair(elem.getKey(),elem.getValue()));
}
if(list.size() > 0){
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset);
httpPost.setEntity(entity);
}
HttpResponse response = httpClient.execute(httpPost);
if(response != null){
HttpEntity resEntity = response.getEntity();
if(resEntity != null){
result = EntityUtils.toString(resEntity,charset);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}
}2. Access interface
@Api(value = "/", tags = " Bill related interface ")
@Controller
@RequestMapping("/merchant")
public class MerchantController {
private static final Logger logger = LoggerFactory.getLogger(MerchantController.class);
@Value("${merchantUrl}")
private String merchantUrl;
@RequestMapping(value = "getDetail", method = RequestMethod.GET)
@ApiOperation(value = " For more details ")
@ResponseBody
public RtnInfo getDetail(@ApiParam(" bill id") @RequestParam(value = "id") String id) {
logger.info("getDetail ============================>begin");
logger.info("getDetail param: id=" + id);
RtnInfo rtnInfo = new RtnInfo();
Map<String, String> params = new HashMap<String, String>();
params.put("id", id);
String returnObj = HttpUtils.doPost(merchantUrl + "/logistics/free/getDetail", params, "utf-8");
if (StringUtils.isBlank(returnObj)) {
rtnInfo.setSystemCode(SystemCode.ERROR_5);
rtnInfo.setMsg(" Interface returns no data !");
return rtnInfo;
}
RtnInfo returnData = JSONObject.parseObject(returnObj, RtnInfo.class);
if (returnData.getCode().equals("0")) {
rtnInfo.setData(returnData.getData());
rtnInfo.setSystemCode(SystemCode.SUCCESS);
} else {
rtnInfo.setData(null);
rtnInfo.setSystemCode(SystemCode.ERROR_5);
rtnInfo.setMsg(returnData.getMsg());
}
logger.info("returnResult:" + rtnInfo.toString());
logger.info("getDetail ============================>end");
return rtnInfo;
}
}边栏推荐
- Analysis while experiment - a little optimization of memory leakage in kotlin
- JVM tuning V: JVM tuning tools and tuning practice
- oh my zsh正确安装姿势
- New product release: Lianrui launched a dual port 10 Gigabit bypass network card
- Recommend a free intranet penetration open source software that can be used in the local wechat official account under test
- Section II: structural composition characteristics of asphalt pavement (2) structural layer and performance requirements
- String sorting times --- bubble sorting deformation
- Dongmingzhu said that "Gree mobile phones are no worse than apple". Where is the confidence?
- MySQL nested sorting: first sort and filter the latest data, and then customize the sorting of this list
- Simple linear regression of sklearn series
猜你喜欢

Games101 job 7-path tracing implementation process & detailed interpretation of code

Analyzing while experimenting - memory leakage caused by non static inner classes

KD-Tree and LSH

Paper recommendation: relicv2, can the new self supervised learning surpass supervised learning on RESNET?

Topological sorting

Titanic rescued - re exploration of data mining (ideas + source code + results)

Network security construction in 5g Era

C (I) C basic grammar all in one

White Gaussian noise (WGN)

Combien de courant le câblage des PCB peut - il supporter?
随机推荐
Customize the layout of view Foundation
Analyzing while experimenting - memory leakage caused by non static inner classes
选择数字资产托管人时,要问的 6 个问题
Apply the intelligent OCR identification technology of Shenzhen Yanchang technology to break through the bottleneck of medical bill identification at one stroke. Efficient claim settlement is not a dr
Target detection - personal understanding of RCNN series
Restoration of binary tree -- number restoration
Opencv learning path (2-4) -- Deep parsing cvtcolor function
Share | defend against physically realizable image classification attacks
Simple linear regression of sklearn series
Combien de courant le câblage des PCB peut - il supporter?
JVM tuning V: JVM tuning tools and tuning practice
【入门级基础】Node基础知识总结
Paper reproduction: pare
Intercept file extension
Course design summary
lower_ Personal understanding of bound function
董明珠称“格力手机做得不比苹果差”哪里来的底气?
Click the icon is not sensitive how to adjust?
49. grouping of acronyms
Yolov5 training personal data set summary