日照智慧社区接口服务
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.
 
 
 
 
 

49 lines
1.7 KiB

package com.epmet.service.impl;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.dto.form.PaWxCodeFormDTO;
import com.epmet.dto.result.UserTokenResultDTO;
import com.epmet.service.PaUserLoginService;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 描述一下
*
* @author yinzuomei@elink-cn.com
* @date 2020/7/8 18:31
*/
@Service
public class PaUserLoginServiceImpl implements PaUserLoginService {
private static final Logger logger = LoggerFactory.getLogger(PaUserLoginServiceImpl.class);
@Autowired
private WxMpService wxMpService;
@Override
public UserTokenResultDTO loginByWxCode(PaWxCodeFormDTO formDTO) {
WxMpUser wxMpUser=this.getWxMpUser(formDTO.getWxCode());
return null;
}
private WxMpUser getWxMpUser(String wxCode) {
WxMpUser wxMpUser = null;
try {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(wxCode);
wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
} catch (WxErrorException e) {
logger.error("->[getWxMpUser]::error[{}]", "解析微信用户信息失败");
}
if (null == wxMpUser || StringUtils.isBlank(wxMpUser.getUnionId())) {
throw new RenException("解析微信用户信息失败");
}
return wxMpUser;
}
}