app/공중번호/애플릿 위챗 로그인 후 왜 유니언을 유일한 표식으로

2224 단어 위챗 로그인
앱/공중번호/애플릿 위챗 로그인 후 왜 유니언을 유일한 표식으로 사용해야 하는지, 3단 위챗 오픈id가 일치하지 않아 위챗이 3단 로그인 후 3명의 사용자가 생성됩니다.삼단은 위챗 오픈 플랫폼에서 서로 연결된 후에 유일한 유닛이 생길 것이다.오픈 플랫폼에서 공중 플랫폼과 애플릿의 appid를 연결한 후에야 그게 유니언을 얻을 수 있음을 주의하십시오.
유니언을 구체적으로 얻은 코드는 붙이지 않겠습니다.백엔드에서 얻을 수도 있고, 백엔드에서 얻은 후에 백엔드에 전달할 수도 있다.위챗 공식 문서는 비교적 분명하게 말한다.내가 흰둥이를 막을 테니 여기도 코드를 붙여라.
public Map getOpenidByCode1( String code,Integer type) {
      initWxConfig(false);
      Map parmas = new HashMap();
      HttpClient client = new HttpClient();
      String resultStr = null;
      parmas.put("grant_type", "authorization_code");
      if (type == 1) {//     
         parmas.put("appid", APPID_X);
         parmas.put("secret", APPSECRET_X);
         parmas.put("js_code", code);
         resultStr = client.get("https://api.weixin.qq.com/sns/jscode2session", parmas);
      }
    if (type == 2) {//     
       parmas.put("appid", APPID_G);
       parmas.put("secret", APPSECRET_G);
       parmas.put("code", code);
       resultStr = client.get("https://api.weixin.qq.com/sns/oauth2/access_token", parmas);
    }
      JSONObject result = JSONObject.parseObject(resultStr);
      checkErr(result);
      Map body = new HashMap();
      String openid = result.getString("openid");
      String unionid = result.getString("unionid");
      body.put("openId", openid);
      body.put("unionid",unionid );
      System.out.println(unionid);
      return body;

   }

 
private void checkErr(JSONObject result) {
   if(result == null){
      return ;
   }
   String errcode = result.getString("errcode");
   if (StringUtils.isEmpty(errcode)) {
      return;
   }
   if ("0".equals(errcode)) {
      return;
   }

   if ("40014".equals(errcode) || "42001".equals(errcode) ) {
      /**/if (lock.tryLock()) {
         try {
            token();
         } finally {
            lock.unlock();
         }
      }
   }

   throw new BizException(Code.ERR_CODE);
}

좋은 웹페이지 즐겨찾기