修复部分参数字段

This commit is contained in:
lulz1 2024-02-06 15:06:54 +08:00
parent 84f4d9d342
commit b4d8f012ca
27 changed files with 366 additions and 144 deletions

View File

@ -0,0 +1,9 @@
package com.chint.application.commands;
import com.chint.infrastructure.echo_framework.command.Command;
import static com.chint.infrastructure.constant.Constant.LEG_EVENT_NOT_ORDERED;
public class LegRejectCommand extends Command {
private Integer LegEventType = LEG_EVENT_NOT_ORDERED;
}

View File

@ -9,14 +9,12 @@ import static com.chint.infrastructure.constant.Constant.LEG_EVENT_NOT_ORDERED;
@Data
public class LegSyncCommand extends Command {
private Integer LegEventType = LEG_EVENT_NOT_ORDERED;
private Long LegId;
private Long routOrderId;
private SyncLegData data;
public LegSyncCommand legId(Long LegId) {
this.setLegId(LegId);
return this;
}
// public LegSyncCommand legId(Long LegId) {
// this.setLegId(LegId);
// return this;
// }
public LegSyncCommand data(SyncLegData data) {
this.data = data;

View File

@ -2,12 +2,16 @@ package com.chint.application.out;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.service.auth.AuthenticateService;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.domain.value_object.UserLoginResult;
import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Digest;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest;
import com.chint.interfaces.rest.ly.LYUserRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
@ -15,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.CompletableFuture;
import static com.chint.infrastructure.constant.Constant.*;
@RestController
@ -24,6 +30,12 @@ public class LoginController {
@Autowired
private AuthenticateService authenticateService;
@Autowired
private LYUserRequest lyUserRequest;
@Autowired
private CTripUserSaveRequest cTripUserSaveRequest;
@Transactional
@GetMapping("/login")
public Result<UserLoginResult> login(@RequestParam("sfno") String sfno,
@ -41,6 +53,21 @@ public class LoginController {
.authenticateEmployeeNo(userLoginParam);
//发送创建行程订单命令
Command.of(OrderCreateCommand.class).of(userLoginParam).sendToQueue();
//异步执行更新用户信息到同程
User currentUser = userLoginResult.getUser();
CompletableFuture.runAsync(() -> {
BaseContext.setCurrentUser(currentUser);
lyUserRequest.saveCurrentUser();
BaseContext.removeCurrentUser();
});
//异步执行更新用户信息到携程
CompletableFuture.runAsync(() -> {
BaseContext.setCurrentUser(currentUser);
cTripUserSaveRequest.saveUserToCTrip();
BaseContext.removeCurrentUser();
});
return Result.Success(SUCCESS, userLoginResult);
} else {
return Result.error(SIGN_ERROR);

View File

@ -3,7 +3,9 @@ package com.chint.application.out;
import com.chint.application.services.SupplierLoginService;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.dto.login.H5Response;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -18,6 +20,7 @@ public class SupplierLoginController {
@Autowired
private SupplierLoginService supplierLoginService;
@ApiOperation("单点登录同程")
@PostMapping("/ly/login")
public Result<LYRedirectUrlResponse> lyLogin() {
//登录
@ -25,9 +28,10 @@ public class SupplierLoginController {
return Result.Success(SUCCESS, data);
}
@ApiOperation("单点登录携程")
@PostMapping("/CTrip/login")
public Result<String> cTripLogin() {
return Result.Success(SUCCESS);
public Result<H5Response> cTripLogin() {
return Result.Success(SUCCESS, supplierLoginService.cTripLogin());
}
}

View File

@ -1,5 +1,7 @@
package com.chint.application.services;
import com.chint.interfaces.rest.ctrip.CTripLoginRequest;
import com.chint.interfaces.rest.ctrip.dto.login.H5Response;
import com.chint.interfaces.rest.ly.LYLoginRequest;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
import org.springframework.beans.factory.annotation.Autowired;
@ -13,10 +15,18 @@ public class SupplierLoginService {
@Autowired
private LYLoginRequest lyLoginRequest;
@Autowired
private CTripLoginRequest cTripLoginRequest;
/**
* 登录接口
*/
public LYRedirectUrlResponse lyLogin() {
return lyLoginRequest.login(L_Y_ENTRANCE_HOME);
}
public H5Response cTripLogin() {
return cTripLoginRequest.hSingleLogin();
}
}

View File

@ -13,10 +13,7 @@ import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import static com.chint.infrastructure.constant.Constant.*;
@ -75,22 +72,23 @@ public class Leg {
}
public Leg reloadStatus() {
if (eventList == null) {
if (eventList == null || eventList.isEmpty()) {
this.legStatus = LEG_STATUS_PREPARE;
} else {
int eventLength = eventList.size() - 1;
this.legStatus = eventLength < 0 ? LEG_STATUS_PREPARE : eventLength;
if (legStatus > 1) {
Optional<LegEvent> legEvent = this.eventList
.stream()
.filter(event -> event.getEventType().equals(LEG_EVENT_ORDERED))
.findFirst();
if (legEvent.isPresent()) {
LegEvent event = legEvent.get();
this.amount = event.getOrderDetail().getAmount();
}
// Find the latest event based on the maximum id
LegEvent latestEvent = this.eventList.stream()
.max(Comparator.comparingLong(LegEvent::getLegEventId))
.orElse(null);
// Set the legStatus based on the type of the latest event
this.legStatus = latestEvent.getEventType();
// If the latest event is an order event, update the amount
if (latestEvent.getEventType().equals(LEG_EVENT_ORDERED)) {
this.amount = latestEvent.getOrderDetail().getAmount();
}
}
this.legStatusName = translateLegStatus(this.legStatus);
if (legType != null) {
this.legTypeName = translateLegType(this.legType);
@ -98,6 +96,7 @@ public class Leg {
return this;
}
public Leg reloadStatus(LegData legData) {
this.reloadStatus();
if (Objects.equals(legData.getLegId(), this.getLegId()) && this.legStatus.equals(LEG_STATUS_PREPARE)) {
@ -118,6 +117,7 @@ public class Leg {
case LEG_STATUS_PAYED -> LEG_STATUS_PAYED_NAME;
case LEG_STATUS_FINISH -> LEG_STATUS_FINISH_NAME;
case LEG_STATUS_NOT_ORDERED -> LEG_STATUS_NOT_ORDERED_NAME;
case LEG_STATUS_REJECT -> LEG_STATUS_REJECT_NAME;
default -> "未知状态";
};
}
@ -151,11 +151,16 @@ public class Leg {
throw new LegEventException("The first event must be a prepare event.");
}
// 事件类型为负数代表是可以任何时机都可进行的事件
if(event.getEventType() < 0) {
eventList.add(event);
return this;
}
// 如果列表不为空确保新事件的类型是按顺序的
if (!eventList.isEmpty()) {
LegEvent lastEvent = eventList.get(eventList.size() - 1);
int lastEventType = lastEvent.getEventType();
if (newEventType != lastEventType + 1) {
throw new LegEventException("Events must be added in sequence.");
}

View File

@ -35,6 +35,8 @@ public class LegEvent {
case LEG_EVENT_PAYED -> LEG_EVENT_PAYED_NAME;
case LEG_EVENT_FINISH -> LEG_EVENT_FINISH_NAME;
case LEG_EVENT_NOT_ORDERED -> LEG_EVENT_NOT_ORDERED_NAME;
case LEG_EVENT_APPROVAL -> LEG_EVENT_APPROVAL_NAME;
case LEG_EVENT_REJECT -> LEG_EVENT_REJECT_NAME;
default -> "未知事件";
};
}

View File

@ -190,6 +190,7 @@ public class RouteOrder extends BaseEntity {
case ORDER_STATUS_PAYED -> ORDER_STATUS_PAYED_NAME;
case ORDER_STATUS_FINISH -> ORDER_STATUS_FINISH_NAME;
case ORDER_STATUS_NOT_ORDERED -> ORDER_STATUS_NOT_ORDERED_NAME;
case ORDER_STATUS_REJECT -> ORDER_STATUS_REJECT_NAME;
default -> "未知状态";
};
}

View File

@ -65,7 +65,7 @@ public class LYEstimate implements AmountEstimate {
TrainMaxPrice trainMaxPrice = new TrainMaxPrice();
trainMaxPrice.setTicketType(0);
trainMaxPrice.setDepartDate(leg.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//开始时间
trainMaxPrice.setDepartCityName(leg.getOriginLocationId().getLocationName());//出发城市
trainMaxPrice.setDepartCityName(leg.getOriginLocation().getLocationName());//出发城市
trainMaxPrice.setArriveCityName(leg.getDestinationLocation().getLocationName());//到达城市
Description<TrainMaxPrice> description = new Description<>();
description.setParam(trainMaxPrice);

View File

@ -16,4 +16,5 @@ public interface LegEventService {
void payForLeg(LegPayedCommand command);
//结束
void finishLeg(LegFinishedCommand command);
void rejectLeg(LegRejectCommand command);
}

View File

@ -2,6 +2,7 @@ package com.chint.domain.service.leg_event;
import com.chint.application.commands.*;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.exceptions.CommandException;
import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.RouteRepository;
@ -10,12 +11,13 @@ import com.chint.domain.value_object.ApproveLegData;
import com.chint.domain.value_object.OrderLegData;
import com.chint.domain.value_object.PayLegData;
import com.chint.domain.value_object.SyncLegData;
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.echo_framework.annotation.TransitionTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_APPROVAL;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
@Service
public class LegEventServiceImpl implements LegEventService {
@ -52,6 +54,8 @@ public class LegEventServiceImpl implements LegEventService {
public void approveLeg(LegApprovalCommand command) {
ApproveLegData data = command.getData();
RouteOrder routeOrder = routeRepository.findByFakeOrderNo(data.getFakeOrderNo());
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)){
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo());
approveOrderNo.setAccountCompany(data.getAccountCompany());
@ -63,6 +67,9 @@ public class LegEventServiceImpl implements LegEventService {
//保存routeOrder的状态
routeRepository.save(routeOrder);
} else {
throw new CommandException("订单未初始化");
}
}
//这里需要获取同步类价格routeOrder同步到供应商
@ -70,7 +77,8 @@ public class LegEventServiceImpl implements LegEventService {
@Override
public void syncLeg(LegSyncCommand command) {
SyncLegData data = command.getData();
RouteOrder routeOrder = routeRepository.queryById(command.getRoutOrderId());
RouteOrder routeOrder = routeRepository.queryById(data.getRouteId());
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_APPROVAL)) {
String supplierName = data.getSupplierName();
routeOrder.setSupplierName(supplierName);
//这里order所有的leg触发approve事件
@ -80,6 +88,9 @@ public class LegEventServiceImpl implements LegEventService {
syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus());
//保存routeOrder的状态
routeRepository.save(routeOrder);
} else {
throw new CommandException("订单未提交审批");
}
}
@ -121,4 +132,13 @@ public class LegEventServiceImpl implements LegEventService {
leg.addEvent(legEvent);
legRepository.save(leg);
}
@Override
@ListenTo(command = "LegRejectCommand", order = 0)
public void rejectLeg(LegRejectCommand command) {
// Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
// LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
// leg.addEvent(legEvent);
// legRepository.save(leg);
}
}

View File

@ -1,8 +1,14 @@
package com.chint.domain.service.order_sync;
import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.CityRepository;
import com.chint.domain.repository.LocationRepository;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ctrip.CTripApprovalRequest;
import com.chint.interfaces.rest.ctrip.dto.approval.ApprovalRequest;
import com.chint.interfaces.rest.ctrip.dto.approval.quick.RankInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -12,10 +18,21 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
@Autowired
private CityRepository cityRepository;
@Autowired
private CTripApprovalRequest approvalRequest;
@Autowired
private LocationRepository locationRepository;
@Override
public void syncSupplierOrder(RouteOrder order) {
System.out.println("开始同步协程订单");
// User currentUser = BaseContext.getCurrentUser();
// ApproveOrderNo approveOrderNo = order.getApproveOrderNo();
// new RankInfo()
// ApprovalRequest.buildApproval(currentUser.getEmployeeNo(), approveOrderNo.getActualOrderNo(), )
//
// approvalRequest.approval()
//
// System.out.println("开始同步协程订单");
}
}

View File

@ -4,5 +4,6 @@ import lombok.Data;
@Data
public class SyncLegData {
private Long routeId;
private String supplierName;
}

View File

@ -52,6 +52,8 @@ public class Constant {
public static final String ORDER_STATUS_PAYED_NAME = "已付款";
public static final int ORDER_STATUS_FINISH = 5;
public static final String ORDER_STATUS_FINISH_NAME = "已结束";
public static final int ORDER_STATUS_REJECT = -1;
public static final String ORDER_STATUS_REJECT_NAME = "审批拒绝";
// 规划节点状态
public static final int LEG_STATUS_PREPARE = 0;
@ -66,6 +68,8 @@ public class Constant {
public static final String LEG_STATUS_PAYED_NAME = "已付款";
public static final int LEG_STATUS_FINISH = 5;
public static final String LEG_STATUS_FINISH_NAME = "已结束";
public static final int LEG_STATUS_REJECT = -1;
public static final String LEG_STATUS_REJECT_NAME = "审批未通过";
// 规划节点运输方式
public static final int LEG_TYPE_TRAIN = 0;
@ -85,13 +89,15 @@ public class Constant {
public static final int LEG_EVENT_APPROVAL = 1;
public static final String LEG_EVENT_APPROVAL_NAME = "审批事件";
public static final int LEG_EVENT_NOT_ORDERED = 2;
public static final String LEG_EVENT_NOT_ORDERED_NAME = "审批事件";
public static final String LEG_EVENT_NOT_ORDERED_NAME = "同步事件";
public static final int LEG_EVENT_ORDERED = 3;
public static final String LEG_EVENT_ORDERED_NAME = "下单事件";
public static final int LEG_EVENT_PAYED = 4;
public static final String LEG_EVENT_PAYED_NAME = "付款事件";
public static final int LEG_EVENT_FINISH = 5;
public static final String LEG_EVENT_FINISH_NAME = "结束事件";
public static final int LEG_EVENT_REJECT = -1;
public static final String LEG_EVENT_REJECT_NAME = "拒绝事件";
// 金额
public static final String KEEP_TWO_DECIMAL_ZERO = "0.00";
@ -131,9 +137,11 @@ public class Constant {
public static final String TICKET_PATH = "/SwitchAPI/Order/Ticket";
public static final String C_TRIP_LOGIN_PATH = "/singlesignon/openapi/saml/login";
public static final String C_TRIP_ENTITY_ID = "/zhengtai";
public static final String C_TRIP_CORP_ID = "zhengtai";
public static final String C_TRIP_APP_KEY = "obk_zhengtai"; // 测试appkey
public static final String C_TRIP_APP_SECURITY = "gV417qxpou5bFlh2C93c452T"; // 测试app秘钥
public static final String C_TRIP_APP_ID = "zhengtai2024";
public static final String C_TRIP_CORP_ID = "zhengtai2024";
public static final String C_TRIP_APP_KEY = "obk_zhengtai2024"; // 测试appkey
public static final String C_TRIP_APP_SECURITY = "fI3}FZX+zUdxPa2W!R6I2gYO"; // 测试app秘钥
public static final String C_TRIP_H5_LOGIN = "/corpservice/authorize/getticket"; // 测试app秘钥
public static final String USER_SAVE_PATH = "/corpservice/CorpCustService/SaveCorpCustInfoList";
public static final String HOTEL_CITY_PATH = "/corpopenapi/HotelCity/GetCountryCityExtend";
public static final String HOTEL_COUNTRY_PATH = "/corpopenapi/HotelCity/GetCountry";
@ -163,15 +171,15 @@ public class Constant {
public static final String L_Y_ACCOUNT = "4f9cb1080b564dd0a94aa95f7a19c8b5"; // 测试appkey
public static final String L_Y_PASSWORD = "1fD3SutgzfS48qznYQiq"; // 测试app秘钥
public static final String L_Y_SECRET = "WOHzCMvHd823iHgH"; // 测试app秘钥
public static final Integer L_Y_PLAT_PC = 0; // 测试app秘钥
public static final Integer L_Y_PLAT_H5 = 1; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_HOME = 0; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_AIR_ORDER = 11; // 测试app秘钥page
public static final Integer L_Y_ENTRANCE_AIR_DETAIL = 1; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_AIR_ORDER_OVERSEA = 22; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_AIR_DETAIL_OVERSEA = 2; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_HOTEL_ORDER = 33; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_HOTEL_DETAIL = 3; // 测试app秘钥
public static final Integer L_Y_PLAT_PC = 0; //
public static final Integer L_Y_PLAT_H5 = 1; //
public static final Integer L_Y_ENTRANCE_HOME = 0; //
public static final Integer L_Y_ENTRANCE_AIR_ORDER = 11; //
public static final Integer L_Y_ENTRANCE_AIR_DETAIL = 1; //
public static final Integer L_Y_ENTRANCE_AIR_ORDER_OVERSEA = 22; //
public static final Integer L_Y_ENTRANCE_AIR_DETAIL_OVERSEA = 2; //
public static final Integer L_Y_ENTRANCE_HOTEL_ORDER = 33; //
public static final Integer L_Y_ENTRANCE_HOTEL_DETAIL = 3; //
public static final Integer L_Y_TRAVEL_TYPE_ALL = 0; // 全部(因公因私)
public static final Integer L_Y_TRAVEL_TYPE_PERSON = 1; // (因公)
public static final Integer L_Y_TRAVEL_TYPE_NO_PERSON = 2; // (因私)

View File

@ -16,9 +16,9 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String token = request.getHeader(HEADER_TOKEN);
if (request.getRequestURI().endsWith("/login")) {
return true;
}
// if (request.getRequestURI().endsWith("/login")) {
// return true;
// }
if (request.getRequestURI().contains("/pubilc")) {
return true;
}

View File

@ -55,6 +55,20 @@ public class PostRequest {
return gson.fromJson(responseBody, responseType);
}
public <T> T post(HttpPost post, Class<T> responseType) {
String responseBody = null;
HttpEntity responseEntity = null;
HttpResponse response = null;
try {
response = client.execute(post);
responseEntity = response.getEntity();
responseBody = EntityUtils.toString(responseEntity, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
return gson.fromJson(responseBody, responseType);
}
public Gson gson() {
return gson;
}

View File

@ -62,7 +62,7 @@ public class CTripEstimateRequest {
.done()
.valuationProductInfo()
.addFlightProductInfo(flightProductInfo)
// .addTrainProductInfo(trainProductInfo)
.addTrainProductInfo(trainProductInfo)
.done()
.done()
.build();

View File

@ -1,22 +1,19 @@
package com.chint.interfaces.rest.ctrip;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Digest;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.ctrip.dto.AuthenticationResponseList;
import com.chint.interfaces.rest.ctrip.dto.login.CTripAuthLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripHSingleLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripLoginParam;
import com.chint.interfaces.rest.ly.dto.LYBaseRequest;
import com.chint.interfaces.rest.ctrip.dto.login.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -24,6 +21,8 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@ -50,6 +49,7 @@ public class CTripLoginRequest {
//H5单点登录
private String singleLoginUrl = C_TRIP_BASE_URL + C_TRIP_SINGLE_LOGIN;
private String singleTokenUrl = C_TRIP_BASE_URL + C_TRIP_H5_LOGIN;
private String IDPEntityID = C_TRIP_ENTITY_ID;
private String corpId = C_TRIP_CORP_ID;
@ -103,9 +103,8 @@ public class CTripLoginRequest {
List entitys = new ArrayList<>();
entitys.add(new BasicNameValuePair("AppKey", appKey));
entitys.add(new BasicNameValuePair("Token", token));
entitys.add(new BasicNameValuePair("Ticket", ticket));
entitys.add(new BasicNameValuePair("EmployeeID",authLoginParam.getEmployeeID()));
entitys.add(new BasicNameValuePair("EmployeeID", employeeId));
entitys.add(new BasicNameValuePair("Signature", finallySign));
entitys.add(new BasicNameValuePair("ForCorp", "0"));
@ -123,11 +122,13 @@ public class CTripLoginRequest {
}
public HttpResponse hSingleLogin(CTripHSingleLoginParam hSingleLoginParam) {
String ticket = ticketRequest.loadTicket();
String token = tokenRequest.getToken();
public H5Response hSingleLogin() {
CTripHSingleLoginParam hSingleLoginParam = new CTripHSingleLoginParam();
User currentUser = BaseContext.getCurrentUser();
H5LoginToken h5TokenResponse = postRequest.post(singleTokenUrl, H5TicketModel.build(), H5LoginToken.class);
String token = h5TokenResponse.getToken();
String accessUserId = C_TRIP_APP_KEY;
String employeeId = StringUtils.isNotBlank(hSingleLoginParam.getEmployeeId())?hSingleLoginParam.getEmployeeId():"";
String employeeId = String.valueOf(currentUser.getEmployeeNo());
String corpPayType = StringUtils.isNotBlank(hSingleLoginParam.getCorpPayType()) ?
hSingleLoginParam.getCorpPayType() : "public";
@ -151,9 +152,11 @@ public class CTripLoginRequest {
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(costCenter3);
costCenter3 = StandardCharsets.UTF_8.decode(byteBuffer).toString();
}
String mdAppSecurity = Digest.md5(C_TRIP_APP_SECURITY);
String mdAppSecurity = getMD5Hash(C_TRIP_APP_SECURITY);
String signOrigin = accessUserId + employeeId + corpPayType + costCenter1 + costCenter2 + costCenter3 + mdAppSecurity;
System.out.println(signOrigin);
String finallySign =
Digest.md5(accessUserId+employeeId+corpPayType+costCenter1+costCenter2+costCenter3+mdAppSecurity);
getMD5Hash(signOrigin);
hSingleLoginParam.setSignature(finallySign);
@ -162,16 +165,21 @@ public class CTripLoginRequest {
entitys.add(new BasicNameValuePair("accessUserId", accessUserId));
entitys.add(new BasicNameValuePair("employeeId", employeeId));
entitys.add(new BasicNameValuePair("token", token));
entitys.add(new BasicNameValuePair("appId","zhengtai"));
entitys.add(new BasicNameValuePair("appId", C_TRIP_APP_ID));
entitys.add(new BasicNameValuePair("signature", finallySign));
entitys.add(new BasicNameValuePair("corpPayType","public"));
entitys.add(new BasicNameValuePair("corpPayType", corpPayType));
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(entitys, "UTF-8");
httpPost.setEntity(entity);
HttpClient client = new DefaultHttpClient();
try {
return client.execute(httpPost);
HttpResponse execute = client.execute(httpPost);
String body = EntityUtils.toString(execute.getEntity(), "UTF-8");
String url = getUrlFromHtml(body);
H5Response h5Response = new H5Response();
h5Response.setSuccess(true);
h5Response.setRedirectUrl(url);
return h5Response;
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -186,4 +194,52 @@ public class CTripLoginRequest {
return matcher.find();
}
public H5Response h5Login() {
User currentUser = BaseContext.getCurrentUser();
CTripHSingleLoginParam cTripHSingleLoginParam = new CTripHSingleLoginParam();
cTripHSingleLoginParam.setAppId(C_TRIP_APP_KEY);
cTripHSingleLoginParam.setEmployeeId(String.valueOf(currentUser.getEmployeeNo()));
cTripHSingleLoginParam.setToken(tokenRequest.getToken());
cTripHSingleLoginParam.setAppId("zhengtai");
cTripHSingleLoginParam.setCorpPayType("public");
String finallySign =
Digest.md5(C_TRIP_APP_KEY + currentUser.getEmployeeNo() + "public" + Digest.md5(C_TRIP_APP_SECURITY));
cTripHSingleLoginParam.setSignature(finallySign);
return postRequest.post(hSinngleLoginUrl, cTripHSingleLoginParam, H5Response.class);
}
public String getMD5Hash(String source) {
StringBuilder sb = new StringBuilder();
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(source.getBytes());
for (byte b : md5.digest()) {
sb.append(String.format("%02x", b));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
private static String getUrlFromHtml(String htmlContent) {
String regexPattern = "var config = \\{\"url\":\"(.*?)\",\"appid\":";
Pattern pattern = Pattern.compile(regexPattern);
Matcher matcher = pattern.matcher(htmlContent);
if (matcher.find()) {
return matcher.group(1);
} else {
throw new NotFoundException(NOT_FOUND);
}
}
}

View File

@ -0,0 +1,4 @@
package com.chint.interfaces.rest.ctrip;
public class CTripSyncRequest {
}

View File

@ -3,13 +3,14 @@ package com.chint.interfaces.rest.ctrip;
import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.ctrip.dto.AuthenticationResponseList;
import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationEntity;
import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationInfo;
import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationListRequest;
import com.chint.interfaces.rest.user.UserHttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chint.interfaces.rest.ctrip.dto.AuthenticationResponseList;
import java.util.List;
import static com.chint.infrastructure.constant.Constant.*;
@ -27,6 +28,7 @@ public class CTripUserSaveRequest {
private final String userUrl = C_TRIP_BASE_URL + C_TRIP_USER_SAVE_PATH;
public void saveUserToCTrip() {
User currentUser = BaseContext.getCurrentUser();
User user = userHttpRequest.loadUserInfo(currentUser);
@ -35,13 +37,12 @@ public class CTripUserSaveRequest {
AuthenticationListRequest authenticationListRequest = new AuthenticationListRequest();
authenticationListRequest.setAppkey(C_TRIP_APP_KEY);
authenticationListRequest.setTicket(ticket);
authenticationListRequest.setCorporationID("zhengtai");
authenticationListRequest.setCorporationID(C_TRIP_CORP_ID);
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
authenticationInfo.setSequence("0");
authenticationInfo.setAuthentication(authenticationEntity);
authenticationListRequest.setAuthenticationInfoList(List.of(authenticationInfo));
AuthenticationResponseList post = postRequest.post(userUrl, authenticationInfo, AuthenticationResponseList.class);
System.out.println(post);
postRequest.post(userUrl, authenticationListRequest, AuthenticationResponseList.class);
}
@ -49,7 +50,7 @@ public class CTripUserSaveRequest {
AuthenticationEntity authenticationEntity = new AuthenticationEntity();
authenticationEntity.setName(user.getName());
authenticationEntity.setEmployeeID(user.getEmployeeNo().toString());
authenticationEntity.setRankName(user.getRankCode());
// authenticationEntity.setRankName(user.getRankCode());
authenticationEntity.setValid(user.getWorkStatus());
authenticationEntity.setSubAccountName("zhengtai_提前审批测试");
return authenticationEntity;

View File

@ -9,4 +9,9 @@ public class RankInfo {
private String rankName;
// Getters and setters...
public static RankInfo of(String rankName) {
RankInfo rankInfo = new RankInfo();
rankInfo.setRankName(rankName);
return rankInfo;
}
}

View File

@ -0,0 +1,9 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
@Data
public class H5LoginToken {
private String Token;
private boolean Success;
}

View File

@ -0,0 +1,9 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
@Data
public class H5Response {
private String redirectUrl;
private boolean success;
}

View File

@ -0,0 +1,19 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
import static com.chint.infrastructure.constant.Constant.C_TRIP_APP_KEY;
import static com.chint.infrastructure.constant.Constant.C_TRIP_APP_SECURITY;
@Data
public class H5TicketModel {
private String AppKey;
private String AppSecurity;
public static H5TicketModel build(){
H5TicketModel h5TicketModel = new H5TicketModel();
h5TicketModel.setAppKey(C_TRIP_APP_KEY);
h5TicketModel.setAppSecurity(C_TRIP_APP_SECURITY);
return h5TicketModel;
}
}

View File

@ -0,0 +1,11 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
@Data
public class PageViewData {
private String serviceStatus;
private boolean success;
private String url;
private String ssoType;
}

View File

@ -29,6 +29,7 @@ public class LYUserRequest {
private String userUrl = L_Y_BASE_URL + L_Y_USER_PATH;
public boolean saveCurrentUser() {
System.out.println("saveCurrentUser");
User currentUser = BaseContext.getCurrentUser();
userHttpRequest.loadUserInfo(currentUser);
EmployeeEntity employeeEntity = user2LYEmployee(currentUser);

View File

@ -3,7 +3,6 @@ package com.chint;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.CityRepository;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.CTripEstimateRequest;
import com.chint.interfaces.rest.ctrip.CTripLocationHttpRequest;
import com.chint.interfaces.rest.ctrip.CTripLoginRequest;
@ -15,7 +14,6 @@ import com.chint.interfaces.rest.ctrip.dto.estimate.response.BookingRelatedApiRe
import com.chint.interfaces.rest.ctrip.dto.location.CTripCity;
import com.chint.interfaces.rest.ctrip.dto.location.CTripCountry;
import com.chint.interfaces.rest.ctrip.dto.login.CTripAuthLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripHSingleLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripLoginParam;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@ -112,24 +110,16 @@ public class CTripTest {
@Test
void hSingleLogin() {
// BaseContext.setCurrentUser(user);
// CTripLoginParam cTripLoginParam = new CTripLoginParam();
// cTripLoginParam.setEmployeeID(String.valueOf(user.getEmployeeNo()));
CTripHSingleLoginParam param = new CTripHSingleLoginParam();
param.setEmployeeId("230615020");
param.setCorpPayType("public");
HttpResponse response = loginRequest.hSingleLogin(param);
HttpEntity entity = response.getEntity();
String result = null;
try {
result = EntityUtils.toString(entity,"UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
BaseContext.setCurrentUser(user);
System.out.println(loginRequest.hSingleLogin().getRedirectUrl());
}
System.out.println(result);
@Test
void h5LoginTest() {
BaseContext.setCurrentUser(user);
System.out.println(loginRequest.h5Login());
}
@Test
void estimate() {
BaseContext.setCurrentUser(user);