|
@ -2,14 +2,13 @@ package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
|
|
import com.epmet.constant.ModuleConstant; |
|
|
import com.epmet.constant.ModuleConstant; |
|
|
import com.epmet.constant.ThirdPlatformConstant; |
|
|
import com.epmet.constant.ThirdPlatformConstant; |
|
|
import com.epmet.dto.form.ThirdPlatformEventFormDTO; |
|
|
|
|
|
import com.epmet.dto.form.WeChatPlatformAuthCodeFormDTO; |
|
|
import com.epmet.dto.form.WeChatPlatformAuthCodeFormDTO; |
|
|
import com.epmet.exception.AesException; |
|
|
import com.epmet.exception.AesException; |
|
|
import com.epmet.redis.RedisThird; |
|
|
import com.epmet.redis.RedisThird; |
|
|
import com.epmet.service.ComponentVerifyTicketService; |
|
|
import com.epmet.service.ComponentVerifyTicketService; |
|
|
|
|
|
import com.epmet.util.OkHttpHelper; |
|
|
import com.epmet.util.WXBizMsgCrypt; |
|
|
import com.epmet.util.WXBizMsgCrypt; |
|
|
import com.epmet.util.WXXmlToMapUtil; |
|
|
import com.epmet.util.WXXmlToMapUtil; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -18,6 +17,7 @@ import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@ -33,6 +33,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private RedisThird redisThird; |
|
|
private RedisThird redisThird; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private OkHttpHelper okHttpHelper; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description 获得授权事件的票据 |
|
|
* @Description 获得授权事件的票据 |
|
@ -77,9 +79,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPSECRET, PLATFORM_APP_SECRET); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPSECRET, PLATFORM_APP_SECRET); |
|
|
jsonObject.put(ModuleConstant.TICKET_UNDERLINE_KEY, componentVerifyTicket); |
|
|
jsonObject.put(ModuleConstant.TICKET_UNDERLINE_KEY, componentVerifyTicket); |
|
|
// String post = OkHttpHelper.post(API_COMPONENT_TOKEN_URl, JSON.toJSONString(jsonObject));
|
|
|
// todo OkHttpHelper 无法引入
|
|
|
String post = null; |
|
|
String post = okHttpHelper.post(API_COMPONENT_TOKEN_URl, JSON.toJSONString(jsonObject)); |
|
|
log.info("====================返回post结果:" + post); |
|
|
|
|
|
HashMap<String, String> hashMap = JSON.parseObject(post, HashMap.class); |
|
|
HashMap<String, String> hashMap = JSON.parseObject(post, HashMap.class); |
|
|
String componentAccessToken = hashMap.get(ModuleConstant.COMPONENT_ACCESS_TOKEN); |
|
|
String componentAccessToken = hashMap.get(ModuleConstant.COMPONENT_ACCESS_TOKEN); |
|
|
if (StringUtils.isNotEmpty(componentAccessToken)) { |
|
|
if (StringUtils.isNotEmpty(componentAccessToken)) { |
|
@ -102,18 +103,15 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
public void preAuthCode() { |
|
|
public void preAuthCode() { |
|
|
log.info("====================开始执行定时任务获取预授权码【pre_auth_code】===================="); |
|
|
log.info("====================开始执行定时任务获取预授权码【pre_auth_code】===================="); |
|
|
try { |
|
|
try { |
|
|
// String accessToken = redisTemplate.opsForValue().get(ModuleConstant.COMPONENT_ACCESS_TOKEN).toString();
|
|
|
|
|
|
String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); |
|
|
String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); |
|
|
// String post = OkHttpHelper.post(API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject));
|
|
|
String post = okHttpHelper.post(API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)); |
|
|
String post = null; |
|
|
|
|
|
log.info("====================返回post结果:" + post); |
|
|
log.info("====================返回post结果:" + post); |
|
|
HashMap<String, String> hashMap = JSON.parseObject(post, HashMap.class); |
|
|
HashMap<String, String> hashMap = JSON.parseObject(post, HashMap.class); |
|
|
String authCode = hashMap.get("pre_auth_code"); |
|
|
String authCode = hashMap.get("pre_auth_code"); |
|
|
if (StringUtils.isNotEmpty(authCode)) { |
|
|
if (StringUtils.isNotEmpty(authCode)) { |
|
|
redisThird.setPreAuthCode(authCode); |
|
|
redisThird.setPreAuthCode(authCode); |
|
|
// redisTemplate.opsForValue().set("pre_auth_code", authCode, 60 * 10, TimeUnit.SECONDS);
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
throw new RuntimeException("微信开放平台,第三方平台获取【预授权码】失败"); |
|
|
throw new RuntimeException("微信开放平台,第三方平台获取【预授权码】失败"); |
|
|
} |
|
|
} |
|
@ -133,7 +131,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZATION_CODE, authCode); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZATION_CODE, authCode); |
|
|
// String post = OkHttpHelper.post(API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject));
|
|
|
try { |
|
|
|
|
|
String post = okHttpHelper.post(API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject)); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
// 重定向地址
|
|
|
// 重定向地址
|
|
|
// response.sendRedirect("/wechat/authcode");
|
|
|
// response.sendRedirect("/wechat/authcode");
|
|
|
} |
|
|
} |
|
|