| | |
| | | package com.ruoyi.auth.service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A; |
| | | import com.ruoyi.auth.config.QywxInnerConfig; |
| | | import com.ruoyi.auth.utils.RestUtils; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.model.AgentConfigVo; |
| | | import org.apache.commons.codec.binary.Hex; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.cache.RedisCache; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.Calendar; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Service |
| | |
| | | } |
| | | logger.info("----------------userinfo detail -------------"); |
| | | logger.info(detailResponse.toString()); |
| | | |
| | | return detailResponse; |
| | | } |
| | | |
| | | |
| | | |
| | | public AgentConfigVo getAgentConfig(String url) { |
| | | public AgentConfigVo getAgentConfig(String url, String type) { |
| | | |
| | | AgentConfigVo agentConfigVo = new AgentConfigVo(); |
| | | agentConfigVo.setAgentid(qywxInnerConfig.getAgentId()); |
| | | agentConfigVo.setCorpid(qywxInnerConfig.getCorpId()); |
| | | |
| | | //临时票据 |
| | | String ticket = getJsApiTicket(); |
| | | String ticket = getJsApiTicket(type); |
| | | if (StringUtils.isEmpty(ticket)) { |
| | | throw new ServiceException("获取票据异常"); |
| | | } |
| | |
| | | try { |
| | | String unEncryptStr = String.format(unEncryptStrBase, ticket, nonceStr, timestamp, url); |
| | | |
| | | logger.info("----------------unEncryptStrBase-------------"); |
| | | logger.info(unEncryptStrBase); |
| | | logger.info("----------------unEncryptStr-------------"); |
| | | logger.info(unEncryptStr); |
| | | |
| | | MessageDigest digest = MessageDigest.getInstance("SHA-1"); |
| | | // 调用digest方法,进行加密操作 |
| | |
| | | * @paran type |
| | | * @return |
| | | */ |
| | | public String getJsApiTicket() { |
| | | public String getJsApiTicket(String type) { |
| | | String accessToken = getAccessToken(); |
| | | String ticket = redisTemplate.opsForValue().get(Constants.QY_WX_TICKET_KEY); |
| | | String ticketKey = Constants.QY_WX_TICKET_KEY; |
| | | |
| | | String jsapiTicketUrl = qywxInnerConfig.getJsapiTicketUrl(); |
| | | if("agent_config".equals(type)){ |
| | | ticketKey = ticketKey + type; |
| | | jsapiTicketUrl = qywxInnerConfig.getJsapiTicketAgentUrl(); |
| | | } |
| | | |
| | | String ticket = redisTemplate.opsForValue().get(ticketKey); |
| | | if(!StringUtils.isEmpty(ticket)){ |
| | | return ticket; |
| | | } |
| | | String url = String.format(qywxInnerConfig.getJsapiTicketAgentUrl(), accessToken); |
| | | |
| | | String url = String.format(jsapiTicketUrl, accessToken); |
| | | |
| | | JSONObject response = RestUtils.get(url); |
| | | if(response.containsKey(Constants.QY_WX_ERR_CODE) && response.getInteger(Constants.QY_WX_ERR_CODE) != 0){ |
| | |
| | | ticket = response.getString(Constants.QY_WX_TICKET); |
| | | Long expiresIn = response.getLong(Constants.QY_WX_EXPIRES_IN); |
| | | expiresIn = expiresIn - 100; |
| | | redisTemplate.opsForValue().set(Constants.QY_WX_TICKET_KEY, ticket, expiresIn, TimeUnit.SECONDS); |
| | | redisTemplate.opsForValue().set(ticketKey, ticket, expiresIn, TimeUnit.SECONDS); |
| | | |
| | | return ticket; |
| | | } |