|
@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -27,12 +28,18 @@ import java.util.Map;
|
|
public class YqdServiceImpl {
|
|
public class YqdServiceImpl {
|
|
|
|
|
|
|
|
|
|
- private static final String KEY = "f38e792dbcc92bf0b462ec48819fbc17";
|
|
|
|
|
|
+ @Value("${yqd.key}")
|
|
|
|
+ private String key;
|
|
|
|
|
|
- private static final String ACCOUNT = "chen1130";
|
|
|
|
|
|
+ @Value("${yqd.account}")
|
|
|
|
+ private String account;
|
|
|
|
|
|
|
|
|
|
- private static final String CREATE_ORDER = "http://open.yiqida.cn/api/UserOrder/CreateOrder?timestamp=%s&userName=%s&sign=%s";
|
|
|
|
|
|
+ @Value("${yqd.createUrl}")
|
|
|
|
+ private String createUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${yqd.callbackUrl}")
|
|
|
|
+ private String callbackUrl;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
ApiLogDao apiLogDao;
|
|
ApiLogDao apiLogDao;
|
|
@@ -45,7 +52,7 @@ public class YqdServiceImpl {
|
|
body.put("buyCount", dto.getBuyCount());
|
|
body.put("buyCount", dto.getBuyCount());
|
|
body.put("externalSellPrice", dto.getExternalSellPrice());
|
|
body.put("externalSellPrice", dto.getExternalSellPrice());
|
|
body.put("template", "[" + dto.getPhone() + "]");
|
|
body.put("template", "[" + dto.getPhone() + "]");
|
|
- String url = String.format(CREATE_ORDER, timestamp, ACCOUNT, getSign(timestamp, JSON.toJSONString(body)));
|
|
|
|
|
|
+ String url = String.format(createUrl, timestamp, account, getSign(timestamp, JSON.toJSONString(body)));
|
|
ResponseModel request = HttpClientUtil.request(HttpModel.builder().method(MethodType.Post).url(url).body(JSON.toJSONString(body)).build());
|
|
ResponseModel request = HttpClientUtil.request(HttpModel.builder().method(MethodType.Post).url(url).body(JSON.toJSONString(body)).build());
|
|
|
|
|
|
ApiLog apiLog = new ApiLog();
|
|
ApiLog apiLog = new ApiLog();
|
|
@@ -59,7 +66,40 @@ public class YqdServiceImpl {
|
|
LinkedHashMap map = (LinkedHashMap) request.getBody();
|
|
LinkedHashMap map = (LinkedHashMap) request.getBody();
|
|
if (HttpStatus.HTTP_OK == (int) map.get("code")) {
|
|
if (HttpStatus.HTTP_OK == (int) map.get("code")) {
|
|
log.info("视频会员响应:{}", JSON.toJSONString(request));
|
|
log.info("视频会员响应:{}", JSON.toJSONString(request));
|
|
- return ResultContent.build(ResultState.Success,request.getBody());
|
|
|
|
|
|
+ return ResultContent.build(ResultState.Success, request.getBody());
|
|
|
|
+ } else {
|
|
|
|
+ return ResultContent.build(ResultState.Fail, map.get("msg"));
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return ResultContent.build(ResultState.Fail, JSON.parseObject((String) request.getBody()).getString("msg"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public ResultContent create2(YqdCreateRequestModel createRequestModel) {
|
|
|
|
+ createRequestModel.setCallbackUrl(callbackUrl);
|
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
|
+ String url = String.format(createUrl, timestamp, account, getSign(timestamp, JSON.toJSONString(createRequestModel)));
|
|
|
|
+ ResponseModel request = HttpClientUtil.request(HttpModel.builder().method(MethodType.Post).url(url).body(JSON.toJSONString(createRequestModel)).build());
|
|
|
|
+
|
|
|
|
+ ApiLog apiLog = new ApiLog();
|
|
|
|
+ apiLog.setService("create");
|
|
|
|
+ apiLog.setSystem("video");
|
|
|
|
+ apiLog.setRequest(JSON.toJSONString(createRequestModel));
|
|
|
|
+ apiLog.setResponse(JSON.toJSONString(request.getBody()));
|
|
|
|
+ apiLogDao.save(apiLog);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ LinkedHashMap map = (LinkedHashMap) request.getBody();
|
|
|
|
+ if (HttpStatus.HTTP_OK == (int) map.get("code")) {
|
|
|
|
+ log.info("视频会员响应:{}", JSON.toJSONString(request));
|
|
|
|
+ return ResultContent.build(ResultState.Success, request.getBody());
|
|
} else {
|
|
} else {
|
|
return ResultContent.build(ResultState.Fail, map.get("msg"));
|
|
return ResultContent.build(ResultState.Fail, map.get("msg"));
|
|
}
|
|
}
|
|
@@ -71,9 +111,9 @@ public class YqdServiceImpl {
|
|
|
|
|
|
private String getSign(long timestamp, String data) {
|
|
private String getSign(long timestamp, String data) {
|
|
if (StringUtils.isEmpty(data)) {
|
|
if (StringUtils.isEmpty(data)) {
|
|
- return DigestUtils.md5Hex(timestamp + KEY);
|
|
|
|
|
|
+ return DigestUtils.md5Hex(timestamp + key);
|
|
}
|
|
}
|
|
- return DigestUtils.md5Hex(timestamp + data + KEY);
|
|
|
|
|
|
+ return DigestUtils.md5Hex(timestamp + data + key);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|