|
@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
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.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; |
|
@ -17,6 +16,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 javax.servlet.http.HttpServletResponse; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
@ -50,7 +50,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
String xml = pc.decryptMsg(msgSignature, timeStamp, nonce, postData); |
|
|
String xml = pc.decryptMsg(msgSignature, timeStamp, nonce, postData); |
|
|
// 将xml转为map
|
|
|
// 将xml转为map
|
|
|
Map<String, String> result = WXXmlToMapUtil.xmlToMap(xml); |
|
|
Map<String, String> result = WXXmlToMapUtil.xmlToMap(xml); |
|
|
String componentVerifyTicket = MapUtils.getString(result,ModuleConstant.TICKET_KEY); |
|
|
String componentVerifyTicket = MapUtils.getString(result, ModuleConstant.TICKET_KEY); |
|
|
if (StringUtils.isNotEmpty(componentVerifyTicket)) { |
|
|
if (StringUtils.isNotEmpty(componentVerifyTicket)) { |
|
|
// 存储平台授权票据,保存ticket
|
|
|
// 存储平台授权票据,保存ticket
|
|
|
redisThird.setComponentVerifyTicket(componentVerifyTicket); |
|
|
redisThird.setComponentVerifyTicket(componentVerifyTicket); |
|
@ -79,7 +79,6 @@ 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); |
|
|
// todo OkHttpHelper 无法引入
|
|
|
|
|
|
String post = okHttpHelper.post(API_COMPONENT_TOKEN_URl, JSON.toJSONString(jsonObject)); |
|
|
String post = okHttpHelper.post(API_COMPONENT_TOKEN_URl, JSON.toJSONString(jsonObject)); |
|
|
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); |
|
@ -122,21 +121,41 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void weChatPlatformAuthCode(WeChatPlatformAuthCodeFormDTO formDTO) { |
|
|
public void weChatPlatformAuthCode(HttpServletResponse response, String authCode, String expiresIn) { |
|
|
String authCode = formDTO.getAuthCode(); |
|
|
|
|
|
Integer expiresIn = formDTO.getExpiresIn(); |
|
|
|
|
|
// 获取令牌【component_access_token】
|
|
|
// 获取令牌【component_access_token】
|
|
|
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); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZATION_CODE, authCode); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZATION_CODE, authCode); |
|
|
|
|
|
String post; |
|
|
try { |
|
|
try { |
|
|
String post = okHttpHelper.post(API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject)); |
|
|
post = okHttpHelper.post(API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject)); |
|
|
|
|
|
HashMap<String,Map> hashMap = JSON.parseObject(post, HashMap.class); |
|
|
|
|
|
Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO); |
|
|
|
|
|
String authorizerRefreshToken = map.get(ModuleConstant.AUTHORIZER_REFRESH_TOKEN).toString(); |
|
|
|
|
|
redisThird.setAuthorizerRefreshToken(authorizerRefreshToken); |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 重定向地址
|
|
|
// 重定向地址
|
|
|
// response.sendRedirect("/wechat/authcode");
|
|
|
// response.sendRedirect("/wechat/authcode");
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 获取/刷新接口调用令牌 |
|
|
|
|
|
* @param |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public void refreshToken(String authorizerAppId) { |
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
|
//todo 授权方appid从哪来,每个用户的刷新token
|
|
|
|
|
|
//授权方AppId
|
|
|
|
|
|
// jsonObject.put(ModuleConstant.AUTHORIZER_APPID,authorizerAppId);
|
|
|
|
|
|
//第三方平台AppId
|
|
|
|
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID,PLATFORM_APP_ID); |
|
|
|
|
|
jsonObject.put("",redisThird.getAuthorizerRefreshToken("")); |
|
|
|
|
|
} |
|
|
} |
|
|
} |