Browse Source

会员通知消息BUG修复

anderx 1 year ago
parent
commit
6ba511bd31

+ 110 - 3
src/main/java/com/goafanti/common/utils/HttpUtils.java

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ParseException;
-import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
@@ -13,15 +12,122 @@ import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
 
-import java.io.IOException;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.io.*;
+import java.net.URL;
 import java.net.UnknownHostException;
 import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
 import java.util.Map;
 import java.util.Set;
 
 public class HttpUtils {
 
+	/**
+	 * 发送https请求
+	 *
+	 * @param url           url
+	 * @param requestMethod 请求方式
+	 * @param param         请求参数
+	 * @return 返回值
+	 */
+	public String sendHttpsRequest(String url, String requestMethod, Map<String,Object> param) {
+		StringBuilder result = new StringBuilder();
+		try {
+			SSLContext sc = SSLContext.getInstance("SSL");
+			sc.init(null, new TrustManager[]{
+					new X509TrustManager() {
+						@Override
+						public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+						}
+
+						@Override
+						public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+						}
+
+						@Override
+						public X509Certificate[] getAcceptedIssuers() {
+							return new X509Certificate[0];
+						}
+					}
+			}, new SecureRandom());
+			URL console = new URL(url);
+			HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
+			// GET/POST
+			conn.setRequestMethod(requestMethod);
+			conn.setRequestProperty("Content-Type", "application/json");
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			// 设置证书忽略相关操作
+			conn.setSSLSocketFactory(sc.getSocketFactory());
+			if (null != param) {
+				OutputStream outputStream = conn.getOutputStream();
+				// 注意编码格式
+				outputStream.write(JSON.toJSONString(param).getBytes(StandardCharsets.UTF_8));
+				outputStream.close();
+			}
+
+
+			conn.setHostnameVerifier((s, sslSession) -> true);
+			conn.connect();
+			InputStream is = conn.getInputStream();
+			BufferedReader br = new BufferedReader(new InputStreamReader(is,StandardCharsets.UTF_8));
+			String ret = "";
+			while ((ret = br.readLine()) != null) {
+				if (!ret.trim().isEmpty()) {
+					result.append(ret);
+				}
+			}
+			conn.disconnect();
+			br.close();
+		} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
+			e.printStackTrace();
+		}
+        return result.toString();
+	}
+
+	// http协议访问方法
+//	public String sendHttpRequest(String url, String requestMethod, String param) {
+//		StringBuilder result = new StringBuilder();
+//		try {
+//			URL console = new URL(url);
+//			HttpURLConnection conn = (HttpURLConnection) console.openConnection();
+//			// GET/POST
+//			conn.setRequestMethod(requestMethod);
+//			conn.setRequestProperty("Content-Type", "application/json");
+//			conn.setDoOutput(true);
+//			conn.setDoInput(true);
+//			if (null != param) {
+//				OutputStream outputStream = conn.getOutputStream();
+//				// 注意编码格式
+//				outputStream.write(param.getBytes("UTF-8"));
+//				outputStream.close();
+//			}
+//
+//			conn.connect();
+//			InputStream is = conn.getInputStream();
+//			BufferedReader br = new BufferedReader(new InputStreamReader(is));
+//			String ret = "";
+//			while ((ret = br.readLine()) != null) {
+//				if (ret != null && !ret.trim().equals("")) {
+//					result.append(new String(ret.getBytes("utf-8"), "utf-8"));
+//				}
+//			}
+//			conn.disconnect();
+//			br.close();
+//		} catch (IOException ioException) {
+//			ioException.printStackTrace();
+//		}
+//		return result.toString();
+//	}
+
 
 
 	 public static JSONObject httpGet(String url) {
@@ -102,4 +208,5 @@ public class HttpUtils {
 	}
 
 
+
 }

+ 27 - 0
src/main/java/com/goafanti/customer/controller/UserOutboundApiController.java

@@ -0,0 +1,27 @@
+package com.goafanti.customer.controller;
+
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.customer.service.UserOutboundService;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+
+@RestController
+@RequestMapping("/api/admin/userOutbound")
+public class UserOutboundApiController  extends BaseApiController {
+
+    @Resource
+    private UserOutboundService userOutboundService;
+    /**
+     * 客户外呼查询
+     *
+     */
+    @PostMapping("/checkUser")
+    public Result checkUser(Integer type) {
+        return new Result<>().data(this.userOutboundService.checkUser(type));
+    }
+}

+ 5 - 0
src/main/java/com/goafanti/customer/service/UserOutboundService.java

@@ -0,0 +1,5 @@
+package com.goafanti.customer.service;
+
+public interface UserOutboundService {
+    Object checkUser(Integer type);
+}

+ 44 - 0
src/main/java/com/goafanti/customer/service/impl/UserOutboundServiceImpl.java

@@ -0,0 +1,44 @@
+package com.goafanti.customer.service.impl;
+
+import com.goafanti.common.dao.UserArchivesMapper;
+import com.goafanti.common.utils.HttpUtils;
+import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.customer.service.UserOutboundService;
+import org.apache.shiro.crypto.hash.SimpleHash;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Service("userOutboundService")
+public class UserOutboundServiceImpl extends BaseMybatisDao<UserArchivesMapper> implements UserOutboundService {
+    static final String customer="C322";
+    static final String seq="20241101";
+    static final String pwd="084332D02CCF7B42461F34155AC8754F";
+    static final String version= "2.0.6";
+    static final String default_url ="https://webmc.zb-sx.cn:1443";
+
+    @Override
+    public Object checkUser(Integer type) {
+        String url= default_url +"/openapi/"+version+"/getClientInfo";
+        Map<String,Object> param=new HashMap<>();
+        Map<String,Object> authentication=new HashMap<>();
+        authentication.put("customer","C322");
+        long timeMillis = System.currentTimeMillis();
+        authentication.put("timestamp",timeMillis);
+        authentication.put("seq",seq);
+        String digestSource=customer+"@"+timeMillis+"@"+seq+"@"+pwd;
+//        System.out.println("digestSource="+digestSource);
+        String md5 = new SimpleHash("MD5", digestSource).toHex();
+//        System.out.println("md5="+md5);
+        authentication.put("digest",md5);
+        param.put("authentication",authentication);
+        Map<String,Object> request=new HashMap<>();
+        request.put("type",type);
+        param.put("request",request);
+        HttpUtils httpUtils=new HttpUtils();
+        String s = httpUtils.sendHttpsRequest(url, "POST", param);
+        System.out.println(s);
+        return null;
+    }
+}