destoon 短信发送函数及短信接口修改
// $DT在common.inc.php中定义, $CACHE = cache_read('module.php'); $DT = $CACHE['dt']; 从缓存里读取网站配置信息。
//$db 数据库类,$DT 全局配置,$DT['sms'] 开启手机短信,$DT_TIME系统时间,$DT_IP 当前ip地址,$_username当前用户
//DT_CLOUD_UID DT_CLOUD_KEY 在common.inc.php 中定义
//define('DT_CLOUD_UID', $CFG['cloud_uid']); //$CFG 加载根目录下 config.inc.php ,所以短信发送接口用户名和密码在这里设置。新版dt在 后台系统设置-》网站设置-》云服务 里设置。
//define('DT_CLOUD_KEY', $CFG['cloud_key']);
//参数:$mobile手机号,$message发送内容,$word 字数,$time 时间
function send_sms($mobile, $message, $word = 0, $time = 0) {
global $db, $DT, $DT_TIME, $DT_IP, $_username;
//开启短信,设置了用户名密码,手机号合法,内容给不低于5个字符。
if(!$DT['sms'] || !DT_CLOUD_UID || !DT_CLOUD_KEY || !is_mobile($mobile) || strlen($message) < 5) return false;
$word or $word = word_count($message); //若没有指定字数,则通过函数word_count计算字数 ,这个函数涉及mb_strlen,strlen的区别。
$sms_message = convert($message, DT_CHARSET, 'UTF-8');
$data = 'sms_uid='.DT_CLOUD_UID.'&sms_key='.md5(DT_CLOUD_KEY.'|'.$mobile.'|'.md5 ($sms_message)).'&sms_charset='.DT_CHARSET.'&sms_mobile='.$mobile.'&sms_message='.rawurlencode($sms_message).'&sms_time='.$time;
$header = "POST /send.php HTTP/1.0\r\n";
$header .= "Accept: */*\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($data)."\r\n\r\n";
$fp = function_exists('fsockopen') ? fsockopen('sms.destoon.com', 8820) : stream_socket_client('sms.destoon.com:8820');
$code = '';
if($fp) {
fputs($fp, $header.$data);
while(!feof($fp)) {
$code .= fgets($fp, 1024);
}
fclose($fp);
if($code && strpos($code, 'destoon_sms_code=') !== false) {
$code = explode('destoon_sms_code=', $code);
$code = $code[1];
} else {
$code = 'Can Not Connect SMS Server';
}
} else {
$code = 'Can Not Connect SMS Server';
}
//记录发送记录
$db->query("INSERT INTO {$db->pre}sms (mobile,message,word,editor,sendtime,code) VALUES ('$mobile','$message','$word','$_username','$DT_TIME','$code')");
return $code;
}
//mb_strlen,strlen的区别 http://developer.51cto.com/art/201105/263103.htm
function word_count($string) {
if(function_exists('mb_strlen')) return mb_strlen($string, DT_CHARSET);
$string = convert($string, DT_CHARSET, 'gbk');
$length = strlen($string);
$count = 0;
for($i = 0; $i < $length; $i++) {
$t = ord($string[$i]);
if($t > 127) $i++;
$count++;
}
return $count;
}
需要注意的是,mb_strlen并不是PHP核心函数,使用前需要确保在php.ini中加载了php_mbstring.dll,即确保“extension=php_mbstring.dll”这一行存在并且没有被注释掉,否则会出现未定义函 数的问题。
修改系统默认短信端口
global.func.php send_sms函数改成
/**
* 通过CURL发送HTTP请求
* @param string $url //请求URL
* @param array $postFields //请求参数
* @return mixed
*/
function curlPost($url='',$postFields){ $postFields = http_build_query($postFields);
$ch = curl_init();
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
$result = curl_exec ( $ch );
curl_close ( $ch );
return $result;
} /**
* 发送短信
*
* @param string $mobile 手机号码
* @param string $msg 短信内容
* @param string $needstatus 是否需要状态报告
* @param string $product 产品id,可选
* @param string $extno 扩展码,可选
*/
function send_sms($mobile,$msg,$word = 0,$time = 0,$needstatus = 'false',$extno = '') {
global $db, $DT, $DT_TIME, $DT_IP, $_username; if(!$DT['sms'] || !DT_CLOUD_UID || !DT_CLOUD_KEY || !is_mobile($mobile) || strlen($msg) <3) return false; $word or $word = word_count($message);
//创蓝接口参数
$postArr = array (
'account' => DT_CLOUD_UID,
'pswd' => DT_CLOUD_KEY,
'msg' => $msg,
'mobile' => $mobile,
'needstatus' => $needstatus,
'extno' => $extno
);
$url="http://222.73.117.156/msg/HttpBatchSendSM";
$result =curlPost($url, $postArr);
if($result){
$arr=explode(',',$result);
$result=$arr[1]==0?1:$arr[1]; //这个接口成功返回0 返回大于1代表错误
}
$db->query("INSERT INTO {$db->pre}sms (mobile,message,word,editor,sendtime,code) VALUES ('$mobile','$message','$word','$_username','$DT_TIME','$result')");
return $result;
}
destoon 短信发送函数及短信接口修改的更多相关文章
- PHP短信发送服务 youe短信企业服务
/** * 通用短信平台HTTP接口POST方式发送短信实例 * 返回字符串 * 一般情况下调用此方法 */ function postSendMessage($msgContents,$phoneL ...
- 短信平台软件开发,短信发送平台销售,短信软件源码,G客短信发送平台
一:web短信平台组成 需要短信软件平台源码的联系QQ:290615413 vx:290615413 整套短信系统平台还是由B/S(客户端+后台,取消了以前C/S的管理后台) ,C/S发送服务端和 ...
- android 在短信发送界面, 短信发送失败时,提示音不完整,会被中断
1. 当一条SMS到来, 此时SMS是unseen状态, 就会弹出Notification提示用户 2. 但假设处于同一个联系人的界面下, 用户会立马看到这条SMS, 此时这条SMS会被高速的标记为s ...
- Android系统应用Mms之Sms短信发送流程(Mms应用部分)二
1. 新建一条短信, 在发送短信之前, 首先创建的是一个会话Conversation, 以后所有与该接收人(一个或多个接收人)的消息交互, 都在该会话Conversation中. ComposeMes ...
- Android短彩信源码解析-短信发送流程(二)
转载请注明出处:http://blog.csdn.net/droyon/article/details/11699935 2,短彩信发送framework逻辑 短信在SmsSingleRecipien ...
- C# 短信发送 邮件发送
兴趣是最好的老师. --爱因斯坦 一.实现短信发送 1.使用短信mao的方式进行短信发送,前提要购买硬件设备,这里就不考虑展示了: 2.使用中国网建提供的短信平台,但是用几次后要收费: 我们这里主要介 ...
- Java版阿里云通信短信发送API接口实例(新)
阿里云通信(原名阿里大于)的短信服务(Short Message Service)是阿里云为用户提供的一种通信服务的能力,支持快速发送短信验证码.短信通知等. 完美支撑双11期间2亿用户,发送6亿短信 ...
- day80:luffy:短信sdk接入&点击获取验证码&注册功能的实现&Celery实现短信发送功能
目录 1.短信sdk接入 2.前端点击获取验证码效果 3.注册后端接口实现 4.注册-前端 5.Celery 6.Celery完成短信发送功能 1.短信sdk接入 1.准备工作 1.下载云通讯相关的文 ...
- destoon短信接口修改方法
destoon是很优秀的B2B行业站程序.程序模块化开发契合度很高,二次开发起来也很顺畅.数据缓存,权限分配,SEO功能方面都不错. 但是在使用这套程序的时候,常常要用到发送短信的功能,而destoo ...
随机推荐
- Educational Codeforces Round 66 (Rated for Div. 2) A. From Hero to Zero
链接:https://codeforces.com/contest/1175/problem/A 题意: You are given an integer nn and an integer kk. ...
- 【填坑】loj6159. 「美团 CodeM 初赛 Round A」最长树链
水一水 枚举各个质数,把是这个数倍数的点留下,跑直径,没了 #include <bits/stdc++.h> using namespace std; int h,t,n,p,q,M,N; ...
- echart 初级尝试
var option = { title: { text: 'ECharts 入门示例'//标题 }, legend: { data:['销量']//图例 }, xAxis: { data: [&qu ...
- php:比较两个txt文件,格式如下,分别取出a.txt有的b.txt没有的,b.txt有的a.txt没有的及两个都有的
<?php /*比较两个txt文件,格式如下,分别取出a.txt有的b.txt没有的,b.txt有的a.txt没有的及两个都有的 * a.txt: * A * B * C * D * b.txt ...
- python 1 学习廖雪峰博客
输出 用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print('hello, world') p ...
- plsql连接远程数据库快捷方式
不用修改任何文件就可以直接连接远程数据库
- SpriingMVC执行流程结构
SpringMVC也叫spring web mvc,属于表现层的框架,是Spring框架的一部分. Spring MVC请求流程图: request-------->DispatcherSer ...
- Flash图表控件FusionCharts如何高亮显示数据
使用Flash图表控件FusionCharts时,通过改变alpha值是高亮显示数据的最简单方式. XML代码如下: <chart> <set label='John' value= ...
- 31全志r58平台Android4.4.2下打开USB摄像头
31全志r58平台Android4.4.2下打开USB摄像头 2018/10/26 16:00 版本:V1.0 开发板:SC5806 1.系统编译:(略) 2.需要修改的文件: W:\r58_andr ...
- fiddler设置只抓取某一域名请求
简单易懂~