위 챗 공식 플랫폼 테스트 번호, 페이지 오픈 id 획득
웹 페이지 권한 부여 사용자 기본 정보 획득http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
1. 웹 페이지 인증 획득
scope=snsapi_base, openid 만 가 져 오고 침묵 으로 가 져 옵 니 다. 알림 이 없습니다.
기 존 웹 링크 는 oAuth 를 먼저 방문 하여 권한 을 수 여 받 은 후 원래 링크 로 이동 해 야 합 니 다.
원본 링크:http://111.222.333.444/app/test.action
수정 후:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf21ea8f5294dce18&redirect_uri=http://111.222.333.444/app/test.action&response_type=code&scope=snsapi_base&state=123#wechat_redirect
2. code 를 통 해 openid 를 교환 합 니 다.
페이지 에서 코드 가 져 오기: request. getParameter ("code");
// code openId
public static String getOpenId(String code){
if(StringUtil.isNotEmpty(code)){
String appid = "wxf21ea8f5294dce18";
String secret = "d4624c36b6795d1d99dcf0547af5444e";
String result = HttpUtil.doHttpsGet("https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appid+"&secret="+secret+"&code="+code+"&grant_type=authorization_code", null, "UTF-8", true);
if(StringUtil.isNotEmpty(result)){
JSONObject json = JSONObject.fromObject(result);
if(json.get("openid")!=null){
return json.get("openid").toString();
}
}
}
return "";
}
HttpUtil
자바 HttpClient 3 로 Https 의 Get 과 Post 요청 보 내기 (강화)
http://happyqing.iteye.com/blog/2266742
scope 매개 변수 가 잘못 되 었 거나 scope 권한 이 없 는 개발 자 는 먼저 공공 플랫폼 홈 페이지 의 개발 자 센터 페이지 에 권한 을 부여 하여 도 메 인 이름 을 되 돌려 야 합 니 다 (테스트 번호 관리 에서 도 가능 합 니 다) 웹 계 정 을 설정 해 야 합 니 다. 웹 페이지 권한 부여 사용자 기본 정보 획득 무제 한 수정
OAuth 2.0 웹 페이지 권한 부여
도 메 인 이름 이나 ip 설정
redirect_uri 매개 변수 가 잘못 설 정 된 도 메 인 이나 ip 는 80 포트 여야 합 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
위 챗 내 장 된 브 라 우 저 여 부 를 판단 합 니 다.자바 버 전 javascript 버 전...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.