mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
新增 代开发小程序 授权事件接收URL,验证票据接口
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package com.jsowell.service;
|
||||
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.wxplatform.AesException;
|
||||
import com.jsowell.common.util.wxplatform.WXBizMsgCrypt;
|
||||
import com.jsowell.common.util.wxplatform.WXXmlToMapUtil;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 代开发小程序Service
|
||||
*
|
||||
* @author Lemon
|
||||
* @Date 2023/7/27 15:58
|
||||
*/
|
||||
@Service
|
||||
public class AgentDevService {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* 第三方平台 appid
|
||||
*/
|
||||
private static final String PLATFORM_APP_ID = "****************";
|
||||
|
||||
/**
|
||||
* 第三方平台 secret
|
||||
*/
|
||||
private static final String PLATFORM_APP_SECRET = "****************";
|
||||
|
||||
/**
|
||||
* 第三方平台 消息加解密Key
|
||||
*/
|
||||
private static final String PLATFORM_AES_KEY = "****************";
|
||||
|
||||
/**
|
||||
* 第三方平台 消息校验Token
|
||||
*/
|
||||
private static final String PLATFORM_COMPONENT_TOKEN = "****************";
|
||||
|
||||
|
||||
/**
|
||||
* 解析请求
|
||||
*
|
||||
* @param timeStamp
|
||||
* @param nonce
|
||||
* @param msgSignature
|
||||
* @param postData
|
||||
* @return
|
||||
*/
|
||||
public String parseRequest(String timeStamp, String nonce, String msgSignature, String postData) {
|
||||
logger.debug("==============================开始授权事件接收URL=================================");
|
||||
try {
|
||||
//这个类是微信官网提供的解密类,需要用到消息校验Token 消息加密Key和服务平台appid
|
||||
WXBizMsgCrypt pc = new WXBizMsgCrypt(PLATFORM_COMPONENT_TOKEN, PLATFORM_AES_KEY, PLATFORM_APP_ID);
|
||||
String xml = pc.decryptMsg(msgSignature, timeStamp, nonce, postData);
|
||||
Map<String, String> result = WXXmlToMapUtil.xmlToMap(xml);// 将xml转为map
|
||||
String componentVerifyTicket = MapUtils.getString(result, "ComponentVerifyTicket");
|
||||
if (StringUtils.isNotEmpty(componentVerifyTicket)) {
|
||||
// 存入Redis 过期时间 12 小时
|
||||
String redisKey = CacheConstants.COMPONENT_VERIFY_TICKET;
|
||||
redisCache.setCacheObject(redisKey, componentVerifyTicket, 60 * 12, TimeUnit.SECONDS);
|
||||
String verifyTicket = redisCache.getCacheObject(redisKey);
|
||||
|
||||
// 存储平台授权票据,保存ticket
|
||||
// redisTemplate.opsForValue().set("component_verify_ticket", componentVerifyTicket, 60 * 12, TimeUnit.SECONDS);
|
||||
// String verifyTicket = redisTemplate.opsForValue().get("component_verify_ticket").toString();
|
||||
logger.debug("====================授权票据【ComponentVerifyTicket】:【" + verifyTicket + "】====================");
|
||||
} else {
|
||||
throw new RuntimeException("微信开放平台,第三方平台获取【验证票据】失败");
|
||||
}
|
||||
} catch (AesException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.debug("==============================结束授权事件接收URL=================================");
|
||||
return "success";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user