云信 短信发送 demo

Posted bowei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了云信 短信发送 demo相关的知识,希望对你有一定的参考价值。

package com.dataTaskListener;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

//全文模板发送
public class SendMsg{
    public static String  sendMSM(String phone,String number){
        try {                    
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod("http://api.sms.cn/sms/"); 
            post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
            NameValuePair[] data ={ new NameValuePair("ac", "send"),new NameValuePair("uid", ""),new NameValuePair("pwd", ""),new NameValuePair("mobile",phone),
                     new NameValuePair("encode","utf8"),new NameValuePair("template",""),new NameValuePair("content","{\"number\":\""+number+"\"}")}; post.setRequestBody(data); client.executeMethod(post); Header[] headers = post.getResponseHeaders(); int statusCode = post.getStatusCode(); //System.out.println("statusCode:"+statusCode); for(Header h : headers){ //System.out.println(h.toString()); } String result = new String(post.getResponseBodyAsString().getBytes("utf-8")); //返回信息 //System.out.println(result); //打印返回消息状态 post.releaseConnection(); return result; } catch (Exception e) { e.printStackTrace(); } return null; } }

 


以上是关于云信 短信发送 demo的主要内容,如果未能解决你的问题,请参考以下文章

网易云信,发送验证码短信C#版代码

网易云信Web IM搭建(Demo)

vue如何对接网易云信IM即时聊天

vue如何对接网易云信IM即时聊天

vue如何对接网易云信IM即时聊天

vue如何对接网易云信IM即时聊天