|
|
|
@ -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<String, String> params = new LinkedMultiValueMap<>(); |
|
|
|
params.add("jwcode", jwcode); |
|
|
|
|
|
|
|
// 构建请求实体 |
|
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers); |
|
|
|
|
|
|
|
// 发送POST请求 |
|
|
|
ResponseEntity<String> 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("-", ""); // 生成唯一订单号(去除横线) |
|
|
|
|
|
|
|
|