Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
8cb003ca
Commit
8cb003ca
authored
Jan 02, 2019
by
testshenbd
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'linqing' of git.shenbd.com:qm-develop/shenbd into linqing
parents
ca7c2437
bdafd0bf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
181 additions
and
162 deletions
+181
-162
OrderConfirmUtil.php
application/library/Order/OrderConfirmUtil.php
+31
-74
WechatCommon.php
application/library/Our/WechatCommon.php
+16
-1
OrderService.php
application/models/Business/Order/OrderService.php
+30
-86
redisPublish.php
public/redisPublish.php
+1
-1
redisSubscribe.php
scripts/crontab/push/redisSubscribe.php
+4
-0
runRedisPush.php
scripts/crontab/push/runRedisPush.php
+99
-0
No files found.
application/library/Order/OrderConfirmUtil.php
View file @
8cb003ca
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Order
;
namespace
Order
;
use
Our\ApiConst
;
use
Our\ApiConst
;
use
Our\RedisHelper
;
use
Our\RedisHelper
;
use
Our\WechatCommon
;
/**
/**
...
@@ -710,83 +711,39 @@ class OrderConfirmUtil {
...
@@ -710,83 +711,39 @@ class OrderConfirmUtil {
}
}
$orderModel
->
db
->
doCommit
();
$orderModel
->
db
->
doCommit
();
$this
->
opCacheInfo
();
$wechatCommon
=
WechatCommon
::
getInstance
();
$this
->
pushMessage
();
$access_token
=
$wechatCommon
->
getAccessToken
();
return
array
(
'needPayFlag'
=>
$needPayFlag
,
'paySn'
=>
$paySn
);
//订单通过小程序表单提交过来
}
if
(
$formId
&&
$access_token
)
{
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
/**
$msg_tpl
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_create_tpl'
))[
'wxapp_order_create_tpl'
];
* 获取小程序表单
$goods_str
=
''
;
* User: King <358887571@qq.com>
if
(
count
(
$goods_datas
)
>
1
)
{
* Date: 2018/12/27 0027
$goods_str
.=
$goods_datas
[
0
]
.
'等'
.
count
(
$goods_datas
)
.
'件商品'
;
* Time: 下午 3:15
}
else
{
*/
$goods_str
.=
$goods_datas
[
0
];
private
function
getLitAccesstoken
(){
$model_wx
=
\DAO\MbWxModel
::
getInstance
();
$weixin
=
$model_wx
->
getOne
(
'id,lit_appid,lit_appsecret,lit_accesstoken,lit_expirestime'
,
'id=1'
);
$access_token
=
''
;
if
(
!
$weixin
[
'lit_expirestime'
]
||
$weixin
[
'lit_expirestime'
]
<
time
())
{
$access_info
=
json_decode
(
file_get_contents
(
'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='
.
$weixin
[
'lit_appid'
]
.
'&secret='
.
$weixin
[
'lit_appsecret'
]),
true
);
if
(
isset
(
$access_info
[
'access_token'
]))
{
$access_token
=
$access_info
[
'access_token'
];
$update_data
=
array
();
$update_data
[
'lit_accesstoken'
]
=
$access_info
[
'access_token'
];
$update_data
[
'lit_expirestime'
]
=
TIMESTAMP
+
$access_info
[
'expires_in'
]
-
1800
;
$where
=
array
(
'id'
=>
$weixin
[
'id'
]);
$result
=
$model_wx
->
update
(
$update_data
,
$where
);
}
}
}
else
{
$sess
=
\Yaf\Session
::
getInstance
();
$access_token
=
$weixin
[
'lit_accesstoken'
];
$authInfo
=
$sess
->
get
(
'wxAuthInfo'
);
}
$openid
=
$authInfo
[
'openid'
];
return
$access_token
;
}
$req_data
=
array
(
'touser'
=>
$openid
,
'template_id'
=>
$msg_tpl
,
'form_id'
=>
$formId
,
'page'
=>
'pages/orders/detail/index?id='
.
$orderId
,
/**
'data'
=>
array
(
* curl请求
'keyword1'
=>
array
(
'value'
=>
'下单成功'
),
* @param $url
'keyword2'
=>
array
(
'value'
=>
$order
[
'order_sn'
]),
* @param $access_token
'keyword3'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
* @param $data
'keyword4'
=>
array
(
'value'
=>
$order
[
'store_name'
]),
* @param $method
'keyword5'
=>
array
(
'value'
=>
$goods_str
),
*/
));
private
function
sendurl
(
$url
,
$access_token
=
''
,
$data
=
''
,
$method
=
'get'
,
$header
=
''
)
{
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
//
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
if
(
strtolower
(
$method
)
==
'post'
)
{
// \Our\Log::getInstance()->write($json, '/data/log/apptest');
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
.
$access_token
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
FALSE
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
FALSE
);
}
else
{
$curl
=
curl_init
(
$url
.
$access_token
);
}
if
(
$header
){
//设置头部信息
curl_setopt
(
$curl
,
CURLOPT_HTTPHEADER
,
$header
);
}
}
//$curl = curl_init($url.$access_token);
curl_setopt
(
$curl
,
CURLOPT_FAILONERROR
,
1
);
//设置允许页面重定向
curl_setopt
(
$curl
,
CURLOPT_FOLLOWLOCATION
,
1
);
//设置返回值赋给变量
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
//设置操作时间
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
5
);
if
(
$method
==
'post'
){
if
(
!
$data
)
$data
=
''
;
// 使用post 请求
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
// 设置请求参数
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
}
//开始事务
$this
->
opCacheInfo
();
$r
=
curl_exec
(
$curl
);
$this
->
pushMessage
();
curl_close
(
$curl
);
return
array
(
'needPayFlag'
=>
$needPayFlag
,
'paySn'
=>
$paySn
);
return
$r
;
}
}
public
function
pushMessage
(){
public
function
pushMessage
(){
...
...
application/library/Our/WechatCommon.php
100755 → 100644
View file @
8cb003ca
...
@@ -72,6 +72,21 @@ class WechatCommon
...
@@ -72,6 +72,21 @@ class WechatCommon
return
$jsonstr
;
return
$jsonstr
;
}
}
/**
* 发送模板消息
*
* @param $access_token token
* @param $req_data 请求数据数组
* User: King <358887571@qq.com>
* Date: 2019/1/2 0002
* Time: 下午 4:41
*/
public
function
sendTemplateMessage
(
$access_token
,
$req_data
)
{
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
.
$access_token
;
$result
=
$this
->
httpsPostJson
(
$url
,
$req_data
,
true
);
return
$result
;
}
public
function
httpsPostJson
(
$url
,
$data
=
''
,
$array
=
false
)
public
function
httpsPostJson
(
$url
,
$data
=
''
,
$array
=
false
)
{
{
...
@@ -127,4 +142,4 @@ class WechatCommon
...
@@ -127,4 +142,4 @@ class WechatCommon
return
self
::
$_instance
;
return
self
::
$_instance
;
}
}
}
}
\ No newline at end of file
application/models/Business/Order/OrderService.php
View file @
8cb003ca
...
@@ -18,6 +18,7 @@ use Our\NameConst;
...
@@ -18,6 +18,7 @@ use Our\NameConst;
use
Our\PageConst
;
use
Our\PageConst
;
use
Our\Push
;
use
Our\Push
;
use
Our\RedisHelper
;
use
Our\RedisHelper
;
use
Our\WechatCommon
;
/**
/**
* 店铺service
* 店铺service
...
@@ -87,52 +88,6 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -87,52 +88,6 @@ class OrderServiceModel extends \Business\AbstractModel
return
$access_token
;
return
$access_token
;
}
}
/**
* curl请求
* @param $url
* @param $access_token
* @param $data
* @param $method
*/
private
function
sendurl
(
$url
,
$access_token
=
''
,
$data
=
''
,
$method
=
'get'
,
$header
=
''
)
{
//
if
(
strtolower
(
$method
)
==
'post'
)
{
$curl
=
curl_init
();
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
.
$access_token
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYPEER
,
FALSE
);
curl_setopt
(
$curl
,
CURLOPT_SSL_VERIFYHOST
,
FALSE
);
}
else
{
$curl
=
curl_init
(
$url
.
$access_token
);
}
if
(
$header
){
//设置头部信息
curl_setopt
(
$curl
,
CURLOPT_HTTPHEADER
,
$header
);
}
//$curl = curl_init($url.$access_token);
curl_setopt
(
$curl
,
CURLOPT_FAILONERROR
,
1
);
//设置允许页面重定向
curl_setopt
(
$curl
,
CURLOPT_FOLLOWLOCATION
,
1
);
//设置返回值赋给变量
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
//设置操作时间
curl_setopt
(
$curl
,
CURLOPT_TIMEOUT
,
5
);
if
(
$method
==
'post'
){
if
(
!
$data
)
$data
=
''
;
// 使用post 请求
curl_setopt
(
$curl
,
CURLOPT_POST
,
1
);
// 设置请求参数
curl_setopt
(
$curl
,
CURLOPT_POSTFIELDS
,
$data
);
}
//开始事务
$r
=
curl_exec
(
$curl
);
curl_close
(
$curl
);
return
$r
;
}
/**
/**
* 发送模板消息
* 发送模板消息
*
*
...
@@ -146,7 +101,8 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -146,7 +101,8 @@ class OrderServiceModel extends \Business\AbstractModel
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_order_goods
=
\DAO\Order\OrderGoodsModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_order_goods
=
\DAO\Order\OrderGoodsModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$access_token
=
$this
->
getLitAccesstoken
();
$wechatCommon
=
WechatCommon
::
getInstance
();
$access_token
=
$wechatCommon
->
getAccessToken
();
$wxapp_templates
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_paysucc_tpl'
,
'wxapp_order_shipping_tpl'
,
'wxapp_order_receive_tpl'
));
$wxapp_templates
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_paysucc_tpl'
,
'wxapp_order_shipping_tpl'
,
'wxapp_order_receive_tpl'
));
//付款7天内付款消息通知
//付款7天内付款消息通知
...
@@ -180,14 +136,10 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -180,14 +136,10 @@ class OrderServiceModel extends \Business\AbstractModel
'keyword6'
=>
array
(
'value'
=>
'已付款'
),
'keyword6'
=>
array
(
'value'
=>
'已付款'
),
));
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
if
(
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
json_encode
(
$req_data
),
'post'
))
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
2
),
$order
[
'order_id'
]);
$json
=
json_decode
(
$result
,
true
);
echo
'order['
.
$order
[
'order_id'
]
.
'] send payment succ'
.
"
\n
"
;
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
2
),
$order
[
'order_id'
]);
echo
'order['
.
$order
[
'order_id'
]
.
'] send payment succ'
.
"
\n
"
;
}
}
}
}
}
...
@@ -235,14 +187,11 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -235,14 +187,11 @@ class OrderServiceModel extends \Business\AbstractModel
'keyword7'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
'keyword7'
=>
array
(
'value'
=>
number_format
(
$order
[
'order_amount'
]
/
100
,
2
)
.
'元'
),
));
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
if
(
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
json_encode
(
$req_data
),
'post'
))
{
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
$json
=
json_decode
(
$result
,
true
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
3
),
$order
[
'order_id'
]);
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
3
),
$order
[
'order_id'
]);
echo
'order['
.
$order
[
'order_id'
]
.
'] send shipping succ'
.
"
\n
"
;
echo
'order['
.
$order
[
'order_id'
]
.
'] send payment succ'
.
"
\n
"
;
}
}
}
}
}
...
@@ -299,14 +248,11 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -299,14 +248,11 @@ class OrderServiceModel extends \Business\AbstractModel
'keyword9'
=>
array
(
'value'
=>
'您购买的商品已被签收,如不是您本人签收,请尽快联系商家'
),
'keyword9'
=>
array
(
'value'
=>
'您购买的商品已被签收,如不是您本人签收,请尽快联系商家'
),
));
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
if
(
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
json_encode
(
$req_data
),
'post'
))
{
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
$json
=
json_decode
(
$result
,
true
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
4
),
$order
[
'order_id'
]);
$model
->
updateByOrderId
(
array
(
'msg_status'
=>
4
),
$order
[
'order_id'
]);
echo
'order['
.
$order
[
'order_id'
]
.
'] send reciver succ'
.
"
\n
"
;
echo
'order['
.
$order
[
'order_id'
]
.
'] send payment succ'
.
"
\n
"
;
}
}
}
}
}
...
@@ -689,7 +635,8 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -689,7 +635,8 @@ class OrderServiceModel extends \Business\AbstractModel
$push
->
sendTcpMessage
();
$push
->
sendTcpMessage
();
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$model_member
=
\DAO\MemberModel
::
getInstance
(
DbNameConst
::
salveDBConnectName
);
$access_token
=
$this
->
getLitAccesstoken
();
$wechatCommon
=
WechatCommon
::
getInstance
();
$access_token
=
$wechatCommon
->
getAccessToken
();
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$settingDAO
=
\DAO\SettingModel
::
getInstance
();
$wxapp_templates
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_receive_tpl'
));
$wxapp_templates
=
$settingDAO
->
getListCache
(
array
(
'wxapp_order_receive_tpl'
));
...
@@ -734,13 +681,10 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -734,13 +681,10 @@ class OrderServiceModel extends \Business\AbstractModel
'keyword9'
=>
array
(
'value'
=>
'您购买的商品已被签收,如不是您本人签收,请尽快联系商家'
),
'keyword9'
=>
array
(
'value'
=>
'您购买的商品已被签收,如不是您本人签收,请尽快联系商家'
),
));
));
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
// \Our\Log::getInstance()->write(json_encode($req_data), '/data/log/apptest');
$url
=
'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='
;
if
(
$result
=
$this
->
sendurl
(
$url
,
$access_token
,
json_encode
(
$req_data
),
'post'
))
{
$json
=
$wechatCommon
->
sendTemplateMessage
(
$access_token
,
$req_data
);
$json
=
json_decode
(
$result
,
true
);
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
if
(
$json
[
'errmsg'
]
==
'ok'
)
{
$orderDao
->
updateByOrderId
(
array
(
'msg_status'
=>
4
),
$order
[
'order_id'
]);
$orderDao
->
updateByOrderId
(
array
(
'msg_status'
=>
4
),
$order
[
'order_id'
]);
}
}
}
}
}
...
@@ -1070,12 +1014,12 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -1070,12 +1014,12 @@ class OrderServiceModel extends \Business\AbstractModel
$orderDao
->
db
->
doRollback
();
$orderDao
->
db
->
doRollback
();
continue
;
continue
;
}
}
array_push
(
$orderIds
,
$order
[
'orderId'
]);
$this
->
updateOrderGoodsStoregeByOrderIds
(
$orderIds
);
array_push
(
$newOrders
,
$order
);
$orderIds
=
array
();
$orderDao
->
db
->
doCommit
();
}
}
array_push
(
$orderIds
,
$order
[
'orderId'
]);
$this
->
updateOrderGoodsStoregeByOrderIds
(
$orderIds
);
array_push
(
$newOrders
,
$order
);
$orderIds
=
array
();
$orderDao
->
db
->
doCommit
();
$orderDao
->
deleteOrderCache
(
$order
[
'buyerId'
],(
string
)
$order
[
'orderId'
],
$order
[
'storeId'
],
true
);
$orderDao
->
deleteOrderCache
(
$order
[
'buyerId'
],(
string
)
$order
[
'orderId'
],
$order
[
'storeId'
],
true
);
$storeDao
->
deleteStoreCache
(
$order
[
'storeId'
],
$order
[
'orderId'
]);
$storeDao
->
deleteStoreCache
(
$order
[
'storeId'
],
$order
[
'orderId'
]);
$push
=
\Our\Push
::
getInstance
();
$push
=
\Our\Push
::
getInstance
();
...
@@ -1148,12 +1092,12 @@ class OrderServiceModel extends \Business\AbstractModel
...
@@ -1148,12 +1092,12 @@ class OrderServiceModel extends \Business\AbstractModel
$orderDao
->
db
->
doRollback
();
$orderDao
->
db
->
doRollback
();
continue
;
continue
;
}
}
array_push
(
$orderIds
,
$order
[
'orderId'
]);
$this
->
updateOrderGoodsStoregeByOrderIds
(
$orderIds
);
array_push
(
$newOrders
,
$order
);
$orderIds
=
array
();
$orderDao
->
db
->
doCommit
();
}
}
array_push
(
$orderIds
,
$order
[
'orderId'
]);
$this
->
updateOrderGoodsStoregeByOrderIds
(
$orderIds
);
array_push
(
$newOrders
,
$order
);
$orderIds
=
array
();
$orderDao
->
db
->
doCommit
();
$orderDao
->
deleteOrderCache
(
$order
[
'buyerId'
],(
string
)
$order
[
'orderId'
],
$order
[
'storeId'
],
true
);
$orderDao
->
deleteOrderCache
(
$order
[
'buyerId'
],(
string
)
$order
[
'orderId'
],
$order
[
'storeId'
],
true
);
$storeDao
->
deleteStoreCache
(
$order
[
'storeId'
],
$order
[
'orderId'
]);
$storeDao
->
deleteStoreCache
(
$order
[
'storeId'
],
$order
[
'orderId'
]);
$push
=
\Our\Push
::
getInstance
();
$push
=
\Our\Push
::
getInstance
();
...
...
public/redisPublish.php
View file @
8cb003ca
...
@@ -3,4 +3,4 @@
...
@@ -3,4 +3,4 @@
$redis
=
new
Redis
();
$redis
=
new
Redis
();
$redis
->
connect
(
'192.168.1.201'
,
6379
);
$redis
->
connect
(
'192.168.1.201'
,
6379
);
$message
=
'happy New Year'
;
$message
=
'happy New Year'
;
$ret
=
$redis
->
publish
(
'
pushcenter
'
,
$message
);
$ret
=
$redis
->
publish
(
'
redisPublish
'
,
$message
);
scripts/crontab/push/redisSubscribe.php
View file @
8cb003ca
...
@@ -24,5 +24,9 @@ function printTest($meg){
...
@@ -24,5 +24,9 @@ function printTest($meg){
echo
$meg
.
'213'
;
echo
$meg
.
'213'
;
}
}
function
callback
(
$instance
,
$channelName
,
$message
){
function
callback
(
$instance
,
$channelName
,
$message
){
if
(
$message
==
'outPid'
){
$instance
->
unsubscribe
(
array
(
$channelName
));
return
;
}
printTest
(
$message
);
printTest
(
$message
);
}
}
scripts/crontab/push/runRedisPush.php
0 → 100644
View file @
8cb003ca
<?php
define
(
"APPLICATION_PATH"
,
realpath
(
dirname
(
__FILE__
)
.
'/../../../'
));
//指向public的上一级
require
APPLICATION_PATH
.
'/scripts/crontab/baseCli.php'
;
require
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
error_reporting
(
E_ALL
^
E_NOTICE
);
class
runRedisPush
{
/* config */
const
LISTEN
=
"tcp://192.168.2.15:5555"
;
const
MAXCONN
=
100
;
const
pidfile
=
__CLASS__
;
const
uid
=
80
;
const
gid
=
80
;
/**/
protected
$pool
=
NULL
;
protected
$zmq
=
NULL
;
public
function
__construct
()
{
$this
->
pidfile
=
'/var/run/'
.
self
::
pidfile
.
'.pid'
;
}
private
function
daemon
()
{
if
(
file_exists
(
$this
->
pidfile
))
{
echo
"The file
$this->pidfile
exists.
\n
"
;
exit
();
}
$pid
=
pcntl_fork
();
if
(
$pid
==
-
1
)
{
die
(
'could not fork'
);
}
else
if
(
$pid
)
{
// we are the parent
//pcntl_wait($status); //Protect against Zombie children
exit
(
$pid
);
}
else
{
// we are the child
file_put_contents
(
$this
->
pidfile
,
getmypid
());
posix_setuid
(
self
::
uid
);
posix_setgid
(
self
::
gid
);
return
(
getmypid
());
}
}
private
function
start
()
{
$pid
=
$this
->
daemon
();
$conf
=
\Yaf\Registry
::
get
(
'config'
)
->
get
(
'redis.database.params'
);
$redis
=
new
Redis
();
$redis
->
connect
(
$conf
[
'host'
],
$conf
[
'port'
]);
if
(
!
empty
(
$conf
[
'password'
])){
$redis
->
auth
(
$conf
[
'password'
]);
}
//ini_set('default_socket_timeout', -1);(所有长连接不超时)
$redis
->
setOption
(
Redis
::
OPT_READ_TIMEOUT
,
-
1
);
$result
=
$redis
->
subscribe
(
array
(
'redisPublish'
),
'callback'
);
function
printTest
(
$meg
){
echo
$meg
.
'213'
;
}
function
callback
(
$instance
,
$channelName
,
$message
){
printTest
(
$message
);
}
}
private
function
stop
()
{
if
(
file_exists
(
$this
->
pidfile
))
{
$pid
=
file_get_contents
(
$this
->
pidfile
);
posix_kill
(
$pid
,
9
);
unlink
(
$this
->
pidfile
);
}
}
private
function
help
(
$proc
)
{
printf
(
"%s start | stop | help
\n
"
,
$proc
);
}
public
function
main
(
$argv
)
{
if
(
count
(
$argv
)
<
2
)
{
printf
(
"please input help parameter
\n
"
);
exit
();
}
if
(
$argv
[
1
]
===
'stop'
)
{
$this
->
stop
();
}
else
if
(
$argv
[
1
]
===
'start'
)
{
$this
->
start
();
}
else
{
$this
->
help
(
$argv
[
0
]);
}
}
}
$cgse
=
new
runRedisPush
();
$cgse
->
main
(
$argv
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment