|
@@ -7,11 +7,14 @@ import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONConfig;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.zswl.cloud.springBatch.client.model.request.CreateOrder2Request;
|
|
|
-import com.zswl.cloud.springBatch.client.model.request.CreateOrdereRquest;
|
|
|
+import com.zswl.cloud.springBatch.client.model.ypp.request.CreateOrder2Request;
|
|
|
+import com.zswl.cloud.springBatch.client.model.ypp.request.CreateOrdereRquest;
|
|
|
import com.zswl.cloud.springBatch.client.model.request.OrderListRequest;
|
|
|
-import com.zswl.cloud.springBtach.server.core.api.ypp.request.SessionRequest;
|
|
|
+import com.zswl.cloud.springBatch.client.model.ypp.response.CreateOrdereResponse;
|
|
|
+import com.zswl.cloud.springBatch.client.model.ypp.response.OrderDetailResponse;
|
|
|
+import com.zswl.cloud.springBatch.client.model.ypp.response.CreateOrder2Response;
|
|
|
+import com.zswl.cloud.springBtach.server.core.dao.ApiLogDao;
|
|
|
+import com.zswl.cloud.springBtach.server.core.domain.ApiLog;
|
|
|
import com.zswl.cloud.springBtach.server.core.helper.RedisHelper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -20,7 +23,6 @@ import org.springframework.util.Assert;
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
//接口地址 https://apifox.com/apidoc/shared-48c64918-c4ce-49f4-b846-d23855299d7a/doc-2590155
|
|
|
@Component
|
|
@@ -30,12 +32,21 @@ public class YppApi {
|
|
|
RedisHelper redisHelper;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ApiLogDao apiLogDao;
|
|
|
+
|
|
|
@Value("${ypp.entId}")
|
|
|
private String entId;
|
|
|
|
|
|
@Value("${ypp.appSecret}")
|
|
|
private String appSecret;
|
|
|
|
|
|
+ @Value("${ypp.appId}")
|
|
|
+ private String appId;
|
|
|
+ @Value("${ypp.test}")
|
|
|
+ private Boolean test;
|
|
|
+
|
|
|
+
|
|
|
private final String tokenName = "ypp-token";
|
|
|
private final String tokenValue = "Bearer ";
|
|
|
|
|
@@ -46,9 +57,11 @@ public class YppApi {
|
|
|
* @param orderId
|
|
|
* @return
|
|
|
*/
|
|
|
- public JSONObject order_detail(String orderId) {
|
|
|
+ public OrderDetailResponse order_detail(String orderId) {
|
|
|
String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/order_detail?id=" + orderId);
|
|
|
- return JSONUtil.parseObj(entries);
|
|
|
+
|
|
|
+ OrderDetailResponse bean = JSONUtil.toBean(entries, OrderDetailResponse.class);
|
|
|
+ return bean;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -59,8 +72,8 @@ public class YppApi {
|
|
|
* @param mobile
|
|
|
* @return
|
|
|
*/
|
|
|
- public JSONObject pay_order(String orderId, String mobile) {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/pay_order?id=" + orderId + "&test=&mobile=" + mobile);
|
|
|
+ public JSONObject pay_order(String orderId) {
|
|
|
+ String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/pay_order?id=" + orderId + "&test="+test);
|
|
|
return JSONUtil.parseObj(entries);
|
|
|
|
|
|
}
|
|
@@ -95,9 +108,10 @@ public class YppApi {
|
|
|
* @param createOrdereRquest
|
|
|
* @return
|
|
|
*/
|
|
|
- public JSONObject create_order(CreateOrdereRquest createOrdereRquest) {
|
|
|
+ public CreateOrdereResponse create_order(CreateOrdereRquest createOrdereRquest) {
|
|
|
JSONObject entries = httpPost("https://channel.youpiaopiao.cn/api/movie/create_order", createOrdereRquest);
|
|
|
- return entries;
|
|
|
+ CreateOrdereResponse bean = JSONUtil.toBean(entries, CreateOrdereResponse.class);
|
|
|
+ return bean;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -107,9 +121,10 @@ public class YppApi {
|
|
|
* @param createOrder2Request
|
|
|
* @return
|
|
|
*/
|
|
|
- public JSONObject create_order2(CreateOrder2Request createOrder2Request) {
|
|
|
+ public CreateOrder2Response create_order2(CreateOrder2Request createOrder2Request) {
|
|
|
+ createOrder2Request.setAppId(appId);
|
|
|
JSONObject entries = httpPost("https://channel.youpiaopiao.cn/api/movie/create_order2", createOrder2Request);
|
|
|
- return entries;
|
|
|
+ return JSONUtil.toBean(entries, CreateOrder2Response.class);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -127,7 +142,9 @@ public class YppApi {
|
|
|
builder.queryParam("pageIndex", pageIndex);
|
|
|
builder.queryParam("pageSize", pageSize);
|
|
|
String entries = httpGet(builder.build().toUriString());
|
|
|
- return JSONUtil.parseObj(entries);
|
|
|
+ JSONConfig jsonConfig = JSONConfig.create();
|
|
|
+ jsonConfig.setIgnoreError(true);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -243,10 +260,10 @@ public class YppApi {
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl);
|
|
|
builder.queryParam("movieId", movieId);
|
|
|
builder.queryParam("cinemaId", cinemaId);
|
|
|
-
|
|
|
-
|
|
|
String entries = httpGet(builder.build().toUriString());
|
|
|
- return JSONUtil.parseObj(entries);
|
|
|
+ JSONConfig jsonConfig = JSONConfig.create();
|
|
|
+ jsonConfig.setIgnoreError(true);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -268,7 +285,9 @@ public class YppApi {
|
|
|
builder.queryParam("movieId", movieId);
|
|
|
builder.queryParam("sid", sid);
|
|
|
String entries = httpGet(builder.build().toUriString());
|
|
|
- return JSONUtil.parseObj(entries);
|
|
|
+ JSONConfig jsonConfig = JSONConfig.create();
|
|
|
+ jsonConfig.setIgnoreError(true);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -284,10 +303,15 @@ public class YppApi {
|
|
|
}
|
|
|
|
|
|
private String httpGet(String url) {
|
|
|
+ ApiLog apiLog = new ApiLog();
|
|
|
+ apiLog.setRequest(url);
|
|
|
+ apiLog.setSystem("ypp");
|
|
|
String token = getoken();
|
|
|
HttpRequest get = HttpUtil.createGet(url);
|
|
|
HttpResponse execute = get.header("Authorization", token).execute();
|
|
|
String body = execute.body();
|
|
|
+ apiLog.setResponse(body);
|
|
|
+ apiLogDao.save(apiLog);
|
|
|
JSONObject entries = JSONUtil.parseObj(body);
|
|
|
Integer code = (Integer) entries.get("code");
|
|
|
Assert.isTrue(execute.isOk(), "飘飘响应错误");
|
|
@@ -307,7 +331,6 @@ public class YppApi {
|
|
|
String response = execute.body();
|
|
|
JSONObject entries = JSONUtil.parseObj(response);
|
|
|
Integer code = (Integer) entries.get("code");
|
|
|
- Assert.isTrue(execute.isOk(), "票票响应错误");
|
|
|
Assert.isTrue(code.equals(0), String.valueOf(entries.get("message")));
|
|
|
return entries;
|
|
|
}
|