使用007idc的短信包api发送短信

在官网购买短信包

点击进入007idc官网进行注册并实名认证:https://www.007idc.cn/aff/PYRWUYMH

短信服务套餐:https://www.007idc.cn/cart?fid=98&gid=167

查看短信包详情、获取API地址

进入控制台查看,购买完成若长时间未开通可以提交工单给客服开通

7a4788c59b7af75fe86ec534a61a175e

进入短信包管理页面

eef201c12df5305de93701dcd7517215

可以进入网页端手动发送信息,但此处主要是说使用api发送

关于api的调用,官方也给出了说明文档:https://course.007idc.cn/dxdj,但是此处的地址并不能直接使用

c45c5bd2f68070f6aa88e52354af32a3

点击这个地址进入新的页面

image-20240806140127491

此处浏览器地址栏的地址才是我们真正要用到的地址:http://8.130.73.63:9090/sms/batch/v1

调用API群发短信

我已经根据官方给的教程中的代码稍微修改放在此处(使用Java)

首先Maven引入依赖

<dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.13</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.75</version> <!-- 请使用最新版本 -->
    </dependency>
</dependencies>

SmsApi.java

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class SmsApi {

    public static void send(
            String appKey, String appCode, String appSecret, String phone, String msg
    ) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        send(appKey, appCode, appSecret, phone, msg, System.currentTimeMillis() + "", "", "");
    }

    public static void send(
            String appKey, String appCode, String appSecret, String phone, String msg, String timestamp
    ) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        send(appKey, appCode, appSecret, phone, msg, timestamp, "", "");
    }

    public static void send(
            String appKey, String appCode, String appSecret, String phone, String msg, String timestamp,
            String uid, String extend
    ) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        HttpClient httpClient = null;
        HttpPost httppost = null;
        try {
            httpClient = new DefaultHttpClient();
            httppost = new HttpPost("http://8.130.73.63:9090/sms/batch/v1");
            Map<String, String> map = new HashMap<>();
            map.put("appkey", appKey);
            map.put("appcode", appCode);
            map.put("sign", md5(appKey + appSecret + timestamp));
            if (!Objects.equals(uid, "")) map.put("uid", uid);
            map.put("phone", phone);
            map.put("msg", msg);
            map.put("timestamp", timestamp);
            if (!Objects.equals(extend, "")) map.put("extend", extend);
            String json = JSONObject.toJSONString(map);
            StringEntity formEntity = new StringEntity(json, "utf-8");
            httppost.setEntity(formEntity);
            HttpResponse httpresponse = null;
            httpresponse = httpClient.execute(httppost);
            HttpEntity httpEntity = httpresponse.getEntity();
            String response = EntityUtils.toString(httpEntity, "utf-8");
            System.out.println(response);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (httppost != null) {
                httppost.abort();
            }
            if (httpClient != null) {
                httpClient.getConnectionManager().shutdown();
            }
        }
    }

    private static String md5(String param) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] md5Byte = md5.digest(param.getBytes("utf8"));
        String result = byteToHex(md5Byte);
        return result;
    }

    private static String byteToHex(byte[] md5Byte) {
        String result = "";
        StringBuilder sb = new StringBuilder();
        for (byte each : md5Byte) {
            int value = each & 0xff;
            String hex = Integer.toHexString(value);
            if (value < 16) {
                sb.append("0");
            }
            sb.append(hex);
        }
        result = sb.toString();
        return result;
    }

    public static int byte4ToInteger(byte[] b, int offset) {
        return (0xff & b[offset]) << 24 | (0xff & b[offset + 1]) << 16 |
                (0xff & b[offset + 2]) << 8 | (0xff & b[offset + 3]);
    }
}

Main.java

public class Main {
    public static void main(String[] args) throws Exception {
        SmsApi.send(
                "登录账号", // 购买短信包时填写的账号
                "1000", // 默认固定1000
                "登录密码", // 购买短信包时填写的密码
                "手机号码", // 目标手机号,多个手机号使用半角英文逗号隔开
                "短信内容"
        );
    }
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇