paypal支付刷新token,代码整理

This commit is contained in:
egan
2019-03-31 23:42:04 +08:00
parent a1b5a694ac
commit 45fb4b0489
7 changed files with 79 additions and 87 deletions

View File

@@ -4,14 +4,15 @@ import com.egzosn.pay.common.api.BasePayConfigStorage;
/**
* 贝宝支付配置存储
* @author egan
*
* email egzosn@gmail.com
* date 2018-4-8 22:11:42
* @author egan
* <p>
* email egzosn@gmail.com
* date 2018-4-8 22:11:42
*/
public class PayPalConfigStorage extends BasePayConfigStorage {
private volatile String clientID;
private String clientID;
@Override
public String getAppid() {
@@ -41,28 +42,25 @@ public class PayPalConfigStorage extends BasePayConfigStorage {
}
public void setClientSecret(String clientSecret) {
setKeyPrivate(clientSecret);
setKeyPrivate(clientSecret);
}
@Override
public boolean isAccessTokenExpired() {
if (getExpiresTime() == 0){
return true;
}
return (getExpiresTime() - System.currentTimeMillis() / 1000) <= 0;
}
/**
* 设置取消页面的url
*
* @param cancelUrl 取消页面的url
*/
public void setCancelUrl(String cancelUrl){
public void setCancelUrl(String cancelUrl) {
setNotifyUrl(cancelUrl);
}
/**
* 获取取消页面的url
*/
public String getCancelUrl(){
return getNotifyUrl();
public String getCancelUrl() {
return getNotifyUrl();
}
}

View File

@@ -83,7 +83,6 @@ public class PayPalPayService extends BasePayService<PayPalConfigStorage>{
}
if (payConfigStorage.isAccessTokenExpired()) {
if (null == payConfigStorage.getAccessToken()){
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Basic " + authorizationString(getPayConfigStorage().getAppid(), getPayConfigStorage().getKeyPrivate()));
header.put("Accept", "application/json");
@@ -91,12 +90,11 @@ public class PayPalPayService extends BasePayService<PayPalConfigStorage>{
try {
HttpStringEntity entity = new HttpStringEntity("grant_type=client_credentials", header);
JSONObject resp = getHttpRequestTemplate().postForObject(getReqUrl(PayPalTransactionType.AUTHORIZE), entity, JSONObject.class);
payConfigStorage.updateAccessToken(String.format("%s %s", resp.getString("token_type" ), resp.getString("access_token" )), resp.getLongValue("expires_in" ));
payConfigStorage.updateAccessToken(String.format("%s %s", resp.getString("token_type" ), resp.getString("access_token" )), resp.getIntValue("expires_in" ));
} catch (UnsupportedEncodingException e) {
throw new PayErrorException(new PayException("failure", e.getMessage()));
}
}
return payConfigStorage.getAccessToken();
}
} finally {