Java秒杀数字藏品并推送微信消息
1.依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.26</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.11</version>
</dependency>
2.微信推送准备工作
关注公众号
记录下自己的token
3.编写代码
秒杀类,用于秒杀藏品,两种钱包,所以重复了两次 比较随意见谅
public class MFeng {
public static void killProduct(String price,String id,String num){
String body = HttpRequest.post("https://www.mfeng.art/api/v1/nft/order/batch/market")
.body("{\"id\":\""+id+"\",\"maxPrice\":\""+price+"\",\"qty\":\""+num+"\",\"walletId\":2}")
.header("X-Auth-Token", "")
.execute().body();
String message = null;
try {
message = (String) JSONObject.parseObject(body)
.get("message");
} catch (Exception e) {
throw new RuntimeException(e);
}
System.out.println("message = " + message);
if (message.contains("操作成功")) {
PushMessage.pushMessage("","蜜蜂抢购",id.concat(" 抢购成功 ").concat(num).concat(" 个"));
}
body = HttpRequest.post("https://www.mfeng.art/api/v1/nft/order/batch/market")
.body("{\"id\":\""+id+"\",\"maxPrice\":\""+price+"\",\"qty\":\""+num+"\",\"walletId\":1}")
.header("X-Auth-Token", "")
.execute().body();
try {
message = (String) JSONObject.parseObject(body)
.get("message");
} catch (Exception e) {
throw new RuntimeException(e);
}
System.out.println("message = " + message);
if (message.contains("操作成功")) {
PushMessage.pushMessage("1eb175de899047369c8d42dd0c7529ef","蜜蜂抢购",id.concat(" 抢购成功 ").concat(num).concat(" 个"));
}
}
}
推送类,用于抢购后推送微信消息
//推送消息到微信
public class PushMessage {
public static String pushMessage(String token, String title, String message) {
HashMap<String, String> bodyMap = new HashMap<>();
if (!title.isEmpty()) {
bodyMap.put("title", title);
}
bodyMap.put("content", message);
String body = HttpRequest.post("http://www.pushplus.plus/send/" + token)
.body(JSON.toJSONString(bodyMap))
.execute().body();
return body;
}
}
4.效果
最终当抢购成功后,就会及时发送消息推送给个人微信