package com.thhy.usercore.modules.sys.login.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.thhy.general.common.BasicResult;
|
import com.thhy.general.common.entity.SysUserDto;
|
import com.thhy.usercore.modules.sys.login.entity.LoginVO;
|
import com.thhy.usercore.modules.sys.login.entity.MpLoginVo;
|
import com.thhy.usercore.modules.sys.login.service.LoginService;
|
import com.thhy.usercore.utils.HttpUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
@RestController
|
@RequestMapping("mpLogin")
|
public class MPController {
|
|
@Autowired
|
private LoginService loginService;
|
|
@PostMapping
|
public BasicResult login(@RequestBody SysUserDto sysUserDto){
|
MpLoginVo loginVO = loginService.mpLogin(sysUserDto);
|
return BasicResult.success(loginVO);
|
}
|
|
@Value("${wemp.appId}")
|
private String appId;
|
|
@Value("${wemp.secret}")
|
private String secret;
|
|
/**
|
* 获取OPENID
|
* @param jscode
|
* @return
|
*/
|
@RequestMapping(value = "getOpenId")
|
public BasicResult getOpenId(String jscode){
|
String result = HttpUtils.get("https://api.weixin.qq.com/sns/jscode2session?appid="+appId+"&secret="+secret+"&js_code="+jscode+"&grant_type=authorization_code");
|
JSONObject json = JSON.parseObject(result);
|
if(json.containsKey("errcode")){
|
return BasicResult.faild("9999",json.getString("errmsg"),null);
|
}
|
json.remove("session_key");
|
return BasicResult.success(json);
|
}
|
}
|