溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

java短信接口怎么用

發(fā)布時(shí)間:2022-01-18 10:47:54 來源:億速云 閱讀:101 作者:iii 欄目:建站服務(wù)器

本文小編為大家詳細(xì)介紹“java短信接口怎么用”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“java短信接口怎么用”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識吧。

短信發(fā)送接口

1.1 請求地址

請求地址是客戶接口程序調(diào)用時(shí)請求的url地址,采用的是https post 接口,地址是

https://sh3.ipyy.com/sms.aspx 對應(yīng)UTF-8

https://sh3.ipyy.com/smsGBK.aspx 對應(yīng)GB2312

https://sh3.ipyy.com/smsJson.aspx 對應(yīng)UTF-8(返回值為json格式)

https://sh3.ipyy.com/ensms.ashx 對應(yīng)UTF-8(加密傳輸,使用json)

入口地址一般不會(huì)發(fā)生變化,當(dāng)發(fā)生變化的時(shí)候,會(huì)通知接口用戶

1.2參數(shù)說明

參數(shù)名稱

含義

說明

userid

企業(yè)id

企業(yè)ID(不驗(yàn)證)

account

發(fā)送用戶帳號

用戶帳號,由系統(tǒng)管理員

password

發(fā)送帳號密碼

用戶賬號對應(yīng)的密碼

可以使用明文,也可以全用md5加密方式,md5采用32位大寫

如abc123加密后為

E99A18C428CB38D5F260853678922E03

mobile

全部被叫號碼

短信發(fā)送的目的號碼.多個(gè)號碼之間用半角逗號隔開 

content

發(fā)送內(nèi)容

短信的內(nèi)容,內(nèi)容需要UTF-8編碼,提交內(nèi)容格式:內(nèi)容+【簽名】。簽名是公司的名字或者公司項(xiàng)目名稱。示例:您的驗(yàn)證碼:1439【騰飛】?!尽渴呛灻臉?biāo)識符。請按照正規(guī)的格式提交內(nèi)容測試

sendTime

定時(shí)發(fā)送時(shí)間

為空表示立即發(fā)送,定時(shí)發(fā)送格式2010-10-24 09:08:10

action

發(fā)送任務(wù)命令

設(shè)置為固定的:send

extno

擴(kuò)展子號

請先詢問配置的通道是否支持?jǐn)U展子號,如果不支持,請?zhí)羁?。子號只能為?shù)字,且最多5位數(shù)。

例如:

https://sh3.ipyy.com/sms.aspx?action=send&userid=&account=賬號&password=密碼&mobile=15023239810,13527576163&content=內(nèi)容&sendTime=&extno=

1.3返回值

在接收到客戶端發(fā)送的https請求后,返回以xml的方式返回處理結(jié)果。格式為:

<?xml version="1.0"  encoding="utf-8" ?>

<returnsms>

<returnstatus>status</returnstatus> ---------- 返回狀態(tài)值:成功返回Success 失敗返回:Faild

<message>message</message> ---------- 相關(guān)的錯(cuò)誤描述

<remainpoint> remainpoint</remainpoint> ---------- 返回余額

<taskID>taskID</taskID>  -----------  返回本次任務(wù)的序列ID

<successCounts>successCounts</successCounts> --成功短信數(shù):當(dāng)成功后返回提交成功短信數(shù)

</returnsms>

1.4 Json返回值

{"returnstatus":"Success",
"message":"操作成功",
"remainpoint":"-4",
"taskID":"1504080852350206",
"successCounts":"1"}

package com.yy.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.json.JSONObject;

import sun.misc.BASE64Encoder;

public class HttpEnsms {
    /**
     * http加密
     * @param args
     */
    public static void main(String[] args) {


        SimpleDateFormat df=new SimpleDateFormat("MMddHHmmss");        
        String Stamp = df.format(new Date());
        String password="123456";
        String Secret=MD5.GetMD5Code(password+Stamp).toUpperCase();
        
        try {
            JSONObject j=new JSONObject();
            j.put("UserName", "qq");
            j.put("Stamp", Stamp);
            j.put("Secret", Secret);
            j.put("Moblie", "17721077856");//可以call協(xié)助對接
            j.put("Text", "您的驗(yàn)證碼是:8859【華信】");
            j.put("Ext", "");
            j.put("SendTime", "");
            //獲取json字符串
            String json=j.toString();
            byte[] data=json.getBytes("utf-8");
            byte[] key=password.getBytes();
            //獲取加密的key
            byte[] nkey=new byte[8];
            System.arraycopy(key, 0, nkey, 0, key.length > 8 ? 8 : key.length);
            //Des加密,base64轉(zhuǎn)碼
            String str=new BASE64Encoder().encode(DesHelper.encrypt(data, nkey)); 
            
            System.out.println(str);
            //url編碼
            //str=URLEncoder.encode(str, "utf-8");
            
            //發(fā)送http請求
            String Url="http://42.96.205.165/ensms.ashx";
            HttpClient client=new HttpClient();
            PostMethod post=new PostMethod(Url);
            post.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
            NameValuePair UserId=new NameValuePair("UserId","1");
            NameValuePair Text64=new NameValuePair("Text64",str);
            post.setRequestBody(new NameValuePair[]{UserId,Text64});
            int statu=client.executeMethod(post);
            System.out.println("statu="+statu);
            //返回結(jié)果
            String result=post.getResponseBodyAsString();
            System.out.println("result="+result);


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }

}

讀到這里,這篇“java短信接口怎么用”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI