위챗 애플릿 로그인
3051 단어 위챗 애플릿
위챗 애플릿 위챗 로그인을 실현하는 전제에서 당신은 위챗 공중 플랫폼 애플릿 계정을 등록해야만 아래의 조작을 할 수 있습니다!(애플릿 로그인이 기업 위챗 로그인보다 간단할 것 같다)
말을 많이 하지 않고 코드를 말하다.
위챗 애플릿에서 로그인 시작
--------------------------------------------------------------------------------------------------------------------------
현재 로그인은 button 형식으로 Open-type='getUserInfo'bindgetuser info='doLogin'두 가지 중요한 속성을 부여합니다
doLogin :function(e){
console.log(e)
wx.login({
success: function(res){
console.log(res)
//
var code = res.code;
// session_key openID
wx.request({
url: 'http://localhost:8080/wxLogin?code='+code,
method:"post",
success: function (resule){
console.log(resule);
}
})
}
})
}
그리고 js에 가서 위챗 애플릿login 방법을 호출해서 백엔드 인터페이스에 접근합니다
----------------------------------------------java 백엔드 코드---------------------------------------------------------------------------------------------
@PostMapping("/wxLogin")
public IMoocJSONResult wxLogin(String code) {
String url = "https://api.weixin.qq.com/sns/jscode2session";
Map param = new HashMap<>();
param.put("appid", " id");
param.put("secret", " ");
param.put("js_code", code);
param.put("grant_type", "authorization_code");
String wxResult = this.doGet(url, param);
System.out.println(wxResult);
//wxResult openid session_key json
WXSessionModel model = JsonUtils.jsonToPojo(wxResult, WXSessionModel.class);
return IMoocJSONResult.ok(model);
}
public static String doGet(String url, Map param) {
// Httpclient
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
// uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
// http GET
HttpGet httpGet = new HttpGet(uri);
//
response = httpclient.execute(httpGet);
// 200
if (response.getStatusLine().getStatusCode() == 200) {
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
직접 cv, 이상은 위챗 애플릿이 로그인을 얻는 절차와 실현
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
유니앱, 위챗 애플릿에서 MQTT 사용 문제(1)MQTT.js는 JavaScript로 작성된 MQTT 프로토콜의 클라이언트 라이브러리로 Node에 사용할 수 있습니다.js와 브라우저.노드에서.js단은 전역 설치를 통해 명령행 연결을 사용할 수 있으며 MQTT...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.