package com.ltkj.web.tduck;
|
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.URLUtil;
|
import com.ltkj.tduck.utils.Result;
|
import lombok.AllArgsConstructor;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.security.PermitAll;
|
import javax.validation.constraints.NotBlank;
|
|
/**
|
* @author : smalljop
|
* @description : 微信公众号网页
|
* @create : 2020-12-02 13:40
|
**/
|
@AllArgsConstructor
|
@RestController
|
@RequestMapping("/wx/jsapi/")
|
public class WxJsApiController {
|
// private final WxMpService wxService;
|
|
|
/**
|
* 用户授权url
|
*
|
* @return hcah
|
*/
|
@GetMapping("/authorization/url")
|
@PermitAll
|
public Result getAuthorizationUrl(@RequestParam @NotBlank String url) {
|
String appId = "11111";
|
String authorizationUrl = StrUtil.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={}&redirect_uri={}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", appId, URLUtil.encode(url));
|
return Result.success(authorizationUrl);
|
}
|
|
|
/**
|
* 根据code获取用户信息
|
*
|
* @param code
|
* @return
|
*/
|
@GetMapping("/authorization/user/info")
|
@PermitAll
|
public Result greetUser(@RequestParam @NotBlank String code) {
|
// WxOAuth2UserInfo userInfo = null;
|
// try {
|
// WxOAuth2AccessToken accessToken = wxService.getOAuth2Service().getAccessToken(code);
|
// userInfo = wxService.getOAuth2Service().getUserInfo(accessToken, null);
|
// } catch (WxErrorException e) {
|
// return Result.success();
|
// }
|
// return Result.success(userInfo);
|
return Result.success();
|
}
|
|
|
/**
|
* 获取jsapi签名
|
*/
|
@GetMapping("/signature")
|
@PermitAll
|
public Result getSignature(@RequestParam String url) throws Exception {
|
// WxJsapiSignature signature = wxService.createJsapiSignature(url);
|
// return Result.success(signature);
|
return Result.success();
|
}
|
|
|
}
|