微信的几个接口
This commit is contained in:
parent
7b41dd0bc4
commit
290576620d
|
|
@ -29,5 +29,23 @@ public class WxController {
|
|||
return Result.success(wxService.getOpenidByCode(code));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "前端入参appid等信息,获取openId", httpMethod = "POST")
|
||||
@PostMapping("/getOpenidByCodeAndId")
|
||||
@ResponseBody
|
||||
public Result<String> getOpenidByCodeAndAppId(@RequestParam(value = "code") String code,
|
||||
@RequestParam(value = "appId") String appId,
|
||||
@RequestParam(value = "secret") String secret){
|
||||
return Result.success(wxService.getOpenidByCode(code, appId, secret));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取用户信息", httpMethod = "POST")
|
||||
@PostMapping("/getWxInfo")
|
||||
@ResponseBody
|
||||
public Result<String> getWxInfo(@RequestParam(value = "openId") String openId,
|
||||
@RequestParam(value = "accessToken") String accessToken){
|
||||
return Result.success(wxService.getWxInfo(openId, accessToken));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,8 @@ public interface WxService {
|
|||
|
||||
String getOpenidByCode(String code);
|
||||
|
||||
String getOpenidByCode(String code, String appId, String secret);
|
||||
|
||||
String getWxInfo(String openId, String accessToken);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,4 +42,22 @@ public class WxServiceImpl implements WxService {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOpenidByCode(String code, String appId, String secret) {
|
||||
String url = "https://api.weixin.qq.com/sns/jscode2session?appid="+ appId + "&secret=" + secret + "&js_code=" + code + "&grant_type=authorization_code";
|
||||
log.info("调用微信获取openId,入参url:{}", url);
|
||||
String result = HttpUtils.sendGet(url);
|
||||
log.info("调用微信获取openId,响应内容:{}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWxInfo(String openId, String accessToken) {
|
||||
String url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + accessToken + "&openid=" + openId + "&lang=zh_CN";
|
||||
log.info("调用微信获取用户信息,入参url:{}", url);
|
||||
String result = HttpUtils.sendGet(url);
|
||||
log.info("调用微信获取用户信息,响应内容:{}", result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue