|
@@ -29,31 +29,46 @@ class Msg
|
|
|
);
|
|
|
|
|
|
$data = json_encode($data);
|
|
|
- Dever::setInput('touser', 'oIZ895adCNPtwyPX47Uv8ne8_xcM');
|
|
|
+ //Dever::setInput('touser', 'oIZ895bO9a_TT_ouYCQLPFMod57c');
|
|
|
|
|
|
//Dever::setInput('touser', 'oIZ895bO9a_TT_ouYCQLPFMod57c');
|
|
|
Dever::setInput('page', $page);
|
|
|
Dever::setInput('data', $data);
|
|
|
- Dever::setInput('form_id', '1526293953558');
|
|
|
- Dever::setInput('id', 1);
|
|
|
+ //Dever::setInput('form_id', '1526295575657');
|
|
|
+ Dever::setInput('key', 'sendall');
|
|
|
+ Dever::setInput('project_id', '4');
|
|
|
$this->send();
|
|
|
}
|
|
|
|
|
|
- # 发送模板消息
|
|
|
+ # 发送单条模板消息
|
|
|
public function send()
|
|
|
{
|
|
|
- $id = Dever::input('id');
|
|
|
- if ($id > 0) {
|
|
|
- $info = Dever::db('applet/msg')->one($id);
|
|
|
+ $key = Dever::input('key');
|
|
|
+ $project_id = Dever::input('project_id');
|
|
|
+ $touser = Dever::input('touser');
|
|
|
+ $page = Dever::input('page');
|
|
|
+ $data = Dever::input('data');
|
|
|
+ $form_id = Dever::input('form_id');
|
|
|
+ $emphasis_keyword = Dever::input('emphasis_keyword');
|
|
|
+ $this->sendOne($key, $project_id, $touser, $page, $data, $form_id, $emphasis_keyword);
|
|
|
+
|
|
|
+ return 'ok';
|
|
|
+ }
|
|
|
+
|
|
|
+ # 发送单条模板消息
|
|
|
+ public function sendOne($key, $project_id, $touser, $page, $data, $form_id, $emphasis_keyword = '')
|
|
|
+ {
|
|
|
+ if ($project_id > 0 && $key && $touser && $page && $data) {
|
|
|
+ $info = Dever::db('applet/msg')->one(array('option_key' => $key, 'option_project_id' => $project_id));
|
|
|
if ($info) {
|
|
|
$update = array();
|
|
|
$update['project_id'] = $info['project_id'];
|
|
|
$update['msg_id'] = $info['id'];
|
|
|
- $update['touser'] = Dever::input('touser');
|
|
|
- $update['page'] = Dever::input('page');
|
|
|
- $update['data'] = Dever::input('data');
|
|
|
- $update['form_id'] = Dever::input('form_id');
|
|
|
- $update['emphasis_keyword'] = Dever::input('emphasis_keyword');
|
|
|
+ $update['touser'] = $touser;
|
|
|
+ $update['page'] = $page;
|
|
|
+ $update['data'] = $data;
|
|
|
+ $update['form_id'] = $form_id;
|
|
|
+ $update['emphasis_keyword'] = $emphasis_keyword;
|
|
|
|
|
|
if (!$update['form_id']) {
|
|
|
$update['form_id'] = $this->getFormId($update['touser']);
|
|
@@ -71,10 +86,48 @@ class Msg
|
|
|
Core::run($info['project_id'], 'send_msg', 'msg.sendAction', 'msg.sendLog', 'applet', $id);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ # 发送多条模板消息 入队
|
|
|
+ public function sendMul()
|
|
|
+ {
|
|
|
+ $key = Dever::input('key');
|
|
|
+ $project_id = Dever::input('project_id');
|
|
|
+ $page = Dever::input('page');
|
|
|
+ $data = Dever::input('data');
|
|
|
+ $emphasis_keyword = Dever::input('emphasis_keyword');
|
|
|
+ if ($id > 0 && $page && $data) {
|
|
|
+ # 获取所有拥有formid的openid,并去重
|
|
|
+ $data = Dever::db('applet/msg_form')->getAllGroupByOpenid();
|
|
|
+ print_r($data);die;
|
|
|
+ if ($data) {
|
|
|
+ Dever::import('queue');
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $param = array();
|
|
|
+ $param['key'] = $key;
|
|
|
+ $param['project_id'] = $project_id;
|
|
|
+ $param['touser'] = $v['openid'];
|
|
|
+ $param['page'] = $page;
|
|
|
+ $param['data'] = $data;
|
|
|
+ $param['form_id'] = $v['form_id'];
|
|
|
+ $param['emphasis_keyword'] = $emphasis_keyword;
|
|
|
+ Dever::push($param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
|
+ # 发送多条模板消息 出队 每小时执行一次
|
|
|
+ public function cron()
|
|
|
+ {
|
|
|
+ Dever::import('queue');
|
|
|
+ while ($data = Dever::pop()) {
|
|
|
+ $this->sendOne($data['key'], $data['project_id'], $data['touser'], $data['page'], $data['data'], $data['form_id'], $data['emphasis_keyword']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function getFormId($openid)
|
|
|
{
|
|
|
# 获取一个form_id,取最新的100条,然后随机取
|
|
@@ -92,18 +145,16 @@ class Msg
|
|
|
# 记录form_id 之后加上清理过期的form_id 七天过期
|
|
|
public function write_form_id()
|
|
|
{
|
|
|
- $id = Dever::input('id');
|
|
|
+ $id = Dever::input('project_id');
|
|
|
if ($id > 0) {
|
|
|
- $info = Dever::db('applet/msg')->one($id);
|
|
|
-
|
|
|
$update = array();
|
|
|
- $update['project_id'] = $info['project_id'];
|
|
|
+ $update['project_id'] = $id;
|
|
|
$update['form_id'] = Dever::input('form_id');
|
|
|
$update['openid'] = Dever::input('openid');
|
|
|
|
|
|
$where = array();
|
|
|
$where['option_openid'] = $update['openid'];
|
|
|
- $where['option_project_id'] = $info['project_id'];
|
|
|
+ $where['option_project_id'] = $update['project_id'];
|
|
|
$where['option_form_id'] = $update['form_id'];
|
|
|
|
|
|
$id = Dever::upinto('applet/msg_form', $where, $update);
|