|
@ -1,5 +1,6 @@ |
|
|
package com.example.demo.serviceImpl.bean; |
|
|
package com.example.demo.serviceImpl.bean; |
|
|
|
|
|
|
|
|
|
|
|
import com.example.demo.Util.BaseDES2; |
|
|
import com.example.demo.domain.vo.bean.BeanAuditInfo; |
|
|
import com.example.demo.domain.vo.bean.BeanAuditInfo; |
|
|
import com.example.demo.domain.vo.bean.BeanRechargeInfo; |
|
|
import com.example.demo.domain.vo.bean.BeanRechargeInfo; |
|
|
import com.example.demo.domain.vo.bean.GoldBean; |
|
|
import com.example.demo.domain.vo.bean.GoldBean; |
|
@ -11,13 +12,22 @@ import com.github.pagehelper.PageInfo; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
|
import org.springframework.http.HttpEntity; |
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
|
import org.springframework.http.MediaType; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.client.RestClientException; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.util.UriComponentsBuilder; |
|
|
import org.springframework.web.util.UriComponentsBuilder; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -41,7 +51,7 @@ public class BeanAuditServiceImpl implements BeanAuditService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 构建接口URL及参数 |
|
|
// 2. 构建接口URL及参数 |
|
|
@Value("${file.upload.url}") |
|
|
|
|
|
|
|
|
@Value("${bean.url}") |
|
|
String apiUrl; |
|
|
String apiUrl; |
|
|
|
|
|
|
|
|
//查找审核信息 |
|
|
//查找审核信息 |
|
@ -57,36 +67,50 @@ public class BeanAuditServiceImpl implements BeanAuditService { |
|
|
public Result updateStatus1(BeanAuditInfo info) { |
|
|
public Result updateStatus1(BeanAuditInfo info) { |
|
|
BeanAuditInfo beanAuditInfo = beanAuditMapper.selectById(info.getId()); |
|
|
BeanAuditInfo beanAuditInfo = beanAuditMapper.selectById(info.getId()); |
|
|
String jwcode = beanAuditInfo.getJwcode().toString(); |
|
|
String jwcode = beanAuditInfo.getJwcode().toString(); |
|
|
String op = "recharge"; // 操作类型(根据实际业务定义,例如"recharge"表示充值) |
|
|
|
|
|
|
|
|
// String jwcode = "2e35cadd48a15cc4cd834d35e38faa71"; |
|
|
|
|
|
try { |
|
|
|
|
|
BaseDES2 d = new BaseDES2(); |
|
|
|
|
|
jwcode = d.encrypt(jwcode); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return Result.error("加密失败"); |
|
|
|
|
|
} |
|
|
String content = beanAuditInfo.getRemark(); // 备注作为content参数 |
|
|
String content = beanAuditInfo.getRemark(); // 备注作为content参数 |
|
|
String orderNo = UUID.randomUUID().toString().replace("-", ""); // 生成唯一订单号(去除横线) |
|
|
String orderNo = UUID.randomUUID().toString().replace("-", ""); // 生成唯一订单号(去除横线) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UriComponentsBuilder urlBuilder1 = UriComponentsBuilder.fromHttpUrl(apiUrl) |
|
|
|
|
|
.queryParam("jwcode", jwcode) |
|
|
|
|
|
.queryParam("op", op) |
|
|
|
|
|
.queryParam("gold", beanAuditInfo.getFreeBean()) |
|
|
|
|
|
.queryParam("content", content); |
|
|
|
|
|
|
|
|
|
|
|
UriComponentsBuilder urlBuilder2 = UriComponentsBuilder.fromHttpUrl(apiUrl) |
|
|
|
|
|
.queryParam("jwcode", jwcode) |
|
|
|
|
|
.queryParam("op", op) |
|
|
|
|
|
.queryParam("gold", beanAuditInfo.getPermanentBean()) |
|
|
|
|
|
.queryParam("content", content) |
|
|
|
|
|
.queryParam("order_no", orderNo); |
|
|
|
|
|
// 3. 发送GET请求 |
|
|
|
|
|
ResponseEntity<String> response1 = restTemplate.getForEntity(urlBuilder1.toUriString(), String.class); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 处理响应结果 |
|
|
|
|
|
if (!response1.getStatusCode().is2xxSuccessful()) { |
|
|
|
|
|
return Result.error("免费远程接口调用失败,状态码:" + response1.getStatusCodeValue()); |
|
|
|
|
|
} |
|
|
|
|
|
// 3. 发送GET请求 |
|
|
|
|
|
ResponseEntity<String> response2 = restTemplate.getForEntity(urlBuilder2.toUriString(), String.class); |
|
|
|
|
|
|
|
|
// 1. 创建请求参数对象(使用Map或自定义实体类) |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("jwcode", jwcode); |
|
|
|
|
|
params.put("gold_buy", beanAuditInfo.getPermanentBean().toString()); |
|
|
|
|
|
params.put("gold_free", beanAuditInfo.getFreeBean().toString()); |
|
|
|
|
|
params.put("content", content); |
|
|
|
|
|
params.put("order_no", orderNo); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 构建请求头,指定Content-Type为JSON |
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON); // 关键:设置为JSON格式 |
|
|
|
|
|
|
|
|
// 4. 处理响应结果 |
|
|
|
|
|
if (!response2.getStatusCode().is2xxSuccessful()) { |
|
|
|
|
|
return Result.error("付费远程接口调用失败,状态码:" + response2.getStatusCodeValue()); |
|
|
|
|
|
|
|
|
// 3. 构建请求实体(参数+头信息) |
|
|
|
|
|
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(params, headers); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 4. 发送POST请求 |
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity( |
|
|
|
|
|
apiUrl, |
|
|
|
|
|
requestEntity, |
|
|
|
|
|
String.class |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
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()); |
|
|
} |
|
|
} |
|
|
beanAuditMapper.updateStatus1(info); |
|
|
beanAuditMapper.updateStatus1(info); |
|
|
return Result.success(); |
|
|
return Result.success(); |
|
|