提交 3e1f5da6 authored 作者: liupengfei's avatar liupengfei

--no commit message

上级 44cc3035
......@@ -70,5 +70,27 @@ public class WeChatLoginWapController {
return CallBack.success(user);
}
@ApiOperation(value = "获取微信openid", notes = "获取微信openid")
@GetMapping("/query/openid" )
public CallBack<WeChartThirdReturn> queryOpenid(String code,HttpServletRequest request) throws Exception{
String appid="appid="+WeChatLoginWapConfig.APPID;
String secret="&secret="+WeChatLoginWapConfig.SECRET;
String code1="&code="+code;
String grant_type="&grant_type="+WeChatLoginWapConfig.GRANT_TYPE;
//调用微信接口获得openid和access_token
String param = appid + secret + code1 + grant_type;
String result=HttpsUtils.sendGet("https://api.weixin.qq.com/sns/oauth2/access_token", param);
JSONObject object = (JSONObject)JSON.parse(result);
//判断接口是否调用成功
if(object.containsKey("errcode")){
throw new BaseException(ResponseCodeEnum.EXCEPTION.getCode(),object.get("errcode").toString());
}
//唯一标识用户的 openId
String openId=object.get("openid").toString();
WeChartThirdReturn user=new WeChartThirdReturn();
user.setOpenid(openId);
return CallBack.success(user);
}
}
......@@ -10,10 +10,10 @@ package com.zrqx.third.wechatlogin.config;
*/
public class WeChatLoginWapConfig {
// appid 应用唯一标识
public final static String APPID = "wxdee4149de87badc3";
public final static String APPID = "wx09e8e76176a7b2fd";
//public final static String APPID = "wx7b8af63db794b9be";
//密钥AppSecret
public final static String SECRET = "60dd814ff6c3febc5414652b6560a3c1";
public final static String SECRET = "123456789ASDFGHJKLqwertyuiopZXCV";
//public final static String SECRET = "2d5b7993d880c5250b967893635824e4";
//固定值 填写 authorization_code
public final static String GRANT_TYPE = "authorization_code";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论