'提交diam'

dev-discount
199901012 4 years ago
parent 6b29a6413d
commit 17e6f9cfcf
  1. 43
      hai-cweb/src/test/common/RegionTest.java
  2. 91
      hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java
  3. 38
      hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java

@ -76,20 +76,37 @@ public class RegionTest {
public void test(){ public void test(){
try { try {
Map<String,Object> map = new HashMap<>(); Map<String,Object> tokenMap = new HashMap<>();
map.put("appId", "js3w7K4W0SglB6bNPVjs3w7K4W0SglB6bNPV"); tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA");
map.put("appSecret", "SoIXquKSKT8s7sa6ySjfyBXxKTC4Jhqx7fiE1qT0XWrrnkScurMGsLdGrz5ThLo5"); tokenMap.put("appSecret", "R7yJjinikdPhOlTrVgmdS7cblWMMOf99zEJkfPgaTIoDtKGlX51JKueLV725a6S4");
Long date = new Date().getTime(); JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap));
String signature = "mUGcV7CxPYRuzIWXd72bVknKYCXuT7d1tRxQUdVR9iAcxxTdmWC8lTo0rL5wDZwLmTwQnpCqeHz3MtAIVBrm99WmtPv93pRdgWcIkkgPt18pAFyavYrPt80Yh8iyFr8s";
String sha256 = encodeBySHA256(signature + JSON.toJSONString(map) + date);
Map<String,Object> map2 = new HashMap<>();
map2.put("signature", signature);
map2.put("body", JSON.toJSONString(map));
map2.put("ts", date);
JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(map2));
System.out.println(jsonObject.toJSONString()); System.out.println(jsonObject.toJSONString());
if(jsonObject != null && jsonObject.getBoolean("success") == true) {
JSONObject data = jsonObject.getJSONObject("data");
String token = data.getString("token");
Map<String,Object> bodyMap = new HashMap<>();
bodyMap.put("appId", "jsVpwDoHZfR2rrpjhA");
bodyMap.put("pageNo", 1);
bodyMap.put("pageSize", 10);
bodyMap.put("startTime", "2021-3-31 00:00:00");
bodyMap.put("endTime", "2021-3-31 23:00:00");
bodyMap.put("customerCode", "48464274");
String signature = "hAFO76ZqXmIqosNw3PTAP4wxGJTN7MPawSU0QFDzzNioLjKMEaVFDlNKRIQX6n0DgyoVMy170T0b13P8uUTAQsbk9UNRPFO5i0fWp1hHOhNdaaQ2BdC0WXQz5QQ5epyK";
Long date = new Date().getTime();
String sha256 = encodeBySHA256(signature + JSON.toJSONString(bodyMap) + date);
Map<String,Object> headerMap = new HashMap<>();
headerMap.put("sign", sha256);
headerMap.put("token", token);
headerMap.put("ts", date);
//map2.put("sign", sha256);
HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", bodyMap, headerMap);
//System.out.println(jsonObject.toJSONString());
}
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();

@ -0,0 +1,91 @@
package com.hai.schedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.utils.HttpsUtils;
import com.hai.entity.HighOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Auther: 胡锐
* @Description: 同步中石化接口
* @Date: 2021/3/31 23:49
*/
@Configuration
public class SynchronizeCNPC {
private static Logger log = LoggerFactory.getLogger(SynchronizeCNPC.class);
private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次
public void certification() {
Map<String, Object> tokenMap = new HashMap<>();
tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA");
tokenMap.put("appSecret", "R7yJjinikdPhOlTrVgmdS7cblWMMOf99zEJkfPgaTIoDtKGlX51JKueLV725a6S4");
JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap));
System.out.println(jsonObject.toJSONString());
if (jsonObject != null && jsonObject.getBoolean("success") == true) {
JSONObject data = jsonObject.getJSONObject("data");
String token = data.getString("token");
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("appId", "jsVpwDoHZfR2rrpjhA");
bodyMap.put("pageNo", 1);
bodyMap.put("pageSize", 10);
bodyMap.put("startTime", "2021-3-31 00:00:00");
bodyMap.put("endTime", "2021-3-31 23:00:00");
bodyMap.put("customerCode", "48464274");
String signature = "hAFO76ZqXmIqosNw3PTAP4wxGJTN7MPawSU0QFDzzNioLjKMEaVFDlNKRIQX6n0DgyoVMy170T0b13P8uUTAQsbk9UNRPFO5i0fWp1hHOhNdaaQ2BdC0WXQz5QQ5epyK";
Long date = new Date().getTime();
String sha256 = encodeBySHA256(signature + JSON.toJSONString(bodyMap) + date);
Map<String, Object> headerMap = new HashMap<>();
headerMap.put("sign", sha256);
headerMap.put("token", token);
headerMap.put("ts", date);
log.info(HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", bodyMap, headerMap).toJSONString());
}
}
public String encodeBySHA256(String str) {
try{
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
return getFormattedText(messageDigest.digest());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (Exception e) {
throw new RuntimeException(e);
}
return "";
}
private String getFormattedText(byte[] bytes) {
int len = bytes.length;
StringBuilder buf = new StringBuilder(len * 2);
// 把密文转换成十六进制的字符串形式
for (int j=0;j<len;j++){
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
}

@ -221,6 +221,44 @@ public class HttpsUtils {
return null; return null;
} }
public static JSONObject doPost(String apiUrl, Map<String,Object> body, Map<String,Object> header) {
CloseableHttpClient httpClient = null;
if (apiUrl.startsWith("https")) {
httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory())
.setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
} else {
httpClient = HttpClients.createDefault();
}
String httpStr = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(apiUrl);
httpPost.setConfig(requestConfig);
for (Map.Entry<String, Object> entry : header.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue().toString());
}
StringEntity stringEntity = new StringEntity(JSON.toJSONString(body), "UTF-8");// 解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
httpStr = EntityUtils.toString(entity, "UTF-8");
return JSON.parseObject(httpStr);
} catch (Exception e) {
log.error(e.getMessage(),e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return null;
}
/** /**
* 发送 POST 请求JSON形式 * 发送 POST 请求JSON形式
* *

Loading…
Cancel
Save