|
|
@@ -5,9 +5,26 @@ import com.uas.sso.bihe.entity.OAuthRoot;
|
|
|
import com.uas.sso.bihe.service.BiHeService;
|
|
|
import com.uas.sso.common.util.HttpUtil;
|
|
|
import com.uas.sso.core.BHParam;
|
|
|
+import com.uas.sso.exception.VisibleError;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.client.HttpClient;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
|
+import javax.net.ssl.HostnameVerifier;
|
|
|
+import javax.net.ssl.HttpsURLConnection;
|
|
|
+import javax.net.ssl.SSLSession;
|
|
|
+import java.io.*;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
/**
|
|
|
* @author: huyy
|
|
|
* @date: 2018/7/18 11:26
|
|
|
@@ -19,20 +36,19 @@ public class BiHeServiceImpl implements BiHeService {
|
|
|
String url = "https://opengwtest.bgycc.com/open/oauth/token";
|
|
|
String appid = BHParam.DEFAULT_APPID;
|
|
|
String appSecret = BHParam.DEFAULT_APPSECRET;
|
|
|
- ModelMap data = new ModelMap();
|
|
|
- data.put("code", "XIH1G4");
|
|
|
- data.put("appId", appid);
|
|
|
- data.put("appSecret", appSecret);
|
|
|
-
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("code", "XIH1G4");
|
|
|
+ map.put("appSecret", "8a9d398c70f842309472a69bc730038d");
|
|
|
+ map.put("appId", "a9f624cbbdb947049f5638880b0ecbb2");
|
|
|
try {
|
|
|
- HttpUtil.ResponseWrap res = HttpUtil.doHttpsPost(url, data.toString(), 10000);
|
|
|
- if (res.getContent() != null) {
|
|
|
- System.out.println(res.getContent().toString());
|
|
|
- OAuthRoot oAuthRoot = JSON.parseObject(res.getContent().toString(), OAuthRoot.class);
|
|
|
- return oAuthRoot;
|
|
|
+ String content = com.uas.sso.util.HttpUtil.doPost(url, JSON.toJSONString(map));
|
|
|
+ OAuthRoot oAuthRoot = JSON.parseObject(content, OAuthRoot.class);
|
|
|
+ if (!OAuthRoot.Code.OK.getCode().equals(oAuthRoot.getCode())) {
|
|
|
+ throw new VisibleError(oAuthRoot.getMsg());
|
|
|
}
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
- System.out.println(e);
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|