|
|
|
@ -1,10 +1,14 @@ |
|
|
|
|
package com.cjy.back.ybsjAppointment.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.cjy.back.ybsjAppointment.entity.vo.GetAppointmentRecordVO; |
|
|
|
|
import com.cjy.back.ybsjAppointment.entity.vo.ReservationNowVO; |
|
|
|
|
import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentRecordService; |
|
|
|
|
import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentSettingService; |
|
|
|
|
import com.cjy.util.ServerResponse; |
|
|
|
|
import org.json.JSONArray; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
import org.junit.jupiter.api.extension.MediaType; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
@ -12,8 +16,17 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
import sun.net.www.http.HttpClient; |
|
|
|
|
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.net.URLConnection; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author liangjiawei |
|
|
|
@ -135,4 +148,95 @@ public class YbsjyAppletsAppointmentController { |
|
|
|
|
|
|
|
|
|
return ServerResponse.createBySuccess(ybsjyAppointmentRecordService.selectPop()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping("/getAccessToken") |
|
|
|
|
public ServerResponse getAccessToken(String appId, String appSecret) throws IOException { |
|
|
|
|
// 目标 URL
|
|
|
|
|
URL url = new URL("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret); |
|
|
|
|
// 打开连接
|
|
|
|
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
|
|
|
|
|
|
|
|
|
// 设置请求方法
|
|
|
|
|
conn.setRequestMethod("GET"); |
|
|
|
|
|
|
|
|
|
// 设置请求头
|
|
|
|
|
conn.setRequestProperty("Content-Type", "application/json"); |
|
|
|
|
|
|
|
|
|
// 获取响应
|
|
|
|
|
int responseCode = conn.getResponseCode(); |
|
|
|
|
System.out.println("Response Code: " + responseCode); |
|
|
|
|
|
|
|
|
|
BufferedReader in = new BufferedReader( |
|
|
|
|
new InputStreamReader(conn.getInputStream())); |
|
|
|
|
String inputLine; |
|
|
|
|
StringBuilder response = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
while ((inputLine = in.readLine()) != null) { |
|
|
|
|
response.append(inputLine); |
|
|
|
|
} |
|
|
|
|
in.close(); |
|
|
|
|
|
|
|
|
|
// 输出响应内容
|
|
|
|
|
return ServerResponse.createBySuccess(response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// public static String uploadImage(String accessToken, File imageFile) throws IOException {
|
|
|
|
|
// String url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=" + accessToken + "&type=image";
|
|
|
|
|
// OkHttpClient client = new OkHttpClient();
|
|
|
|
|
// RequestBody body = new MultipartBody.Builder()
|
|
|
|
|
// .setType(MultipartBody.FORM)
|
|
|
|
|
// .addFormDataPart("media", imageFile.getName(),
|
|
|
|
|
// RequestBody.create(imageFile, MediaType.parse("image/*")))
|
|
|
|
|
// .build();
|
|
|
|
|
// Request request = new Request.Builder().url(url).post(body).build();
|
|
|
|
|
// try (Response response = client.newCall(request).execute()) {
|
|
|
|
|
// JSONObject result = new JSONObject(response.body().string());
|
|
|
|
|
// return result.getString("media_id"); // 返回永久素材ID
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
@RequestMapping("/createDraft") |
|
|
|
|
public ServerResponse createDraft(String accessToken, String title, String content, String thumbMediaId) throws IOException { |
|
|
|
|
String url = "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=" + accessToken; |
|
|
|
|
|
|
|
|
|
// 构建请求体
|
|
|
|
|
JSONObject article = new JSONObject(); |
|
|
|
|
article.put("title", title); |
|
|
|
|
article.put("content", content); |
|
|
|
|
article.put("thumb_media_id", thumbMediaId); |
|
|
|
|
article.put("need_open_comment", 0); |
|
|
|
|
|
|
|
|
|
JSONArray articles = new JSONArray(); |
|
|
|
|
articles.put(article); |
|
|
|
|
JSONObject requestBody = new JSONObject().put("articles", articles); |
|
|
|
|
|
|
|
|
|
// 创建连接
|
|
|
|
|
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); |
|
|
|
|
conn.setRequestMethod("POST"); |
|
|
|
|
conn.setRequestProperty("Content-Type", "application/json"); |
|
|
|
|
conn.setDoOutput(true); |
|
|
|
|
|
|
|
|
|
// 发送请求
|
|
|
|
|
try (OutputStream os = conn.getOutputStream()) { |
|
|
|
|
os.write(requestBody.toString().getBytes("UTF-8")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理响应
|
|
|
|
|
int responseCode = conn.getResponseCode(); |
|
|
|
|
if (responseCode != HttpURLConnection.HTTP_OK) { |
|
|
|
|
throw new IOException("HTTP error code: " + responseCode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try (BufferedReader br = new BufferedReader( |
|
|
|
|
new InputStreamReader(conn.getInputStream(), "UTF-8"))) { |
|
|
|
|
StringBuilder response = new StringBuilder(); |
|
|
|
|
String line; |
|
|
|
|
while ((line = br.readLine()) != null) { |
|
|
|
|
response.append(line); |
|
|
|
|
} |
|
|
|
|
JSONObject result = new JSONObject(response.toString()); |
|
|
|
|
return result.getString("media_id"); |
|
|
|
|
} finally { |
|
|
|
|
conn.disconnect(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|