You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.6 KiB
70 lines
2.6 KiB
package com.web.controller;
|
|
|
|
import com.hai.common.exception.ErrorCode;
|
|
import com.hai.common.exception.ErrorHelp;
|
|
import com.hai.common.exception.SysCode;
|
|
import com.hai.common.utils.*;
|
|
import com.hai.enum_type.LoginPlatform;
|
|
import com.hai.model.ResponseData;
|
|
import com.hai.service.HighUserService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
@Controller
|
|
@RequestMapping(value = "/wechat")
|
|
@Api(value = "微信授权")
|
|
public class WechatController {
|
|
|
|
@Resource
|
|
private HighUserService userService;
|
|
|
|
@RequestMapping(value = "/getH5AccessToken", method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "【H5】获取AccessToken")
|
|
public ResponseData getH5AccessToken(@RequestParam(value = "code", required = true) String code) {
|
|
try {
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("appid", "wxa075e8509802f826");
|
|
params.put("secret", "0e606fc1378d35e359fcf3f15570b2c5");
|
|
params.put("code", code);
|
|
params.put("grant_type", "authorization_code");
|
|
return ResponseMsgUtil.success(HttpsUtils.doGet("https://api.weixin.qq.com/sns/oauth2/access_token", params));
|
|
|
|
} catch (Exception e) {
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/loginBySilence", method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "【H5】根据手机号登录")
|
|
public ResponseData loginBySilence(@RequestParam(value = "phone", required = true) String phone ,
|
|
HttpServletRequest request, HttpServletResponse response) {
|
|
try {
|
|
|
|
// 客户端
|
|
LoginPlatform platform = LoginPlatform.getDataByType("H5");
|
|
if (platform == null) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端");
|
|
}
|
|
|
|
return ResponseMsgUtil.success(userService.loginAndRegister(platform, phone, null, new HashMap<>(), request, response));
|
|
|
|
} catch (Exception e) {
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
}
|
|
|