forked from integrated_whb/integrated_whb
46 lines
1.6 KiB
Java
46 lines
1.6 KiB
Java
|
package com.zcloud.util;
|
||
|
|
||
|
import com.alibaba.fastjson.JSONObject;
|
||
|
import org.springframework.http.MediaType;
|
||
|
import org.springframework.web.reactive.function.BodyInserters;
|
||
|
import org.springframework.web.reactive.function.client.WebClient;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* @author fangjiakai
|
||
|
* @date 2023/03/08 14:51
|
||
|
*/
|
||
|
public class PushUtil {
|
||
|
static final String push_url="https://fc-mp-356b2575-7ebe-471b-b689-8fd2b9b6c518.next.bspapp.com/unipush";
|
||
|
|
||
|
public static void push(Object cid,String title,String content) {
|
||
|
Map<String,Object> requestBody = new HashMap<String,Object>();
|
||
|
requestBody.put("push_clientid", cid);
|
||
|
requestBody.put("title", title);
|
||
|
requestBody.put("content", content);
|
||
|
WebClient client = WebClient.create();
|
||
|
client.post()
|
||
|
.uri(push_url)
|
||
|
.contentType(MediaType.APPLICATION_JSON)
|
||
|
.body(BodyInserters.fromValue(new JSONObject(requestBody)))
|
||
|
.exchange()
|
||
|
.flatMap(response -> {
|
||
|
System.out.println("Status code: " + response.statusCode().value());
|
||
|
return response.bodyToMono(String.class);
|
||
|
})
|
||
|
.doOnSuccess(body -> {
|
||
|
System.out.println("Response body: " + body);
|
||
|
})
|
||
|
.doOnError(throwable -> {
|
||
|
System.out.println("Error occurred: " + throwable.getMessage());
|
||
|
})
|
||
|
.block();
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
push("99854f96e1a77229758e788f183ab29c","标题","内容");
|
||
|
}
|
||
|
}
|