| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ruoyi.common.core.domain.entity.ServiceOrderAppVo; |
| | | import com.ruoyi.common.core.domain.entity.ServiceOrderAppResultVo; |
| | | import com.ruoyi.common.core.domain.entity.ServiceOrderDelResultVo; |
| | | import com.ruoyi.common.core.domain.entity.ServiceOrderDelVo; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.net.URLEncoder; |
| | |
| | | /** |
| | | * 民航医疗接口处理 |
| | | */ |
| | | @Component |
| | | public class ServiceOrderUtil { |
| | | private static final Logger log = LoggerFactory.getLogger(ServiceOrderUtil.class); |
| | | public static String AddServiceOrederAPI = "http://localhost:8011/v1/"; |
| | | private static String addServiceOrederAPI; |
| | | |
| | | @Value("${min.apiUrl}") |
| | | public void setAddServiceOrederAPI(String apiUrl) { |
| | | ServiceOrderUtil.addServiceOrederAPI = apiUrl; |
| | | } |
| | | |
| | | public static String getAddServiceOrederAPI() { |
| | | return addServiceOrederAPI; |
| | | } |
| | | |
| | | /** |
| | | * 创建服务单 |
| | |
| | | * @return 服务单接口调用结果 |
| | | */ |
| | | public static ServiceOrderAppResultVo CreateServiceOrder(ServiceOrderAppVo model,String appSecret) { |
| | | if (AddServiceOrederAPI.isEmpty()) { |
| | | if (addServiceOrederAPI.isEmpty()) { |
| | | // log.info("AddServiceOrederAPI 未设置,请先设置接口地址。"); |
| | | return null; |
| | | } |
| | | |
| | | log.info("接口地址:"+addServiceOrederAPI); |
| | | |
| | | //计算时间戳和签名 |
| | | long unixTime = System.currentTimeMillis() / 1000; // 获取当前时间戳(秒) |
| | | long unixTime = System.currentTimeMillis() / 1000; // 获取当前时间戳(秒) Long.valueOf("1746444543") ;// |
| | | model.setUnixTime(unixTime); // 设置时间戳到模型中 |
| | | |
| | | // 将 model 转换为 Map<String, String> |
| | |
| | | try { |
| | | Object value = field.get(model); |
| | | if (value != null) { |
| | | params.put(field.getName(), value.toString()); |
| | | params.put(field.getName(),URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString())); |
| | | } |
| | | } catch (IllegalAccessException e) { |
| | | // log.error("获取对象属性值时出错", e); |
| | | } catch (UnsupportedEncodingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | model.setSign(ServiceOrderSign.generateSign(params,appSecret)); // 生成签名并设置到模型中 |
| | | |
| | | log.info("Sign值="+model.getSign()); |
| | | |
| | | // 替换为 |
| | | StringBuilder formData = new StringBuilder(); |
| | |
| | | // 将字段名首字母大写 |
| | | String fieldName = field.getName(); |
| | | String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); |
| | | |
| | | formData.append(capitalizedFieldName) |
| | | .append("=") |
| | | .append(value.toString()); |
| | | .append("=") |
| | | .append(URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString())); |
| | | } |
| | | } catch (Exception e) { |
| | | // log.error("拼接表单数据时出错", e); |
| | | } |
| | | } |
| | | |
| | | String responseData = HttpUtils.sendPost(AddServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded"); |
| | | log.info("请求参数="+formData.toString()); |
| | | |
| | | String responseData = HttpUtils.sendPost(addServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded"); |
| | | |
| | | |
| | | if (responseData != null && !responseData.isEmpty()) { |
| | |
| | | * @param model 服务订单删除请求值对象 |
| | | * @return 服务订单删除接口调用结果 |
| | | */ |
| | | public static ServiceOrderAppResultVo CancelServiceOrder(ServiceOrderDelVo model,String appSecret) { |
| | | if (AddServiceOrederAPI.isEmpty()) { |
| | | public static ServiceOrderDelResultVo CancelServiceOrder(ServiceOrderDelVo model,String appSecret) { |
| | | if (addServiceOrederAPI.isEmpty()) { |
| | | // log.info("AddServiceOrederAPI 未设置,请先设置接口地址。"); |
| | | return null; |
| | | } |
| | |
| | | try { |
| | | Object value = field.get(model); |
| | | if (value != null) { |
| | | params.put(field.getName(), value.toString()); |
| | | params.put(field.getName(),URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString())); |
| | | } |
| | | } catch (IllegalAccessException e) { |
| | | // log.error("获取对象属性值时出错", e); |
| | | } catch (UnsupportedEncodingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | // 将字段名首字母大写 |
| | | String fieldName = field.getName(); |
| | | formData.append(fieldName) |
| | | .append("=") |
| | | .append(value.toString()); |
| | | String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); |
| | | |
| | | formData.append(capitalizedFieldName) |
| | | .append("=") |
| | | .append(URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString())); |
| | | } |
| | | } catch (Exception e) { |
| | | // log.error("拼接表单数据时出错", e); |
| | | } |
| | | } |
| | | |
| | | String responseData = HttpUtils.sendPost(AddServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded"); |
| | | String responseData = HttpUtils.sendPost(addServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded"); |
| | | |
| | | if (responseData != null && !responseData.isEmpty()) { |
| | | // log.info("接口响应: " + responseData); |
| | | try { |
| | | return JSON.parseObject(responseData, ServiceOrderAppResultVo.class); |
| | | return JSON.parseObject(responseData, ServiceOrderDelResultVo.class); |
| | | } catch (Exception e) { |
| | | // log.info("解析接口响应数据失败: " + e.getMessage()); |
| | | } |