package com.ruoyi.web.controller.wechat;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.config.WechatConfig;
|
import com.ruoyi.common.utils.WechatUtils;
|
|
/**
|
* 微信接口Controller
|
*
|
* @author ruoyi
|
*/
|
@RestController
|
@RequestMapping("/wechat")
|
public class WechatController extends BaseController {
|
|
@Autowired
|
private WechatConfig wechatConfig;
|
|
/**
|
* 获取微信AccessToken
|
*/
|
@GetMapping("/accessToken")
|
public AjaxResult getAccessToken() {
|
try {
|
String accessToken = WechatUtils.getAccessToken(
|
wechatConfig.getAppId(),
|
wechatConfig.getAppSecret()
|
);
|
if (accessToken == null || accessToken.isEmpty()) {
|
return error("获取微信AccessToken失败");
|
}
|
return success(accessToken);
|
} catch (Exception e) {
|
return error("获取微信AccessToken异常:" + e.getMessage());
|
}
|
}
|
}
|