请帮忙看下,我们调用微信的API是否不规范?
请帮忙看下,我们调用微信的API是否不规范?我们的微信服务号“银数客户服务”,域名: https://znkf.cupdata.com 使用H5的方式与微信公众平台交互,前前后后,共断了9次,均是微信这边的接口调用无响应,连不上微信这边的服务(我们内部已经排查)。
这9次,其中第一次是2019年12月26日下午那一次,这一次就不说了,微信团队也发声明了,但是后面断了几次,时间不长,也就1小时左右,有的持续30分钟左右,微信这边也不给回复,请问是否我们代码写的不规范,微信方屏蔽我们的调用?以下将我们调用微信API的代码贴出来,麻烦帮忙看一下。
调用获取用户信息接口代码:
public CustomerVO getUserInfo(String code) {
WxConf conf = getWxConf();
if (!conf.openflag) {
CustomerVO retVo = new CustomerVO();
retVo.setOpenid(code);
return retVo;
}
Map<String,String> map = getOpenIdAndAccessToken(conf.appId, conf.appSecret, conf.tokenUrl, code);
String openId = map.get("openId");
String accessToken = map.get("accessToken");
String url =String.format(conf.userInfoUrl, accessToken, openId);
LOGGER.info("http call wxapi[getUserInfo]...");
String response = wxapiClient.httpCall(url, "GET", null); //httpsRequestToString(url, "GET", null);
LOGGER.info("http call wxapi[getUserInfo] response:{}", response);
JSONObject jsonObject = JSON.parseObject(response);
CustomerVO retVo=new CustomerVO();
retVo.setOpenid(openId);
retVo.setCountry(jsonObject.getString("country"));
retVo.setProvince(jsonObject.getString("province"));
retVo.setCity(jsonObject.getString("city"));
retVo.setSex(String.valueOf(jsonObject.getInteger("sex")));
retVo.setNickname(jsonObject.getString("country"));
retVo.setHeadimgurl(jsonObject.getString("headimgurl"));
retVo.setLanguage(jsonObject.getString("language"));
return retVo;
}
下面是http请求的方法源码:
[@Override](/user/Override)
public String httpCall(String url, String method, String body) {
return httpsRequestToString(url, method, body);
}
private static String httpsRequestToString(String path, String method, String body) {
if (path == null || method == null) {
return null;
}
String response = null;
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
HttpsURLConnection conn = null;
try {
TrustManager[] tm = { new JEEWeiXinX509TrustManager() };
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url = new URL(path);
conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(ssf);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod(method);
if (null != body) {
OutputStream outputStream = conn.getOutputStream();
outputStream.write(body.getBytes("UTF-8"));
outputStream.close();
}
inputStream = conn.getInputStream();
inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
StringBuffer buffer = new StringBuffer();
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
response = buffer.toString();
LOGGER.info("response:{}", response);
} catch (Exception e) {
e.printStackTrace();
LOGGER.info("httpsRequestToString Exception:{}", e.getMessage());
} finally {
if (conn != null) {
conn.disconnect();
}
try {
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
LOGGER.info("httpsRequestToString finally Exception:{}", e.getMessage());
}
}
return response;
}