|
@@ -0,0 +1,91 @@
|
|
|
+package com.ywt.alipaympapi.web.common;
|
|
|
+
|
|
|
+import com.ywt.alipaympapi.core.utils.JsonSerializer;
|
|
|
+import com.ywt.rpc.core.HttpUtil;
|
|
|
+import com.ywt.rpc.core.RestCaller;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author daiyihua
|
|
|
+ * @create 2020-09-07 下午05:27
|
|
|
+ * @desc 调用 rest api抽出来的公共方法
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class RestCallerApiProvider {
|
|
|
+
|
|
|
+ private Logger logger = LoggerFactory.getLogger(RestCallerApiProvider.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestCaller restCaller;
|
|
|
+
|
|
|
+ private static String wapApiServiceName = "com.ywt.WapApiService";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用 post 方法
|
|
|
+ *
|
|
|
+ * @param serverName 服务名
|
|
|
+ * @param path 路径
|
|
|
+ * @param map 参数
|
|
|
+ * @return {@link HttpUtil.Resp}
|
|
|
+ * @throws IOException io异常
|
|
|
+ * @throws RestCaller.ParamterEmptyException 自定义异常
|
|
|
+ */
|
|
|
+ private HttpUtil.Resp postCommon(String serverName, String path, Map<String, Object> map) throws IOException, RestCaller.ParamterEmptyException {
|
|
|
+
|
|
|
+ Map<String, String> headers = new HashMap<>(16);
|
|
|
+ headers.put("Content-Type", "application/json;charset=UTF-8");
|
|
|
+
|
|
|
+
|
|
|
+ return restCaller.post(serverName, path, JsonSerializer.toJson(map), headers);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用 get 方法
|
|
|
+ *
|
|
|
+ * @param serverName 服务名
|
|
|
+ * @param path 路径
|
|
|
+ * @param map 参数
|
|
|
+ * @return {@link HttpUtil.Resp}
|
|
|
+ * @throws IOException io异常
|
|
|
+ * @throws RestCaller.ParamterEmptyException 自定义异常
|
|
|
+ */
|
|
|
+ private HttpUtil.Resp getCommon(String serverName, String path, Map<String, String> map) throws IOException, RestCaller.ParamterEmptyException {
|
|
|
+ return restCaller.get(serverName, path, map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * post 方法调用 rest wapapi
|
|
|
+ *
|
|
|
+ * @param path 接口路径
|
|
|
+ * @param map 传参
|
|
|
+ * @return {@link HttpUtil.Resp}
|
|
|
+ * @throws IOException io异常
|
|
|
+ * @throws RestCaller.ParamterEmptyException 自定义异常
|
|
|
+ */
|
|
|
+ public HttpUtil.Resp postWapApi(String path, Map<String, Object> map) throws IOException, RestCaller.ParamterEmptyException {
|
|
|
+ return postCommon(wapApiServiceName, path, map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * get 方法调用 rest wapapi
|
|
|
+ *
|
|
|
+ * @param path 接口路径
|
|
|
+ * @param map 传参
|
|
|
+ * @return {@link HttpUtil.Resp}
|
|
|
+ * @throws IOException io异常
|
|
|
+ * @throws RestCaller.ParamterEmptyException 自定义异常
|
|
|
+ */
|
|
|
+ public HttpUtil.Resp getWapApi(String path, Map<String, String> map) throws IOException, RestCaller.ParamterEmptyException {
|
|
|
+ return getCommon(wapApiServiceName, path, map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|