|
@@ -31,6 +31,8 @@ public class YppApi {
|
|
|
@Autowired
|
|
|
RedisHelper redisHelper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ TokenApi tokenApi;
|
|
|
|
|
|
@Autowired
|
|
|
private ApiLogDao apiLogDao;
|
|
@@ -58,7 +60,7 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public OrderDetailResponse order_detail(String orderId) {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/order_detail?id=" + orderId);
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/order_detail?id=" + orderId);
|
|
|
|
|
|
OrderDetailResponse bean = JSONUtil.toBean(entries, OrderDetailResponse.class);
|
|
|
return bean;
|
|
@@ -72,10 +74,10 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject pay_order(String orderId) {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/pay_order?id=" + orderId + "&test=" + test);
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/pay_order?id=" + orderId + "&test=" + test);
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
- return JSONUtil.parseObj(entries,jsonConfig);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -86,7 +88,7 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject order_list(OrderListRequest orderListRequest) {
|
|
|
- JSONObject entries = httpPost("https://channel.youpiaopiao.cn/api/movie/list", orderListRequest);
|
|
|
+ JSONObject entries = tokenApi.httpPost("https://channel.youpiaopiao.cn/api/movie/list", orderListRequest);
|
|
|
return entries;
|
|
|
|
|
|
}
|
|
@@ -98,7 +100,7 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject get_order(String orderId) {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/get_order?id=" + orderId);
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/get_order?id=" + orderId);
|
|
|
return JSONUtil.parseObj(entries);
|
|
|
|
|
|
}
|
|
@@ -111,7 +113,7 @@ public class YppApi {
|
|
|
*/
|
|
|
public CreateOrdereResponse create_order(CreateOrdereRquest createOrdereRquest) {
|
|
|
createOrdereRquest.setAppId(appId);
|
|
|
- JSONObject entries = httpPost("https://channel.youpiaopiao.cn/api/movie/create_order", createOrdereRquest);
|
|
|
+ JSONObject entries = tokenApi.httpPost("https://channel.youpiaopiao.cn/api/movie/create_order", createOrdereRquest);
|
|
|
CreateOrdereResponse bean = JSONUtil.toBean(entries, CreateOrdereResponse.class);
|
|
|
return bean;
|
|
|
|
|
@@ -126,7 +128,7 @@ public class YppApi {
|
|
|
public CreateOrder2Response create_order2(CreateOrder2Request createOrder2Request) {
|
|
|
createOrder2Request.setAppId(appId);
|
|
|
createOrder2Request.setTest(test);
|
|
|
- JSONObject entries = httpPost("https://channel.youpiaopiao.cn/api/movie/create_order2", createOrder2Request);
|
|
|
+ JSONObject entries = tokenApi.httpPost("https://channel.youpiaopiao.cn/api/movie/create_order2", createOrder2Request);
|
|
|
return JSONUtil.toBean(entries, CreateOrder2Response.class);
|
|
|
|
|
|
}
|
|
@@ -144,7 +146,7 @@ public class YppApi {
|
|
|
builder.queryParam("cityId", cityId);
|
|
|
builder.queryParam("pageIndex", pageIndex);
|
|
|
builder.queryParam("pageSize", pageSize);
|
|
|
- String entries = httpGet(builder.build().toUriString());
|
|
|
+ String entries = tokenApi.httpGet(builder.build().toUriString());
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
return JSONUtil.parseObj(entries, jsonConfig);
|
|
@@ -158,10 +160,10 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject coming_movies(String cityId) {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/coming_movies?cityId=" + cityId);
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/coming_movies?cityId=" + cityId);
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
- return JSONUtil.parseObj(entries,jsonConfig);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -172,10 +174,10 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject movie_detail(String movieId) {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/movie_detail?movieId=" + movieId);
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/movie_detail?movieId=" + movieId);
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
- return JSONUtil.parseObj(entries,jsonConfig);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -195,10 +197,10 @@ public class YppApi {
|
|
|
builder.queryParam("lat", lat);
|
|
|
builder.queryParam("lng", lng);
|
|
|
|
|
|
- String entries = httpGet(builder.build().toUriString());
|
|
|
+ String entries = tokenApi.httpGet(builder.build().toUriString());
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
- return JSONUtil.parseObj(entries,jsonConfig);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -224,7 +226,7 @@ public class YppApi {
|
|
|
builder.queryParam("cityId", cityId);
|
|
|
builder.queryParam("lat", lat);
|
|
|
builder.queryParam("lng", lng);
|
|
|
- String entries = httpGet(builder.build().toUriString());
|
|
|
+ String entries = tokenApi.httpGet(builder.build().toUriString());
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
return JSONUtil.parseObj(entries, jsonConfig);
|
|
@@ -238,10 +240,10 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject cinema_filter(String cityId) {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/cinema_filter?cityId=" + cityId);
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/cinema_filter?cityId=" + cityId);
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
- return JSONUtil.parseObj(entries,jsonConfig);
|
|
|
+ return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -251,7 +253,7 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject get_citys() {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/get_citys");
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/get_citys");
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
return JSONUtil.parseObj(entries, jsonConfig);
|
|
@@ -271,7 +273,7 @@ public class YppApi {
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl);
|
|
|
builder.queryParam("movieId", movieId);
|
|
|
builder.queryParam("cinemaId", cinemaId);
|
|
|
- String entries = httpGet(builder.build().toUriString());
|
|
|
+ String entries = tokenApi.httpGet(builder.build().toUriString());
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
return JSONUtil.parseObj(entries, jsonConfig);
|
|
@@ -295,7 +297,7 @@ public class YppApi {
|
|
|
builder.queryParam("cinemaId", cinemaId);
|
|
|
builder.queryParam("movieId", movieId);
|
|
|
builder.queryParam("sid", sid);
|
|
|
- String entries = httpGet(builder.build().toUriString());
|
|
|
+ String entries = tokenApi.httpGet(builder.build().toUriString());
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
return JSONUtil.parseObj(entries, jsonConfig);
|
|
@@ -307,66 +309,11 @@ public class YppApi {
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject ad_configs() {
|
|
|
- String entries = httpGet("https://channel.youpiaopiao.cn/api/movie/ad_configs");
|
|
|
+ String entries = tokenApi.httpGet("https://channel.youpiaopiao.cn/api/movie/ad_configs");
|
|
|
JSONConfig jsonConfig = JSONConfig.create();
|
|
|
jsonConfig.setIgnoreError(true);
|
|
|
return JSONUtil.parseObj(entries, jsonConfig);
|
|
|
}
|
|
|
|
|
|
- private String httpGet(String url) {
|
|
|
- ApiLog apiLog = new ApiLog();
|
|
|
- apiLog.setRequest(url);
|
|
|
- apiLog.setSystem("movie");
|
|
|
- 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(), "飘飘响应错误");
|
|
|
- Assert.isTrue(code.equals(0), String.valueOf(entries.get("message")));
|
|
|
- return body;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private JSONObject httpPost(String url, Object body) {
|
|
|
-
|
|
|
- HttpRequest post = HttpUtil.createPost(url);
|
|
|
- if (!url.contains("api/oauth/token")) {
|
|
|
- String token = getoken();
|
|
|
- post.header("Authorization", token);
|
|
|
- }
|
|
|
-
|
|
|
- ApiLog apiLog = new ApiLog();
|
|
|
- apiLog.setRequest(url);
|
|
|
- apiLog.setSystem("movie");
|
|
|
- apiLog.setService(url);
|
|
|
- HttpResponse execute = post.body(JSONUtil.toJsonStr(body)).execute();
|
|
|
- String response = execute.body();
|
|
|
- apiLog.setRequest(JSONUtil.toJsonStr(body));
|
|
|
- apiLog.setResponse(response);
|
|
|
- apiLogDao.save(apiLog);
|
|
|
- JSONObject entries = JSONUtil.parseObj(response);
|
|
|
- Integer code = (Integer) entries.get("code");
|
|
|
- Assert.isTrue(code.equals(0), String.valueOf(entries.get("message")));
|
|
|
- return entries;
|
|
|
- }
|
|
|
-
|
|
|
- private String getoken() {
|
|
|
- Object value = redisHelper.getValue(tokenName);
|
|
|
- if (!ObjectUtil.isEmpty(value)) {
|
|
|
- return String.valueOf(value);
|
|
|
- }
|
|
|
- HashMap<String, String> para = new HashMap<>();
|
|
|
- para.put("entId", entId);
|
|
|
- para.put("appSecret", appSecret);
|
|
|
- JSONObject http = httpPost("https://channel.youpiaopiao.cn/api/oauth/token", para);
|
|
|
- String access_token = (String) http.getByPath("data.access_token");
|
|
|
- String token = tokenValue + access_token;
|
|
|
- redisHelper.cacheValue(tokenName, token, 82800);
|
|
|
- return token;
|
|
|
- }
|
|
|
|
|
|
}
|