2013年版通达OA与飞信集成

基于PHP-fetion进行修改。

作者博客:http://blog.quanhz.com/

PHP-fetion代码:https://code.google.com/p/php-fetion/

对定时发送页面做了修改:

fetion_send_sms.php(2013年版通达OA)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?
//定时任务发送飞信手机短信
include_once (“inc/conn.php”);
include_once (“inc/fetion.php”); //账号密码
require_once (“inc/class.fetion.php”); //飞信发送类
require_once (“inc/class.gateway.php”); //其他API接口发送
$cur_time = date(“Y-m-d H:i:s”); //获得当前时间
$query = “SELECT `SMS_ID`,`PHONE`,`CONTENT` FROM `SMS2` WHERE `SEND_TIME` <= ‘{$cur_time}’ AND `SEND_FLAG` = ‘3’ LIMIT 1″; //检测短信时间及状态
$cursor = exequery($connection, $query); //连接数据库
//无短信需要发送
if (0 == mysql_num_rows($cursor)) {
echo “No message to send”;
}
else {
//发送飞信
$ROW = mysql_fetch_array($cursor);
$PHONE = $ROW['PHONE'];
$CONTENT = $ROW['CONTENT'];
$SMS_ID = $ROW['SMS_ID'];
//登陆飞信
$fetion = new PHPFetion($mobile, $password);
//发送飞信短信
$result = $fetion->send($PHONE, iconv(“gbk”, “utf-8″, $CONTENT));
//发送短信读取手机号,及信息内容转换代码
$result = iconv(“utf-8″, “gbk”, $result); //返回值
//判定飞信发送是否成功
if (strpos($result, “成功”) === FALSE) {
$JIEGUO = 0; //失败,状态更新至待网关发送
echo “One message to sent by MAS”;
} else {
$JIEGUO = 1; //成功
echo “One message to sent by Fetion”;
}
//更新短信发送状态
$query2 = “UPDATE `SMS2` SET `SEND_FLAG` = ‘{$JIEGUO}’ WHERE `SMS_ID`='{$SMS_ID}'”;
exequery($connection, $query2);
//结束会话
$fetion->_logout();
}
/* End of the file */

其余代码,点击下载:2013年版OA与飞信集成方案

将文件在OA服务器wwwroot目录下进行覆盖,将task目录下的fetion_send_sms.php加入到通达OA的定时任务中。

注:OA自带的定时任务的最小时间间隔为1分钟,飞信发送缓慢。

这里提供2种解决方案:

1、windows下

创建一个cron.bat的批处理文件并用记事本打开输入:

1
2
3
4
5
6
7
8
@echo off
:fetion
ping -n 2 127.0.0.1 >>nul
start http://188.188.0.9/fetion_send_sms.php
ping -n 3 127.0.0.1 >>nul
taskkill /f /im "iexplore.exe"
goto fetion
pause

2.linux下

在/root/shell下创建一个fetion.sh的shell脚本

1
2
3
#!/bin/sh
curl http://188.188.0.9/fetion_send_sms.php
#局域网访问php代码的地址

然后,每隔5s钟访问指定php脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
crontab -e
* * * * * /root/shell/fetion.sh
* * * * * sleep 5 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 10 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 15 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 20 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 25 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 30 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 35 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 40 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 45 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 50 &amp;&amp; /root/shell/fetion.sh
* * * * * sleep 55 &amp;&amp; /root/shell/fetion.sh

2014.5.18日,更新统计飞信、mas发送次数,删除root邮件。

1
2
3
4
5
6
#!/bin/sh
Fetion_DateName=Fetion_Date_$(date +“%Y%m%d”).txt
MAS_DateName=MAS_Date_$(date +“%Y%m%d”).txt
grep ‘One message to sent by Fetion’ /var/spool/mail/root | wc -l >> /root/shell/Date_Fetion/$Fetion_DateName
grep ‘One message to sent by MAS’ /var/spool/mail/root | wc -l >> /root/shell/Date_Fetion/$MAS_DateName
cat /dev/null > /var/spool/mail/root