小程序
小游戏
企业微信
微信支付
扫描小程序码分享
是否又出问题了?? 目前我们的微信API 访问超时?
服务号“银数客户服务”
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你好,麻烦具体描述下问题流程,提供下appid,完整的请求,最近一次操作时间(特别说明,5小时内才有机会快速定位),收到的回复消息
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你好,麻烦具体描述下问题流程,提供下appid,完整的请求,最近一次操作时间(特别说明,5小时内才有机会快速定位),收到的回复消息
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
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;
}