위 챗 공식 플랫폼 테스트 번호, 페이지 오픈 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 설정 微信公众平台测试号,页面获取openid_第1张图片 
redirect_uri 매개 변수 가 잘못 설 정 된 도 메 인 이나 ip 는 80 포트 여야 합 니 다.
 

좋은 웹페이지 즐겨찾기