|
@@ -1,9 +1,11 @@
|
|
|
-package com.fs.tulin;
|
|
|
+package com.fs.tulin.utils;
|
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fs.tulin.entity.StudentInfo;
|
|
|
+import com.fs.tulin.entity.TulinInfoSyncLog;
|
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
@@ -12,6 +14,9 @@ import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
|
+ * 正确与错误返回结果示例:
|
|
|
+ * {"data":{"status":"ok","err_msg":"","execute_log":[***]}
|
|
|
+ * {"msg":"******","code":*****}
|
|
|
* @author: Guos
|
|
|
* @time: 2025/10/21 下午3:40
|
|
|
*/
|
|
@@ -34,39 +39,7 @@ public class SyncStudentInfoService {
|
|
|
*/
|
|
|
private static final String CORP_ID = "PNBnO6MajM0tAd8t";
|
|
|
|
|
|
-
|
|
|
- public static void main(String[] args) throws JsonProcessingException {
|
|
|
-//第一种方式
|
|
|
-// Map<String, Object> requestBody = new HashMap<>();
|
|
|
-// requestBody.put("corp_id", "PNBnO6MajM0tAd8t");
|
|
|
-// List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
-// Map<String, Object> dataItem = new HashMap<>();
|
|
|
-// dataItem.put("union_id", "oLH_O648dcNgoZdQT4CN2Qft8i7k");
|
|
|
-// dataItem.put("open_id", "ozzk-19AxQC5D3X9Wqpb-I3_Y3EQ");
|
|
|
-// dataItem.put("appid", "wx6688e6b9b6fb8700");
|
|
|
-// dataItem.put("nickname", "@冰阔落");
|
|
|
-// dataItem.put("column_name", "测试栏目0921");
|
|
|
-// dataItem.put("pharmacy_id", "26ee29ce-35aa-46c8-9650-3fe46014690c");
|
|
|
-// dataItem.put("service_phone", "13760648472");
|
|
|
-// dataList.add(dataItem);
|
|
|
-// String sort = sortRequestBody(dataItem);
|
|
|
-// requestBody.put("data", dataList);
|
|
|
-// // 生成签名
|
|
|
-// long timestamp = generateTimestamp();
|
|
|
-// String sign = generateSign("PNBnO6MajM0tAd8t", sort, timestamp);
|
|
|
-// System.out.println("时间戳: " + timestamp);
|
|
|
-// System.out.println("签名: " + sign);
|
|
|
-// // 构建完整的请求URL "https://api.xiangyue.life/api/v1/mp/sync/student
|
|
|
-// String url = String.format("https://api.xiangyue.life/api/v1/mp/sync/student?sign=%s&t=%d", sign, timestamp);
|
|
|
-// HttpRequest httpRequest = HttpUtil.createPost(url);
|
|
|
-// httpRequest.header("Content-Type", "application/json");
|
|
|
-// System.out.println("url: " + url);
|
|
|
-// System.out.println("排序后的"+sortRequestBody(requestBody));
|
|
|
-// httpRequest.body(sortRequestBody(requestBody));
|
|
|
-// HttpResponse execute = httpRequest.execute();
|
|
|
-// String body = execute.body();
|
|
|
-// System.out.println("响应结果: " + body);
|
|
|
-//第二种方式
|
|
|
+// public static void main(String[] args) throws JsonProcessingException {
|
|
|
// StudentInfo student = StudentInfo.builder()
|
|
|
// .union_id("oLH_O648dcNgoZdQT4CN2Qft8i7k")
|
|
|
// .open_id("ozzk-19AxQC5D3X9Wqpb-I3_Y3EQ")
|
|
@@ -74,28 +47,8 @@ public class SyncStudentInfoService {
|
|
|
// .nickname("@冰阔落")
|
|
|
// .column_name("测试栏目0921")
|
|
|
// .pharmacy_id(PHARMACY_ID).service_phone("13760648472").build();
|
|
|
-// //排序
|
|
|
-// String sortedJson = JsonSortUtils.toSortedJson(student);
|
|
|
-// long timestamp = generateTimestamp();
|
|
|
-// String sign = generateSign(CORP_ID, sortedJson, timestamp);
|
|
|
-// String url = String.format("https://api.xiangyue.life/api/v1/mp/sync/student?sign=%s&t=%d", sign, timestamp);
|
|
|
-// Map<String, Object> request = new HashMap<>();
|
|
|
-// request.put("corp_id", CORP_ID);
|
|
|
-// request.put("data", Collections.singletonList(student));
|
|
|
-// String jsonBody = mapper.writeValueAsString(request);
|
|
|
-// System.out.println("正确JSON:");
|
|
|
-// System.out.println(jsonBody);
|
|
|
-// sendHttpPost(url, jsonBody);
|
|
|
-
|
|
|
- StudentInfo student = StudentInfo.builder()
|
|
|
- .union_id("oLH_O648dcNgoZdQT4CN2Qft8i7k")
|
|
|
- .open_id("ozzk-19AxQC5D3X9Wqpb-I3_Y3EQ")
|
|
|
- .appid("wx6688e6b9b6fb8700")
|
|
|
- .nickname("@冰阔落")
|
|
|
- .column_name("测试栏目0921")
|
|
|
- .pharmacy_id(PHARMACY_ID).service_phone("13760648472").build();
|
|
|
- String result = send(CORP_ID, student);
|
|
|
- }
|
|
|
+// String result = send(CORP_ID, student);
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* @param corpId 企业ID
|
|
@@ -103,7 +56,7 @@ public class SyncStudentInfoService {
|
|
|
* @return 请求结果
|
|
|
* @throws JsonProcessingException
|
|
|
*/
|
|
|
- public static String send(String corpId, StudentInfo studentInfo) throws JsonProcessingException {
|
|
|
+ public static TulinInfoSyncLog send(String corpId, StudentInfo studentInfo) throws JsonProcessingException {
|
|
|
String sortedJson = JsonSortUtils.toSortedJson(studentInfo);
|
|
|
long timestamp = generateTimestamp();
|
|
|
String sign = generateSign(corpId, sortedJson, timestamp);
|
|
@@ -121,7 +74,7 @@ public class SyncStudentInfoService {
|
|
|
* @param jsonBody 请求体JSON字符串
|
|
|
* @return 响应结果
|
|
|
*/
|
|
|
- private static String sendHttpPost(String url, String jsonBody) {
|
|
|
+ private static TulinInfoSyncLog sendHttpPost(String url, String jsonBody) {
|
|
|
logger.info("云联学生信息同步接口");
|
|
|
logger.info("请求URL:"+ url);
|
|
|
logger.info("请求Body:"+ jsonBody);
|
|
@@ -131,7 +84,14 @@ public class SyncStudentInfoService {
|
|
|
HttpResponse execute = httpRequest.execute();
|
|
|
String result = execute.body();
|
|
|
logger.info("请求结果:"+ result);
|
|
|
- return result;
|
|
|
+ TulinInfoSyncLog tulinInfoSyncLog = new TulinInfoSyncLog();
|
|
|
+ tulinInfoSyncLog.setRequestUrl(url);
|
|
|
+ tulinInfoSyncLog.setResultBody(result);
|
|
|
+ tulinInfoSyncLog.setCreateTime(new Date());
|
|
|
+ tulinInfoSyncLog.setUpdateTime(new Date());
|
|
|
+ tulinInfoSyncLog.setSendBody(jsonBody);
|
|
|
+ tulinInfoSyncLog.setResult(containsOk(result));
|
|
|
+ return tulinInfoSyncLog;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -179,4 +139,11 @@ public class SyncStudentInfoService {
|
|
|
return System.currentTimeMillis() / 1000;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断结果是否成功
|
|
|
+ */
|
|
|
+ private static int containsOk(String resultStr) {
|
|
|
+ return resultStr.contains("ok")? 1 : 0;
|
|
|
+ }
|
|
|
+
|
|
|
}
|