Java秒杀数字藏品并推送微信消息

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.微信推送准备工作

关注公众号 image-20230506094147202

image-20230506094211437

image-20230506094228046

image-20230506094242958

记录下自己的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.效果

最终当抢购成功后,就会及时发送消息推送给个人微信

image-20230506094536160

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秋日的晚霞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值