|
|
@ -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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |