分割 @param content 短信内容 @return 返回值定义参见HTTP协议文档 @throws Excep
标签:
PHP 代码实例<?php
/**
Created by Zhongxinrongda.
Date: 2017/3/3
Time: 14:34
成果:云信通企业信使短信接口类
说明:
一下代码只是供给简单的成果,便利客户的测试,如有其他需求,客户可按照实际自行变动代码。
/
class smsApi{
/*
@param string $sms_send_url 短信发送接口url
@param string $sms_query_url 短信余额盘问接口url
@param string $userid 企业id
@param string $account 短信账户
@param string $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 //发送时间,为空是即时发送
);
$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); //如果需要将功效直接返回到变量里,那加上这句。
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
Java 代码实例
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;
/**
云信通企业信使短信接口Java示例
@param url 应用地点,类似于:port/sms.aspx
@param userid 用户ID
@param account 账号
@param pssword 暗码
@param mobile 手机号码,多个号码使用","支解
@param content 短信内容
@return 返回值界说参见HTTP协议文档
@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 {
//成立连接
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();
}
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/35400.html