Commit c0bb5aa8 by 吕明尚

增加session到期后续期

parent ecae0bf3
......@@ -175,6 +175,7 @@ meituan:
signKey: abcdefghijklmnopqrstuvwxyz
appAuthToken: abcdefghijklmnopqrstuvwxyz
dianping:
appKey: abcdefghijklmnopqrstuvwxyz
appSecret: abcdefghijklmnopqrstuvwxyz
appKey: a59ea57cd1eb4737
appSecret: 0caaabb7fda1c1be46636171548dcf510d1fb706
authCode: abcdefghijklmnopqrstuvwxyz
openShoopUuid: 5067d2db1311d32a0ff366c79a73df51
......@@ -180,6 +180,7 @@ meituan:
signKey: abcdefghijklmnopqrstuvwxyz
appAuthToken: abcdefghijklmnopqrstuvwxyz
dianping:
appKey: abcdefghijklmnopqrstuvwxyz
appSecret: abcdefghijklmnopqrstuvwxyz
appKey: a59ea57cd1eb4737
appSecret: 0caaabb7fda1c1be46636171548dcf510d1fb706
authCode: abcdefghijklmnopqrstuvwxyz
openShoopUuid: 5067d2db1311d32a0ff366c79a73df51
package share.system.service.impl;
import com.dianping.openapi.sdk.api.oauth.CustomerRefreshToken;
import com.dianping.openapi.sdk.api.oauth.DynamicToken;
import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse;
import com.dianping.openapi.sdk.api.oauth.entity.DynamicTokenRequest;
import com.dianping.openapi.sdk.api.oauth.entity.DynamicTokenResponse;
import com.dianping.openapi.sdk.api.oauth.entity.RefreshTokenRequest;
import com.dianping.openapi.sdk.api.oauth.enums.GrantType;
import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptConsume;
import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptGetConsumed;
import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptPrepare;
import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptReverseConsume;
import com.dianping.openapi.sdk.api.tuangou.*;
import com.dianping.openapi.sdk.api.tuangou.entity.*;
import com.dianping.openapi.sdk.httpclient.DefaultOpenAPIClient;
import com.sun.deploy.services.PlatformType;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import share.common.enums.DataSourceType;
import share.common.enums.PlatformTypeEnum;
import share.common.enums.SourceTypeEnum;
import share.common.utils.uuid.UUID;
import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SCoupon;
......@@ -27,11 +24,6 @@ import share.system.domain.vo.FrontTokenComponent;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISCouponService;
import share.system.service.QPService;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Service
......@@ -40,8 +32,9 @@ public class QPServiceImpl implements QPService {
private String APP_KEY;
@Value("${dianping.appSecret}")
private String APP_SECRET;
@Value("${dianping.authCode}")
private String AUTH_CODE;
@Value("${dianping.openShoopUuid}")
private String OPEN_SHOP_UUID;
@Autowired
private ISCouponService isCouponService;
......@@ -117,7 +110,7 @@ public class QPServiceImpl implements QPService {
*/
@Override
public TuangouReceiptPrepareResponseEntity prepare(String code) {
TuangouReceiptPrepareRequest request = new TuangouReceiptPrepareRequest(APP_KEY, APP_SECRET, "session", code, "");
TuangouReceiptPrepareRequest request = new TuangouReceiptPrepareRequest(APP_KEY, APP_SECRET, "session", code, OPEN_SHOP_UUID);
TuangouReceiptPrepare tuangouReceiptPrepare = new TuangouReceiptPrepare(request);
DefaultOpenAPIClient client = new DefaultOpenAPIClient();
TuangouReceiptPrepareResponse invoke = client.invoke(tuangouReceiptPrepare);
......@@ -152,8 +145,8 @@ public class QPServiceImpl implements QPService {
@Override
public List<TuangouReceiptReverseConsumeResponseEntity> reverseconsume(String code, String appDealId) {
TuangouReceiptReverseConsumeRequest tuangouReceiptReverseConsumeRequest = new TuangouReceiptReverseConsumeRequest(APP_KEY, APP_SECRET, "session",
"app_deal_id", code, appDealId, "app_shop_account",
"app_shop_accountname", "open_shop_uuid");
appDealId, code, OPEN_SHOP_UUID,
"app_shop_account", "app_shop_accountname");
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptReverseConsume tuangouReceiptReverseConsume = new TuangouReceiptReverseConsume(tuangouReceiptReverseConsumeRequest);
TuangouReceiptReverseConsumeResponse response = openAPIClient.invoke(tuangouReceiptReverseConsume);
......@@ -171,7 +164,7 @@ public class QPServiceImpl implements QPService {
public TuangouReceiptGetConsumedReponseEntity getconsumed(String code) {
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptGetConsumedRequest request = new TuangouReceiptGetConsumedRequest(APP_KEY, APP_SECRET,
"7bd6cc83aecf6fe937d4cd774e1682aeb87773ad", code, "app_shop_id");
"7bd6cc83aecf6fe937d4cd774e1682aeb87773ad", code, OPEN_SHOP_UUID);
TuangouReceiptGetConsumed tuangouReceiptGetConsumed = new TuangouReceiptGetConsumed(request);
TuangouReceiptGetConsumedReponse response = openAPIClient.invoke(tuangouReceiptGetConsumed);
if (response.getCode() != 200) {
......@@ -181,13 +174,41 @@ public class QPServiceImpl implements QPService {
}
//商家通过接入授权UI,可获取到对应的auth_code,通过此接口获取此次发起授权的session。
public DynamicTokenResponse oauthToken() {
public String oauthToken(String authCode) {
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
DynamicTokenRequest request = new DynamicTokenRequest(APP_KEY,
APP_SECRET, GrantType.AUTHORIZATION_CODE.getValue(),
AUTH_CODE);
APP_SECRET, GrantType.AUTHORIZATION_CODE.getValue(), authCode);
DynamicToken dynamicToken = new DynamicToken(request);
DynamicTokenResponse response = openAPIClient.invoke(dynamicToken);
return response;
if (response.getRemain_refresh_count() == 0) {
return refreshToken(response.getRefresh_token());
}
return response.getAccess_token();
}
//获取团购信息接口
public List<TuangouDealQueryShopDealResponseEntity> queryshopdeal() {
/**
* @param app_key
* @param app_secret
* @param session
* @param app_shop_id
*/
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouDealQueryShopDealRequest request = new TuangouDealQueryShopDealRequest(APP_KEY, APP_SECRET, "session", OPEN_SHOP_UUID, 1, 100);
TuangouDealQueryShopDeal tuangouDealQueryShopDeal = new TuangouDealQueryShopDeal(request);
TuangouDealQueryShopDealResponse response = openAPIClient.invoke(tuangouDealQueryShopDeal);
if (response.getCode() != 200) {
throw new RuntimeException(response.getMsg());
}
return response.getData();
}
public String refreshToken(String newToken) {
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
RefreshTokenRequest request = new RefreshTokenRequest(APP_KEY, APP_SECRET, newToken);
CustomerRefreshToken refreshToken = new CustomerRefreshToken(request);
CustomerRefreshTokenResponse response = openAPIClient.invoke(refreshToken);
return response.getAccess_token();
}
}
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