Commit e78bcefa by 吕明尚

更改Reds存储的数据格式

parent e2bb6b23
......@@ -18,7 +18,8 @@ public class RedisTask {
private ISConsumerCouponService isConsumerCouponService;
@Autowired
private QPService qpService;
RedisTemplate redisTemplate = new RedisTemplate();
@Autowired
private RedisTemplate redisTemplate;
public void AuToReceiptCode() {
//获取redis中所有以tuangou.receipt.prepare开头的key
......@@ -45,11 +46,13 @@ public class RedisTask {
public void AutomaticMtSessionKey() {
Boolean b = redisTemplate.hasKey(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
if (!b) {
JSONObject o = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue());
JSONObject o = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String refreshToken = (String) o.get("refresh_token");
CustomerRefreshTokenResponse customerRefreshTokenResponse = qpService.refreshToken(refreshToken);
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), new JSONObject(customerRefreshTokenResponse));
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), new JSONObject(customerRefreshTokenResponse), customerRefreshTokenResponse.getExpires_in() - 60 * 30);
JSONObject jsonObject = new JSONObject(customerRefreshTokenResponse);
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), jsonObject.toString());
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), jsonObject.toString());
redisTemplate.expire(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), customerRefreshTokenResponse.getExpires_in() - 60 * 30, java.util.concurrent.TimeUnit.SECONDS);
}
}
}
......@@ -23,6 +23,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.stereotype.Service;
import share.common.enums.*;
import share.common.utils.DateUtils;
......@@ -52,9 +53,8 @@ public class QPServiceImpl implements QPService {
@Autowired
private ISConsumerCouponService isConsumerCouponService;
RedisTemplate redisTemplate = new RedisTemplate();
@Autowired
private RedisTemplate redisTemplate;
/**
* 用户验卷接口
*/
......@@ -172,7 +172,7 @@ public class QPServiceImpl implements QPService {
*/
@Override
public TuangouReceiptPrepareResponseEntity prepare(String code, String openShopUuid) {
JSONObject sessionKey = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String session = (String) sessionKey.get("access_token");
TuangouReceiptPrepareRequest request = new TuangouReceiptPrepareRequest(APP_KEY, APP_SECRET, session, code, "", openShopUuid);
TuangouReceiptPrepare tuangouReceiptPrepare = new TuangouReceiptPrepare(request);
......@@ -190,7 +190,7 @@ public class QPServiceImpl implements QPService {
*/
@Override
public List<TuangouReceiptConsumeResponseEntity> consume(String code, int count, String openShopUuid) {
JSONObject sessionKey = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String session = (String) sessionKey.get("access_token");
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
String requestid = UUID.randomUUID().toString();
......@@ -212,7 +212,7 @@ public class QPServiceImpl implements QPService {
*/
@Override
public List<TuangouReceiptReverseConsumeResponseEntity> reverseconsume(String code, Long appDealId, String openShopUuid) {
JSONObject sessionKey = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String session = (String) sessionKey.get("access_token");
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
TuangouReceiptReverseConsumeRequest tuangouReceiptReverseConsumeRequest = new TuangouReceiptReverseConsumeRequest(APP_KEY, APP_SECRET, session,
......@@ -233,7 +233,7 @@ public class QPServiceImpl implements QPService {
*/
@Override
public TuangouReceiptGetConsumedReponseEntity getconsumed(String code, String openShopUuid) {
JSONObject sessionKey = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String session = (String) sessionKey.get("access_token");
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptGetConsumedRequest request = new TuangouReceiptGetConsumedRequest(APP_KEY, APP_SECRET,
......@@ -253,8 +253,11 @@ public class QPServiceImpl implements QPService {
APP_SECRET, GrantType.AUTHORIZATION_CODE.getValue(), authCode);
DynamicToken dynamicToken = new DynamicToken(request);
DynamicTokenResponse response = openAPIClient.invoke(dynamicToken);
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), new JSONObject(response));
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), new JSONObject(response), response.getExpires_in() - 60 * 30);
//response转JSON
JSONObject jsonObject = new JSONObject(response);
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), jsonObject.toString());
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), jsonObject.toString());
redisTemplate.expire(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), response.getExpires_in() - 60 * 30, java.util.concurrent.TimeUnit.SECONDS);
return response.getAccess_token();
}
......@@ -267,7 +270,7 @@ public class QPServiceImpl implements QPService {
* @param app_shop_id
*/
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
JSONObject sessionKey = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String session = (String) sessionKey.get("access_token");
TuangouDealQueryShopDealRequest request = new TuangouDealQueryShopDealRequest(APP_KEY, APP_SECRET, session, "", 1, 100, openShopUuid);
TuangouDealQueryShopDeal tuangouDealQueryShopDeal = new TuangouDealQueryShopDeal(request);
......@@ -288,7 +291,7 @@ public class QPServiceImpl implements QPService {
@Override
public SessionVo queryKey() {
JSONObject o = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue());
JSONObject o = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue()));
Long expiresIn = (Long) o.get("expires_in");
Integer remainRefreshCount = (Integer) o.get("remain_refresh_count");
SessionVo sessionVo = new SessionVo();
......@@ -306,7 +309,7 @@ public class QPServiceImpl implements QPService {
@Override
public List<CustomerKeyShopScopeResponseEntity> scope() {
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
JSONObject sessionKey = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String session = (String) sessionKey.get("access_token");
String bid = (String) sessionKey.get("bid");
// CustomerKeyShopScopeRequest request = new CustomerKeyShopScopeRequest(APP_KEY, APP_SECRET, "13ff8a38219075fafbbdeea6839450ed6bea1b9b","f1fd23c1c413862137b895bdcfc10ef8");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment