|
@@ -12,6 +12,33 @@ use Main\Lib\Core;
|
|
|
|
|
|
class Msg
|
|
|
{
|
|
|
+ # 发送模板消息
|
|
|
+ public function test()
|
|
|
+ {
|
|
|
+ $page = 'pages/index/index';
|
|
|
+ $data = array
|
|
|
+ (
|
|
|
+ 'keyword1' => array
|
|
|
+ (
|
|
|
+ 'value' => '测试活动',
|
|
|
+ ),
|
|
|
+ 'keyword2' => array
|
|
|
+ (
|
|
|
+ 'value' => date('Y-m-d H:i:s'),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ $data = json_encode($data);
|
|
|
+ Dever::setInput('touser', 'oIZ895adCNPtwyPX47Uv8ne8_xcM');
|
|
|
+
|
|
|
+ //Dever::setInput('touser', 'oIZ895bO9a_TT_ouYCQLPFMod57c');
|
|
|
+ Dever::setInput('page', $page);
|
|
|
+ Dever::setInput('data', $data);
|
|
|
+ Dever::setInput('form_id', '1526293953558');
|
|
|
+ Dever::setInput('id', 1);
|
|
|
+ $this->send();
|
|
|
+ }
|
|
|
+
|
|
|
# 发送模板消息
|
|
|
public function send()
|
|
|
{
|
|
@@ -29,13 +56,13 @@ class Msg
|
|
|
$update['emphasis_keyword'] = Dever::input('emphasis_keyword');
|
|
|
|
|
|
if (!$update['form_id']) {
|
|
|
- $update['form_id'] = $this->getFormId();
|
|
|
+ $update['form_id'] = $this->getFormId($update['touser']);
|
|
|
}
|
|
|
|
|
|
$where = array();
|
|
|
$where['option_msg_id'] = $info['id'];
|
|
|
$where['option_touser'] = $update['touser'];
|
|
|
- $where['option_data'] = $update['data'];
|
|
|
+ //$where['option_data'] = $update['data'];
|
|
|
$where['option_form_id'] = $update['form_id'];
|
|
|
$where['option_page'] = $update['page'];
|
|
|
|
|
@@ -48,10 +75,10 @@ class Msg
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
|
- public function getFormId()
|
|
|
+ public function getFormId($openid)
|
|
|
{
|
|
|
# 获取一个form_id,取最新的100条,然后随机取
|
|
|
- $info = Dever::db('applet/msg_form')->getAll();
|
|
|
+ $info = Dever::db('applet/msg_form')->getAll(array('option_openid' => $openid));
|
|
|
if ($info) {
|
|
|
$key = array_rand($info, 1);
|
|
|
$info = $info[$key];
|
|
@@ -72,8 +99,10 @@ class Msg
|
|
|
$update = array();
|
|
|
$update['project_id'] = $info['project_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_form_id'] = $update['form_id'];
|
|
|
|