2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 手机短信验证码发送(106短信验证码发送)

手机短信验证码发送(106短信验证码发送)

时间:2020-11-25 00:12:29

相关推荐

手机短信验证码发送(106短信验证码发送)

打开网页地址栏输入:/

需要用户注册,登陆,在上边购买短信,大概是10块钱100条,

买完之后可以直接下载接口说明文档和源代码的案例,是个压缩包 cu-fa-jie-kou.rar

压缩包解压打开之后如下图,一个短信接口说明文档,两个代码文件夹一个是GBK格式的,一个是UTF-8格式的:

JAVA-----UTF-8代码如下

package com.baizhi;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import .HttpURLConnection;import .URL;/*** * 短信验证码发送* @author Administrator*/public class Send {public static String SMS(String postData, String postUrl) {try {//发送POST请求URL url = new URL(postUrl);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestMethod("POST");conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");conn.setRequestProperty("Connection", "Keep-Alive");conn.setUseCaches(false);conn.setDoOutput(true);conn.setRequestProperty("Content-Length", "" + postData.length());OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");out.write(postData);out.flush();out.close();//获取响应状态if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {System.out.println("connect failed!");return "";}//获取响应内容体String line, result = "";BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));while ((line = in.readLine()) != null) {result += line + "\n";}in.close();return result;} catch (IOException e) {e.printStackTrace(System.out);}return "";}public static void main(String[] args) throws InterruptedException {String sms = SMS("account=NABOBOAN&password=aaa&mobile=13341565444&content=您的验证码是:chenyu。如需帮助请联系客服。", "/utf8/sms.aspx");System.out.println("======"+sms); }}

从新封装,测试使用,

public void SMSA(String mobile){//获取随机数的方法VerifyCodeUtil verifyCodeUtil = new VerifyCodeUtil();String imgCode = verifyCodeUtil.generateVerifyCode(6);//打印随机字符System.out.println(imgCode);System.out.println("mobile="+mobile);String str ="account=ZHANGCN&password=aaa15438679&mobile="+mobile+"&content=您的验证码是:"+imgCode+"。如需帮助请联系客服。";String sms = SMS(str, "/utf8/sms.aspx");System.out.println("======"+sms);}@Testpublic void TestSMS(){SMSA("15010729294");}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。