在数字化时代,信息传播的速度与效率成为了企业营销、客户服务及日常沟通中不可或缺的关键因素。随着移动通信技术的飞速发展,群发彩信作为一种集文字、图片、声音于一体的多媒体信息服务方式,正逐渐展现出其独特的优势,成为众多行业青睐的沟通工具。
支持免费对接试用:乐讯通PaaS平台 找好用的短信平台,选择乐讯通,短信群发|短信平台|群发短信软件|群发短信平台|乐讯通PaaS平台http://yun.loktong.com/login/register/0c61bafb77
<?php
header("Content-type: text/html; charset=utf-8");
/* 彩信发送demo */
$action = 'sendimagetext';
$url = 'http://www.lokapi.cn/smsUTF8.aspx';
$username = '******';
$password = strtoupper(md5('******'));
$token = '******';
$timestamp = getMillisecond();
$sign = strtoupper(md5('action=' . $action . '&username=' . $username . '&password=' . $password . '&token=' . $token . '×tamp=' . $timestamp));
$title = '祝福短信';
$mobile = '17712345678';
/*构造发送主体 */
$content = '祝你生日快乐';
$txt = base64_encode(get_utf8_to_gb($content));
$path = "D:/我的文档/Pictures/6b76a7cb.jpg";
$extension = "jpg"; //图片后缀
$img = imgtobase64($path);
$message = 'txt|' . $txt . ',' . $extension . '|' . $img . ';'; //如果只发送一张图片最后这个;一定不要丢掉
$message = str_replace('%', '%25', $message);
$message = str_replace('&', '%26', $message);
$message = str_replace('+', '%2B', $message);
/*构造发送参数 */
$postData = array(
'action' => $action,
'username' => $username,
'password' => $password,
'token' => $token,
'timestamp' => $timestamp,
'sign' => $sign,
'rece' => 'json',
'title' => $title,
'mobile' => $mobile,
'message' => $message
);
$result = postSMS($url, $postData);
echo $result;
function imgtobase64($img = '', $imgHtmlCode = true)
{
$imageInfo = getimagesize($img);
$base64 = "" . chunk_split(base64_encode(file_get_contents($img)));
return chunk_split(base64_encode(file_get_contents($img)));;
}
function get_utf8_to_gb($value)
{
$value_1 = $value;
$value_2 = @iconv("utf-8", "gb2312//IGNORE", $value_1); //使用@抵制错误,如果转换字符串中,某一个字符在目标字符集里没有对应字符,那么,这个字符之后的部分就被忽略掉了;即结果字符串内容不完整,此时要使用//IGNORE
$value_3 = @iconv("gb2312", "utf-8//IGNORE", $value_2);
if (strlen($value_1) == strlen($value_3)) {
return $value_2;
} else {
return $value_1;
}
}
function postSMS($url, $postData)
{
$row = parse_url($url);
$host = $row['host'];
$port = isset($row['port']) ? $row['port'] : 80;
$file = $row['path'];
$post = "";
while (list($k, $v) = each($postData)) {
$post .= rawurlencode($k) . "=" . rawurlencode($v) . "&";
}
$post = substr($post, 0, -1);
$len = strlen($post);
$fp = @fsockopen($host, $port, $errno, $errstr, 10);
if (!$fp) {
return "$errstr ($errno)\n";
} else {
$receive = '';
$out = "POST $file HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: $len\r\n\r\n";
$out .= $post;
fwrite($fp, $out);
while (!feof($fp)) {
$receive .= fgets($fp, 128);
}
fclose($fp);
$receive = explode("\r\n\r\n", $receive);
unset($receive[0]);
return implode("", $receive);
}
}
function getMillisecond()
{
list($t1, $t2) = explode(' ', microtime());
return (float) sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
}