|
|
@@ -20,6 +20,7 @@ import com.tuoheng.miniprogram.param.WxSendMessageParam; |
|
|
|
import com.tuoheng.miniprogram.service.IWxService; |
|
|
|
import com.tuoheng.miniprogram.utils.CurrentUserUtil; |
|
|
|
import com.tuoheng.miniprogram.utils.GetOpenIdUtil; |
|
|
|
import com.tuoheng.miniprogram.vo.WxAuthorizeVo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
@@ -50,6 +51,32 @@ public class WxServiceImpl implements IWxService { |
|
|
|
|
|
|
|
private static long expiresTime; |
|
|
|
|
|
|
|
public JsonResult checkAuthorize(String code) { |
|
|
|
User user = CurrentUserUtil.getUserInfo(); |
|
|
|
String openidResult = GetOpenIdUtil.getopenid(code, CommonConfig.appId, CommonConfig.appSecret); |
|
|
|
if (null != JSONObject.parseObject(openidResult).getInteger("errcode") || StringUtils.isNotEmpty(JSONObject.parseObject(openidResult).getString("errmsg"))) { |
|
|
|
return JsonResult.error(JSONObject.parseObject(openidResult).getInteger("errcode").intValue(), JSONObject.parseObject(openidResult).getString("errmsg")); |
|
|
|
} |
|
|
|
String openid = JSONObject.parseObject(openidResult).getString("openid"); |
|
|
|
if (StringUtils.isEmpty(openid)) { |
|
|
|
log.error("获取openid失败:", openidResult); |
|
|
|
return JsonResult.error("获取openid失败"); |
|
|
|
} |
|
|
|
// 根据当前登录用户id和vx查询授权表是否存在一条授权数据 |
|
|
|
UserAuthorize beforeUserAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery() |
|
|
|
.eq(UserAuthorize::getUserId, user.getId()) |
|
|
|
.eq(UserAuthorize::getOpenId, openid) |
|
|
|
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode())); |
|
|
|
WxAuthorizeVo wxAuthorizeVo = new WxAuthorizeVo(); |
|
|
|
wxAuthorizeVo.setOpenId(openid); |
|
|
|
if (ObjectUtil.isNotEmpty(beforeUserAuthorize)) { |
|
|
|
wxAuthorizeVo.setIsAuthroize(true); |
|
|
|
} else { |
|
|
|
wxAuthorizeVo.setIsAuthroize(false); |
|
|
|
} |
|
|
|
return JsonResult.success(wxAuthorizeVo); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 根据code获取openId |