支付宝登录

This commit is contained in:
Guoqs
2024-06-11 15:12:02 +08:00
parent 38a8cd884d
commit 2010fe2b18
8 changed files with 30 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alipay.easysdk.base.oauth.models.AlipaySystemOauthTokenResponse;
import com.alipay.easysdk.factory.Factory;
import com.aliyun.tea.TeaUnretryableException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -89,6 +90,8 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@@ -108,6 +111,7 @@ import java.util.stream.Collectors;
@SpringBootTest(classes = JsowellApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
public class SpringBootTestController {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -257,14 +261,18 @@ public class SpringBootTestController {
@Test
public void alipayLoginTest() {
String refreshToken = "";
String auth_code = "1741970ec0e7445fb2dd2712480dYX91";
String auth_code = "354109ecc25f4d9f943331578f56XD91";
try {
// AlipaySystemOauthTokenResponse alipaySystemOauthTokenResponse = Factory.Base.OAuth().refreshToken(refreshToken);
// System.out.println(JSON.toJSONString(alipaySystemOauthTokenResponse));
AlipaySystemOauthTokenResponse token = Factory.Base.OAuth().getToken(auth_code);
System.out.println(JSON.toJSONString(token));
} catch (Exception e) {
throw new RuntimeException(e);
if (e instanceof TeaUnretryableException) {
TeaUnretryableException exception = (TeaUnretryableException) e;
logger.error("TeaUnretryableException异常:{}", exception.getLastRequest());
}
logger.error("Exception", e);
}
}