收藏
回答

2020年1月10日早上9点40分 微信服务号接口又调用不通

是否又出问题了?? 目前我们的微信API 访问超时?


服务号“银数客户服务”


最后一次编辑于  01-10
回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员-娇华
    社区技术运营专员-娇华
    01-10

    你好,麻烦具体描述下问题流程,提供下appid,完整的请求,最近一次操作时间(特别说明,5小时内才有机会快速定位),收到的回复消息

    01-10
    赞同
    回复 1
    • JustRun
      JustRun
      02-21
      调用获取用户信息接口代码:
       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;
       }
      02-21
      回复
登录 后发表内容
问题标签