diff --git a/src/main/java/com/example/demo/serviceImpl/bean/BeanRechargeServiceImpl.java b/src/main/java/com/example/demo/serviceImpl/bean/BeanRechargeServiceImpl.java index 572af45..2b5129d 100644 --- a/src/main/java/com/example/demo/serviceImpl/bean/BeanRechargeServiceImpl.java +++ b/src/main/java/com/example/demo/serviceImpl/bean/BeanRechargeServiceImpl.java @@ -22,6 +22,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -128,6 +130,8 @@ public class BeanRechargeServiceImpl implements BeanRechargeService { } } + @Value("${toujiaoApp.url}") + private String toujiaoAppUrl; @Override public Result addBeanDC(BeanRecharge recharge) { @@ -169,6 +173,44 @@ public class BeanRechargeServiceImpl implements BeanRechargeService { } catch (Exception e) { return Result.error("加密失败"); } + + try { + // 构建完整的请求URL + String fullUrl = toujiaoAppUrl + "/api/user/toujiaoAppLogin"; + + // 创建请求头,设置Content-Type为application/x-www-form-urlencoded + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + // 创建请求体,使用MultiValueMap存储参数 + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("jwcode", jwcode); + + // 构建请求实体 + HttpEntity> requestEntity = new HttpEntity<>(params, headers); + + // 发送POST请求 + ResponseEntity response = restTemplate.postForEntity( + fullUrl, + requestEntity, + String.class + ); + + System.out.println("请求URL:" + fullUrl); + System.out.println("请求参数:" + params); + System.out.println("响应状态码:" + response.getStatusCodeValue()); + System.out.println("响应内容:" + response.getBody()); + + if (!response.getStatusCode().is2xxSuccessful()) { + return Result.error("远程接口调用失败,状态码:" + response.getStatusCodeValue() + ",响应:" + response.getBody()); + } + } catch (RestClientException e) { + e.printStackTrace(); + return Result.error("请求发送失败:" + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + return Result.error("系统异常:" + e.getMessage()); + } String content = recharge.getRemark(); // 备注作为content参数 String orderNo = UUID.randomUUID().toString().replace("-", ""); // 生成唯一订单号(去除横线) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 2d306d8..a7af526 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -92,6 +92,8 @@ file: upload: url: http://39.101.133.168:8828/hljw/api/aws/upload +toujiaoApp: + url: http://39.101.133.168:8828/hljw feishu: webhook: url: https://open.feishu.cn/open-apis/bot/v2/hook/455ccf9c-a8b1-46b4-b4d8-9f528620595d diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index d5bcebd..50f7d66 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -98,6 +98,9 @@ feishu: webhook: url: https://open.feishu.cn/open-apis/bot/v2/hook/1a515b19-b64f-46b7-9486-35842b9539fe +toujiaoApp: + url: https://api.homilychart.com/hljw + bean: recharge: url: http://api.homilychart.com/hljwgo/api/wallet/recharge