API接口
彩信产品,代码示例,乐信
代码示例
彩信接口代码示例
ASP
mms_include.asp 文件
<%
Function Int2S(intp)
    rs = ""
    for i = 0 to 3 
    rs = rs & CHRw(intp AND 255)
    intp = RShift(intp, 8)
    next
    Int2S = rs  
End Function
Function Post(url,data)
    dim Https 
    set Https=server.createobject("MSXML2.XMLHTTP")
    Https.open "POST",url,false
    Https.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    Https.setRequestHeader "Content-Length",LEN(data)
    Https.setRequestHeader "SOAPAction", "http://MmsWebInterface.org/SubmitMms"
    Https.send (data)
    
    if Https.readystate=4 then
        dim objstream 
        set objstream = Server.CreateObject("adodb.stream")
        objstream.Type = 1
        objstream.Mode =3
        objstream.Open
        objstream.Write Https.responseBody
        objstream.Position = 0
        objstream.Type = 2
        objstream.Charset = "utf-8"
        Post = objstream.ReadText
        objstream.Close
        set objstream = nothing
        set https=nothing
        
    end if
End Function
Function ReadBinaryFile(FileName)'二进制获取元素内容 
     Const adTypeBinary = 1   
     'Create Stream object   
     Dim BinaryStream   
     Set BinaryStream = CreateObject("ADODB.Stream")   
     'Specify stream type - we want To get binary data.   
     BinaryStream.Type = adTypeBinary          
     'Open the stream  
     'BinaryStream.Charset = "gb2312"  
     BinaryStream.Open           
     'Load the file data from disk To stream object   
     BinaryStream.LoadFromFile FileName          
     'Open the stream And get binary data from the object   
     ReadBinaryFile = BinaryStream.Read 
End Function
Function ReadTextFile(FileName)'二进制获取元素内容 
      Const adTypeText = 2 
      Const adTypeBinary = 1   
     'Create Stream object   
     Dim BinaryStream   
     Set BinaryStream = CreateObject("ADODB.Stream")   
     'Specify stream type - we want To get binary data.   
     BinaryStream.Type = 2          
     'Open the stream  
     BinaryStream.Charset = "iso-8859-15"  
     BinaryStream.Open           
     'Load the file data from disk To stream object   
     BinaryStream.LoadFromFile FileName          
     'Open the stream And get binary data from the object   
     ReadTextFile = BinaryStream.ReadText
End Function
Function Stream_ToBinary(arr) 
      Const adTypeText = 2 
      Const adTypeBinary = 1 
      Dim name,f_name,file_len,data 
      Dim BinaryStream 'As New Stream 
      Set BinaryStream = CreateObject("ADODB.Stream") 
          
            BinaryStream.Type = 2 
            BinaryStream.Open 
            BinaryStream.Charset ="iso-8859-15" '"windows-1252"
                for i=0 to Ubound(arr)
                       file_name=Server.MapPath("mmsfile/"&arr(i))
                       name=mid(file_name,instrrev(file_name,"\")+1) '元素1名称(即元素1的文件名,包括文件名后缀)   
                       f_name=name&chr(0) '元素1名称(即元素1的文件名,包括文件名后缀)+一个字符串结束符
                       data =ReadTextFile(file_name)
                       file_len=(int)(len(data))                         
                       BinaryStream.WriteText f_name
                       BinaryStream.WriteText Int2S(Clng(file_len))
                       BinaryStream.WriteText data
                next
        BinaryStream.Position = 0
        BinaryStream.SaveToFile Server.MapPath("mmsfile\tms.tms"),2
        BinaryStream.Type = adTypeBinary            
      Stream_ToBinary = BinaryStream.Read 
     'Stream_ToBinary=Clng((int)(len(data)))
      Set BinaryStream = Nothing 
End Function 
Function Base64Encode(Binarystream)
    Dim oXML, oNode
    Set oXML = CreateObject("Msxml2.DOMDocument.3.0") 
    Set oNode = oXML.CreateElement("base64") 
    oNode.dataType = "bin.base64" 
    oNode.nodeTypedValue =Binarystream
    Base64Encode = oNode.text'Mid(oNode.text,5) 
    Set oNode = Nothing 
    Set oXML = Nothing 
End Function 
' 按位左移
Public Function LShift(ByVal val, ByVal n)
    LShift = val * 2 ^ n
End Function
' 按位右移
Public Function RShift(ByVal val, Byval n) 
    RShift = val \ (2 ^ n)
End Function
%>

mms.asp 文件
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%
dim file_name,tmsdata,strbase64,target,post_data
strpath="99338.jpg"&","&"test.txt"&","&"wee.smil"'要发送的彩信文件列表
arr=split(strpath,",")
'res=Stream_ToBinary(arr)
Dim objFSO         '声明一个名称为   objFSO   的变量以存放对象实例   
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If  objFSO.FileExists(Server.MapPath("mmsfile/Tms.tms"))   Then 
'接口提交部分
    strbase64=Base64Encode(ReadBinaryFile(Server.MapPath("mmsfile/Tms.tms")))'获取生成的TMS文件
    target = "http://cf.51welink.com/submitdata/MmsWebInterface.asmx"  '彩信接口地址,以接口文档里的地址为准
    strxml =  ""
    strxml = strxml + ""
    strxml = strxml + ""
    strxml = strxml +""
    strxml = strxml +"dlzyang0"
    strxml = strxml +"123"
    strxml = strxml +""
    strxml = strxml +"2012128"
    strxml = strxml +""
    strxml = strxml +"彩信测试标题"
    strxml = strxml +""&strbase64&""
    strxml = strxml +""
    strxml = strxml +""
    strxml = strxml +""                 
    'response.Write strxml
    response.Write(Post(target,strxml))
''//请自己解析Post(target,post_data)返回的XML字符串并实现自己的逻辑
''0表示成功,其它的参考文档
else
        Response.Write "生成TMS文件出错,请检查!"
End If
%>
                
Delphi
Unit2.pas
unit Unit2;
interface
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns,classes;
type
MyWebServericeSoap = interface(IInvokable)
    ['{5BA22C24-B55B-44D5-63A4-623BCC4101FC}']
    
    function  SubmitMms(const UserID: WideString; const Password: WideString; const CorpID: WideString; const PrdID: WideString; const DstID: WideString; const MmsSubject: WideString; TmsBuffer: TByteDynArray): WideString; stdcall;
  end;
function GetMyWebServericeSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): MyWebServericeSoap;
implementation
function GetMyWebServericeSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): MyWebServericeSoap;
const
  defWSDL = 'http://cf.51welink.com/submitdata/MmsWebInterface.asmx?wsdl';
  defURL  = 'http://cf.51welink.com/submitdata/MmsWebInterface.asmx';
  defSvc  = 'Unit2';
  defPrt  = 'MyWebServericeSoap';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as MyWebServericeSoap);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
    //
    RIO.HTTPWebNode.UseUTF8InHeader:=True;
    //
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;
initialization
  InvRegistry.RegisterInterface(TypeInfo(MyWebServericeSoap), 'http://MmsWebInterface.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(MyWebServericeSoap), 'http://MmsWebInterface.org/%operationName%');
  InvRegistry.RegisterInvokeOptions(TypeInfo(MyWebServericeSoap), ioDocument);
end.

关键调用代码
var
i:integer; tstr:string; ilen:integer;sendstr:string;filename:string; ch:char;
begin
  ch := chr(0);
  MemBuffer:=TMemoryStream.Create;
  for i:=0 to Form1.ControlCount-1 do
  begin
    if(Form1.Controls[i].ClassName = 'TMemo') then
    begin
      tstr := trim(TMemo(Form1.Controls[i]).Text);
      if(Length(tstr)>0) then
      begin
        filename:=ExtractFileName(tstr);
        MemBuffer.WriteBuffer(filename[1],Length(filename));
        MemBuffer.Write(ch,1);
        fs:=TFileStream.Create(tstr,fmOpenRead);
        ilen:=integer(fs.Size);
        MemBuffer.Write(ilen,sizeof(ilen));
        MemBuffer.CopyFrom(fs,fs.Size);
        fs.Free;
      end;
    end;
  end;
    MemBuffer.Position := 0;
    setLength(ByteBuffer,MemBuffer.Size);
    for i:=0 to MemBuffer.Size-1 do
    begin
      MemBuffer.Read(ByteBuffer[i],1);
    end;
  Memo1.Text:=Unit2.GetMyWebServericeSoap(false,'http://cf.51welink.com/submitdata/MmsWebInterface.asmx').SubmitMms('账号','密码','','2012128',edit1.Text,'飞机',ByteBuffer);
  MemBuffer.Clear;
  MemBuffer.Free;
end;
                
JAVA
package cn.umob.mms;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import sun.misc.BASE64Encoder;
/**
 *
 * @author umob.cn
 */
public class Send {
    public static String MMS(String postData, String postUrl) {
        try {
            //发送POST请求
            URL url = new URL(postUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
            conn.setRequestProperty("SOAPAction", "http://MmsWebInterface.org/SubmitMms");
            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 String PackMMS(String sname, String spwd, String scorpid, String sprdid, String tels, String title, byte[] mms) {
        StringBuilder sb = new StringBuilder();
        sb.append("");
        sb.append("" + sname + "");
        sb.append("" + spwd + "");
        sb.append("" + scorpid + "");
        sb.append("" + sprdid + "");
        sb.append("" + tels + "");
        sb.append("" + title + "");
        sb.append("" + new sun.misc.BASE64Encoder().encode(mms) + "");
        sb.append("");
        return sb.toString();
    }
    public static byte[] PackFile(String file) throws IOException {
        File f = new File(file);
        if (f.exists()) {
            String fileName = f.getName();
            int fileSize = (int) f.length();
            try {
                byte[] fileBytes = new byte[fileSize];
                byte[] filenameBytes = (fileName + '\0').getBytes();                         
                FileInputStream stream = new FileInputStream(file);
                DataInputStream ds = new DataInputStream(stream);
                for (int i = 0; i < fileSize; i++) {
                    fileBytes[i] = ds.readByte();
                }
                
                //4 表示文件的大小的int的byte大小
                int length = fileBytes.length + filenameBytes.length + 4;
                ByteBuffer buffer = ByteBuffer.allocate(length);
                buffer.put((fileName + '\0').getBytes());
                ByteBuffer bufferLength = ByteBuffer.allocate(4);
                bufferLength.order(ByteOrder.LITTLE_ENDIAN);
                bufferLength.putInt(fileSize);
                
                buffer.put(bufferLength.array());
                buffer.put(fileBytes);
                return buffer.array();
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            }
        }
        return null;
    }
}

前台调用
<%
    byte[] mmsImage = cn.umob.mms.Send.PackFile("D:/jworkspace/PostMMS/web/image.gif");
    byte[] mmsText = cn.umob.mms.Send.PackFile("D:/jworkspace/PostMMS/web/txt.txt");
    byte[] mmsSmil = cn.umob.mms.Send.PackFile("D:/jworkspace/PostMMS/web/wee.smil");
    ByteBuffer mmsBuffer = ByteBuffer.allocate(mmsImage.length + mmsText.length + mmsSmil.length);
    mmsBuffer.put(mmsImage);
    mmsBuffer.put(mmsText);
    mmsBuffer.put(mmsSmil);
    String PostData = cn.umob.mms.Send.PackMMS("kwsm", "kwsm", "", "2012128", "13910862579", "彩信标题", mmsBuffer.array());
    //out.println(PostData);
    String ret = cn.umob.mms.Send.MMS(PostData, "http://cf.51welink.com/submitdata/MmsWebInterface.asmx");
    out.println(ret);
    //请自己反序列化返回的字符串
%>
            
Asp.Net
HTTP调用方式
string tels = this.toList.Text.Trim();
//处理上传文件
HttpFileCollection fileColllection = HttpContext.Current.Request.Files;
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
List byteList = new List();
try
{
    for (int iFile = 0; iFile < fileColllection.Count; iFile++)
    {
        //检查文件扩展名字
        HttpPostedFile postedFile = fileColllection[iFile];
        string fileExtension;
        string fileName = System.IO.Path.GetFileName(postedFile.FileName);
        if (!string.IsNullOrEmpty(fileName))
        {
            fileExtension = System.IO.Path.GetExtension(fileName);
            strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "
"); strMsg.Append("客户端文件地址:" + postedFile.FileName + "
"); strMsg.Append("上传文件的文件名:" + fileName + "
"); strMsg.Append("上传文件的扩展名:" + fileExtension + "

"); string savePath = HttpContext.Current.Request.MapPath(".") + "/upload/" + fileName; postedFile.SaveAs(savePath); byteList.AddRange(PackFiles.PackFiles.MakeTmsContent(savePath)); } } } catch (System.Exception Ex) { } byte[] mmsData = new byte[byteList.Count]; byteList.CopyTo(mmsData); UTF8Encoding encoding = new UTF8Encoding(); SoapBase64Binary base64Binary = new SoapBase64Binary(mmsData); string postDataStrTpl = "{0}{1}{2}{3}{4}{5}{6}"; string postDataStr = string.Format(postDataStrTpl, sname, spwd, scorpid, sprdid, tels, "彩信title", base64Binary.ToString()); byte[] postData = encoding.GetBytes(postDataStr); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(SmsMmsWebService); myRequest.Method = "POST"; myRequest.ContentType = "text/xml; charset=utf-8"; myRequest.Headers.Add("SOAPAction", "http://MmsWebInterface.org/SubmitMms"); myRequest.ContentLength = postData.Length; Stream newStream = myRequest.GetRequestStream(); // Send the data. newStream.Write(postData, 0, postData.Length); newStream.Flush(); newStream.Close(); HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); if (myResponse.StatusCode == HttpStatusCode.OK) { StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); upfileMmsMsg.Text = reader.ReadToEnd(); //反序列化upfileMmsMsg.Text } upfileMsg.Text = strMsg.ToString(); Web服务调用方式(需要先引用Web服务) string tels = this.toList.Text.Trim(); //处理上传文件 HttpFileCollection fileColllection = HttpContext.Current.Request.Files; System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); List byteList = new List(); try { for (int iFile = 0; iFile < fileColllection.Count; iFile++) { //检查文件扩展名字 HttpPostedFile postedFile = fileColllection[iFile]; string fileExtension; string fileName = System.IO.Path.GetFileName(postedFile.FileName); if (!string.IsNullOrEmpty(fileName)) { fileExtension = System.IO.Path.GetExtension(fileName); strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "
"); strMsg.Append("客户端文件地址:" + postedFile.FileName + "
"); strMsg.Append("上传文件的文件名:" + fileName + "
"); strMsg.Append("上传文件的扩展名:" + fileExtension + "

"); string savePath = HttpContext.Current.Request.MapPath(".") + "/upload/" + fileName; postedFile.SaveAs(savePath); byteList.AddRange(PackFiles.PackFiles.MakeTmsContent(savePath)); } } } catch (System.Exception Ex) { } byte[] newArray = new byte[byteList.Count]; byteList.CopyTo(newArray); state = service.SubmitMms(sname, spwd, scorpid, sprdid, tels, "测试彩信", newArray); upfileMsg.Text = strMsg.ToString(); upfileMmsMsg.Text = "MsgID:" + state.MsgID + "
MsgState:" + state.MsgState + "
State:" + state.State;
PHP
<?php
function packFile($file_name) {
    if(is_file($file_name)) {
        $data = file_get_contents($file_name);
        return basename($file_name) . pack('C', '0') . pack('I', strlen($data)) . $data;
    }
    return null;
}
function craetePostData($sname, $spwd, $scorpid, $sprdid, $tels, $mms_title, $mms_data) {
    $postDataStr = "";
    $postDataStr .= "" . $sname . "";
    $postDataStr .= "" . $spwd . "";
    $postDataStr .= "" . $scorpid . "";
    $postDataStr .= "" . $sprdid . "";
    $postDataStr .= "" . $tels . "";
    $postDataStr .= "" . $mms_title . "";
    $postDataStr .= "" . base64_encode($mms_data) . "";
    $postDataStr .= "";
    return $postDataStr;
}
function Post($data, $target, $SOAPAction) {
    $url_info = parse_url($target);
    $httpheader = "POST " . $url_info['path'] . " HTTP/1.1\r\n";
    $httpheader .= "Host:" . $url_info['host'] . "\r\n";
    $httpheader .= "Content-Type:text/xml; charset=utf-8\r\n";
    $httpheader .= "SOAPAction:" . $SOAPAction . "\r\n";
    $httpheader .= "Content-Length:" . strlen($data) . "\r\n";
    $httpheader .= "Connection:close\r\n\r\n";
    //$httpheader .= "Connection:Keep-Alive\r\n\r\n";
    $httpheader .= $data;
    $fd = fsockopen($url_info['host'], 80);
    fwrite($fd, $httpheader);
    $gets = "";
    while(!feof($fd)) {
        $gets .= fread($fd, 128);
    }
    fclose($fd);
    return $gets;
}
?>
<?php
include_once('mms.php');
$target = "http://cf.51welink.com/submitdata/MmsWebInterface.asmx";
$SOAPAction = "http://MmsWebInterface.org/SubmitMms";
$data = packFile('./mmsfile/image.gif');//多个文件用"."连接起来就可以了
$data .= packFile('./mmsfile/txt.txt');//多个文件用"."连接起来就可以了
if($data != null) {
    //替换成自己的测试账号,参数顺序和wenservice对应
    $post_data = craetePostData('kwsm', 'kwsm', '', '108', '13910862579', 'mmstitle', $data);
    echo $gets = Post($post_data, $target, $SOAPAction);
    //请自己实现返回字符串解析和业务逻辑
}
?>
                
产品
短信验证码
语音验证码
智能短信
国际短信
物联网解决方案
公司
关于我们
公司动态
行业动态
荣誉资质
联系我们
帮助文档
API接口
下载
帮助
隐私条款
常见问题
合作伙伴
中国联通
中国移动
中国电信
联系我们
+86 400-969-6663
7*24小时全天候服务
support@lmobile.cn

乐信平台 短信验证码平台 中山网站建设 餐饮软件 手机归属地查询 广东数据中心 北京群发短信软件 郑州做网站公司 微信分销系统 样本印刷 雨林木风 WIFI设置 济南网站制作 深圳网站建设 win10系统下载 笔记本系统 制沙机 经典语录 追溯系统 防火窗 色差仪