-
PHP -
Java -
.NET(webform) -
.NET(winform) -
ASP -
PYTHON -
C++ -
Node.js -
VB -
PB
<? php /** ?*?Created?by?Zhongxinrongda. ?*?Date:?2017/3/3 ?*?Time:?14:34 *Function: Youyinet SMS interface class *Description: *The following code only provides simple functions to facilitate customer testing. If there are other requirements, the customer can change the code according to the actual situation. ?*/ class?smsApi{ ????/* *@ param string $sms_send_url SMS sending interface url *@ param string $sms_query_url SMS balance query interface url *@ param string $userid Enterprise ID *@ param string $account SMS account *@ param string $password Account password ?????*/ ????var?$sms_send_url=''; ????var?$sms_query_url=''; ????var?$userid=''; ????var?$account=''; ????var?$password=''; ????public?function?sendSms($mobile,$content,$sendTime=''){ ????????$post_data=array( ????????????'userid'=>$this->userid, ????????????'account'=>$this->account, ????????????'password'=>$this->password, ????????????'mobile'=>$mobile, ????????????'content'=>$content, 'sendTime '=>$sendTime//The sending time. If it is empty, it is sent immediately ????????); ????????$url=$this->sms_send_url; ????????$o=''; ????????foreach?($post_data?as?$k=>$v) ????????{ ????????????$o.="$k=".urlencode($v).'&'; ????????} ????????$post_data=substr($o,0,-1); ????????$ch?=?curl_init(); ????????curl_setopt($ch,?CURLOPT_POST,?1); ????????curl_setopt($ch,?CURLOPT_HEADER,?0); ????????curl_setopt($ch,?CURLOPT_URL,$url); ????????curl_setopt($ch,?CURLOPT_POSTFIELDS,?$post_data); ????????//curl_setopt($ch,?CURLOPT_RETURNTRANSFER,?1); //If you need to return the result directly to the variable, add this sentence. ????????$result?=?curl_exec($ch); ????????curl_close($ch); ????????return?$result; ????} }
package?com.zxrd.interfacej; import?java.io.BufferedReader; import?java.io.BufferedWriter; import?java.io.DataOutputStream; import?java.io.IOException; import?java.io.InputStreamReader; import?java.net. HttpURLConnection; import?java.net. URL; import?java.net. URLEncoder; /** *Youyinet SMS interface Java example ?* *@ param url application address, similar to //ip:port/sms.aspx *@ param userid User ID *@ param account account *@ param psword password *@ param mobile phone number, multiple numbers are separated by "," *@ param content SMS content *@ return Refer to the HTTP protocol document for the definition of the return value ?*?@throws?Exception ?*/ public?class?Sms?{ public?static?String?HTTPPost(String?sendUrl,?String?sendParam)?{ String?codingType?=?"UTF-8"; StringBuffer?receive?=?new?StringBuffer(); BufferedWriter?wr?=?null; try?{ //Establish a connection URL?url?=?new?URL(sendUrl); HttpURLConnection?URLConn?=?(HttpURLConnection)?url.openConnection(); URLConn.setDoOutput(true); URLConn.setDoInput(true); ((HttpURLConnection)?URLConn).setRequestMethod("POST"); URLConn.setUseCaches(false); URLConn.setAllowUserInteraction(true); HttpURLConnection.setFollowRedirects(true); URLConn.setInstanceFollowRedirects(true); URLConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); URLConn.connect(); DataOutputStream?dos?=?new?DataOutputStream(URLConn.getOutputStream()); dos.writeBytes(sendParam); BufferedReader?rd?=?new?BufferedReader(new?InputStreamReader( URLConn.getInputStream(),?codingType)); String?line; while?((line?=?rd.readLine())?!= ?null)?{ receive.append(line).append("\r\n"); } rd.close(); }?catch?(java.io.IOException?e)?{ Receive. append ("An exception was generated during the access -->"). append (e.getMessage()); e.printStackTrace(); }?finally?{ if?(wr?!=?null)?{ try?{ wr.close(); }?catch?(IOException?ex)?{ ex.printStackTrace(); } wr?=?null; } } return?receive.toString(); } //Send SMS public?static?String?send(String?sendUrl,?String?userid,?String?account, String?password,?String?mobile,?String?content)?{ String?codingType?=?"UTF-8"; StringBuffer?sendParam?=?new?StringBuffer(); try?{ sendParam.append("action=").append("send"); sendParam.append("&userid=").append(userid); sendParam.append("&account=").append(URLEncoder.encode(account,?codingType)); sendParam.append("&password=").append(URLEncoder.encode(password,?codingType)); sendParam.append("&mobile=").append(mobile); sendParam.append("&content=").append(URLEncoder.encode(content,?codingType)); }?catch?(Exception?e)?{ //Handling exceptions e.printStackTrace(); } return?Sms. HTTPPost(sendUrl,sendParam.toString()); } //Query balance public?static?String?Overage(String?sendUrl,?String?userid,?String?account, String?password)?{ String?codingType?=?"UTF-8"; StringBuffer?sendParam?=?new?StringBuffer(); try?{ sendParam.append("action=").append("overage"); sendParam.append("&userid=").append(userid); sendParam.append("&account=").append(URLEncoder.encode(account,?codingType)); sendParam.append("&password=").append(URLEncoder.encode(password,?codingType)); }?catch?(Exception?e)?{ //Handling exceptions e.printStackTrace(); } return?Sms. HTTPPost(sendUrl,sendParam.toString()); } public?static?String?url?=?" //ip:port/msg/ ";//Corresponding platform address public?static?String?userid?=?"0001"; //Customer id public?static?String?account?=?"xxxx"; //Account No public?static?String?password?=?"123456"; //Password public?static?String?mobile?=?"13000000000"; //Mobile phone number, multiple numbers are separated by "," Public static String content="Dear user, your verification code is: 123456 [your signature]"; //SMS content public?static?void?main(String[]?args)?{ //Send SMS String?sendReturn?=?Sms.send(url,?userid,?account,?password,?mobile,?content); System.out.println(sendReturn);// Processing return values, see the HTTP protocol document //Query balance String?overReturn?=?Sms. Overage(url,?userid,?account,?password); System.out.println(overReturn);// Processing return values, see the HTTP protocol document } }
//Method of sending SMS, phone: mobile number, content: SMS content public?static?void?smsSend(string?phone,string?content) ????????{ ????????????string?userid?=?"*";// Enterprise ID ????????????string?account?=?"*"; //User name ????????????string?password?=?"*"; //Password ????????????StringBuilder?sbTemp?=?new?StringBuilder(); //POST value transfer ????????????sbTemp. Append("action=send&userid="?+?userid?+?"&account="?+?account?+?"&password="?+?password?+?"&mobile="?+?phone?+?"&content="?+?content); ????????????byte[]?bTemp?=?System. Text. Encoding. GetEncoding("GBK"). GetBytes(sbTemp.ToString()); String postReturn=doPostRequest ("Request Address", bTemp); //Parse the returned XML data ?XmlDocument?xmlDoc?=?new?XmlDocument(); ????????????????xmlDoc. LoadXml(postReturn); ????????????????XmlNode?xmlNode?=?xmlDoc. SelectSingleNode("returnsms/returnstatus"); ????????????????string?value?=?xmlNode. FirstChild. Value; //Success indicates that the transmission is successful ????????} ????????private?static?String?doPostRequest(string?url,?byte[]?bData) ????????{ ????????????System. Net. HttpWebRequest?hwRequest; ????????????System. Net. HttpWebResponse?hwResponse; ????????????string?strResult?=?string.Empty; ????????????try ????????????{ ????????????????hwRequest?=?(System.Net.HttpWebRequest)System. Net. WebRequest. Create(url); ????????????????hwRequest. Timeout?=?5000; ????????????????hwRequest. Method?=?"POST"; ????????????????hwRequest. ContentType?=?"application/x-www-form-urlencoded"; ????????????????hwRequest. ContentLength?=?bData. Length; ????????????????System. IO.Stream?smWrite?=?hwRequest. GetRequestStream(); ????????????????smWrite. Write(bData,?0,?bData.Length); ????????????????smWrite. Close(); ????????????} ????????????catch?(System.Exception?err) ????????????{ ????????????????WriteErrLog(err.ToString()); ????????????????return?strResult; ????????????} ????????????//get?response ????????????try ????????????{ ????????????????hwResponse?=?(HttpWebResponse)hwRequest. GetResponse(); ????????????????StreamReader?srReader?=?new?StreamReader(hwResponse.GetResponseStream(),?Encoding. ASCII); ????????????????strResult?=?srReader. ReadToEnd(); ????????????????srReader. Close(); ????????????????hwResponse. Close(); ????????????} ????????????catch?(System.Exception?err) ????????????{ ????????????????WriteErrLog(err.ToString()); ????????????} ????????????return?strResult; ????????} ????????private?static?void?WriteErrLog(string?strErr) ????????{ ????????????Console. WriteLine(strErr); ????????????System. Diagnostics. Trace. WriteLine(strErr); ????????}
public??string?HttpPost(string?uri,?string?parameters) ????????{ ??????????? ????????????WebRequest?webRequest?=?WebRequest. Create(uri); ???????? ????????????webRequest. ContentType?=?"application/x-www-form-urlencoded"; ????????????webRequest. Method?=?"POST"; ????????????byte[]?bytes?=?Encoding. UTF8.GetBytes(parameters);// Here you need to specify the submitted code ????????????System. GC. Collect(); ????????????Stream?os?=?null; ????????????try ????????????{?//?send?the?Post ????????????????webRequest. ContentLength?=?bytes. Length; ???//Count?bytes?to?send ????????????????os?=?webRequest. GetRequestStream(); ????????????????os. Write(bytes,?0,?bytes.Length); ?????????//Send?it ????????????????os. Flush(); ????????????????os. Close(); ????????????} ????????????catch?(WebException?ex) ????????????{ ????????????????MessageBox. Show(ex.Message,?"HttpPost:?Request?error", ???????????????????MessageBoxButtons. OK,?MessageBoxIcon. Error); ????????????} ?????????? ????????????try ????????????{?//?get?the?response ????????????????WebResponse?webResponse?=?webRequest. GetResponse(); ????????????????if?(webResponse?==?null) ????????????????{?return?null;?} ????????????????StreamReader?sr?=?new?StreamReader(webResponse.GetResponseStream(),?System. Text. Encoding. UTF8); //In the above sentence, you need to specify the returned code as the default ????????????????return?sr. ReadToEnd(). Trim(); ? ????????????} ????????????catch?(WebException?ex) ????????????{ ????????????????MessageBox. Show(ex.Message,?"HttpPost:?Response?error", ???????????????????MessageBoxButtons. OK,?MessageBoxIcon. Error); ????????????} ???????? ????????} ??????private?void?button3_Click(object?sender,?EventArgs?e) ????????{ ?????????????string?url=""; ?????????????string?userid=""; ?????????????string?account=""; ?????????????string?password=""; ????????????if?(checkBox1.Checked) {//Send regularly ????????????????textBox3.Text?=?HttpPost(url,?"action=send&userid="+userid+"&account="+account+"&password="+password+"&content=" +TextBox2. Text+"&mobile="+textBox1. Text+"&sendtime="//Capital HH means 24-hour time ???????????????????????+?dateTimePicker1.Value. ToString("yyyy-MM-dd")?+"?"+?dateTimePicker2.Value. ToString("HH:mm:ss")); ????????????} ????????????else {//Send immediately ????????????????textBox3.Text?=?HttpPost(url,?"action=send&userid="+userid+"&account="+account+"&password="+password+"&content=" ????????????????????+?textBox2.Text?+?"&mobile="?+?textBox1.Text?+?"&sendtime="); ????????????} ????????}
<% Function?getHTTPPage(url) Dim?Http Set?Http?=?Server. CreateObject("MSXML2.XMLHTTP") Http. Open?"Get",?url,?False Http.send() If?Http.readystate?<>?4?Then Exit?Function End?If getHTTPPage?=?BytesToBstr(Http.responseBody,?"UTF-8") Set?Http?=?Nothing If?Err. Number?<>?0?Then?Err. Clear End?Function Function?BytesToBstr(body,?Cset) Dim?objstream Set?objstream?=?Server. CreateObject("adodb.stream") objstream. Type?=?1 objstream. Mode?=?3 objstream. Open objstream. Write?body objstream. Position?=?0 objstream. Type?=?2 objstream. Charset?=?Cset BytesToBstr?=?objstream. ReadText objstream. Close Set?objstream?=?Nothing End?Function Response. write getHTTPPage ("Request address? Action=send&userid=enterprise ID&account=account&password=password&mobile=mobile phone number&content=content&sendTime=&extno=") %>
#?-*-?coding:?utf-8?-*- #Special attention: remove the "<>" symbol when transferring parameters! import?requests; import?json; def?send_messag_example(): Resp=requests. post ("<interface address>"), ????data={ "action":?"send", "Userid": "<enterprise id>", "Account": "<Customer user name>", "Password": "<Customer Password>", "Mobile": "<mobile number>", "Content": "<SMS content>", "type":?"json" ????},timeout=3?,?verify=False); ????result?=??json.loads(?resp.content?) ????print?result if?__name__?==?"__main__": ????send_messag_example(); #Note: When the above parameters are passed in, the "<>" symbol is not included
#define?MAXLINE?4096 #define?MAXSUB??2000 #define?MAXPARAM?2048 char?*hostname?=?"123.59.105.84";// Corresponding server IP ? /** ** Send http post request ?*?*/ ssize_t?http_post(char?*poststr) { ????char?sendline[MAXLINE?+?1],?recvline[MAXLINE?+?1]; ????ssize_t?n; ????snprintf(sendline,?MAXSUB, ????????"POST?%s?HTTP/1.0\r\n" "Host: URL r n"//URL request address ????????"Content-type:?application/x-www-form-urlencoded\r\n" ????????"Content-length:?%zu\r\n\r\n" ????????"%s",?strlen(poststr),?poststr); ????write(sockfd,?sendline,?strlen(sendline)); ????printf("\n%s",?sendline); ????printf("\n--------------------------\n"); ????while?((n?=?read(sockfd,?recvline,?MAXLINE))?>?0)?{ ????????recvline[n]?=?'\0'; ????????printf("%s\n",?recvline); ????} ????return?n; } ** Send SMS ?*?*/ ssize_t?send_sms(char?*account,?char?*password,?char?*mobile,?char?*content) { ????char?params[MAXPARAM?+?1]; ????char?*cp?=?params; ? ????sprintf(cp,"action=send&userid=%s&account=%s&password=%s&mobile=%s&content=%s",?userid,?account,?password,?mobile,?content); ??? ? ????return?http_post(cp); } ? int?main(void) { ????struct?sockaddr_in?servaddr; ????char?str[50]; ? //Establish socket connection ????sockfd?=?socket(AF_INET,?SOCK_STREAM,?0); ????bzero(&servaddr,?sizeof(servaddr)); ????servaddr.sin_addr.s_addr?=?inet_addr(hostname); ????servaddr.sin_family?=?AF_INET; ????servaddr.sin_port?=?htons(80); ????inet_pton(AF_INET,?str,?&servaddr.sin_addr); ????connect(sockfd,?(SA?*)?&?servaddr,?sizeof(servaddr)); ? ? Char * userid="Enterprise ID" Char * account="Account No."; Char * password="Password"; Char * mobile="mobile phone number"; //Must be signed Char * msg="[Signature] Your verification code is 123400"; ? ????//get_balance(account,?password); ????send_sms(account,?password,?mobile,?content); ????close(sockfd); ????exit(0); }
var?http?=?require('http'); var?querystring?=?require('querystring'); var?postData?=?{ Action: 'send',//Send the task command and set it to a fixed value: send Userid: 'Enterprise ID', Account: 'User name', Password: 'Password', Mobile: 'Mobile number', Content: '[Signature] Your verification code is: 610912, valid within 3 minutes. If it is not your own operation, you can ignore this message. ', ????type:'json' }; var?content?=?querystring.stringify(postData); var?options?=?{ Host: 'domain name',//Do not add http before ????path:'/2/sms/send.html', ????method:'POST', ????agent:false, ????rejectUnauthorized?:?false, ????headers:{ ????????'Content-Type'?:?'application/x-www-form-urlencoded',? ????????'Content-Length'?:content.length ????} }; var?req?=?http.request(options,function(res){ ????res.setEncoding('utf8'); ????res.on('data',?function?(chunk)?{ ????????console.log(JSON.parse(chunk)); ????}); ????res.on('end',function(){ ????????console.log('over'); ????}); }); req.write(content); req.end();
Public Function getHtmlStr (strUrl As String) 'Get the remote interface function On?Error?Resume?Next Dim?XmlHttp?As?Object,?stime,?ntime Set?XmlHttp?=?CreateObject("Microsoft.XMLHTTP") XmlHttp.open?"GET",?strUrl,?True XmlHttp.send Stime=Now 'Get the current time While?XmlHttp. ReadyState?<>?4 DoEvents Time=Now 'Get cycle time If?DateDiff("s",?stime,?ntime)?>?3?Then?getHtmlStr?=?"":?Exit?Function Wend getHtmlStr?=?StrConv(XmlHttp.responseBody,?vbUnicode) Set?XmlHttp?=?Nothing End?Function Code use: write the following code in the corresponding position of the form code dim?a?as?string A=getHtmlStr ("url? Action=send&userid=enterprise ID&account=account&password=password&mobile=mobile phone number&content=content&sendTime=&extno=) 'Get interface return value
Create an object n_ir_msgbox, inherited from internetresult, and directly return 1 in the internetdata function (this step is critical, and there must be a return value) Create a window to define the instance variable n_ir_msgbox iir_msgbox Add button. In the click event: inet?linet_base? String?ls_url integer?li_rc iir_msgbox?=?CREATE?n_ir_msgbox if?GetContextService("Internet",?linet_base)?=?1?THEN Ls_url="URL? Action=send&userid=enterprise ID&account=account&password=password&mobile=mobile phone number&content=SMS content" ? ?li_rc?=?linet_base. GetURL(ls_url,?iir_msgbox) ??? END?IF DESTROY?iir_msgbox