dever 6 سال پیش
والد
کامیت
d939737533
2فایلهای تغییر یافته به همراه46 افزوده شده و 5 حذف شده
  1. 13 1
      applet/database/msg_form.php
  2. 33 4
      applet/src/Msg.php

+ 13 - 1
applet/database/msg_form.php

@@ -29,6 +29,17 @@ return array
 			'desc' 		=> '请输入项目',
 			'match' 	=> 'is_numeric',
 		),
+
+		'openid'		=> array
+		(
+			'type' 		=> 'varchar-120',
+			'name' 		=> '用户openid',
+			'default' 	=> '',
+			'desc' 		=> '用户openid',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
 		
 		'form_id'		=> array
 		(
@@ -65,7 +76,7 @@ return array
 
 	'manage' => array
 	(
-		'delete' => false,
+		//'delete' => false,
 		'insert' => false,
 		'edit' => false,
 	),
@@ -77,6 +88,7 @@ return array
 			# 匹配的正则或函数 选填项
 			'option' => array
 			(
+				'openid' => 'yes',
 				'cdate' => array(time()+(3600*24*7), '<='),
 				'state' => 1,
 			),

+ 33 - 4
applet/src/Msg.php

@@ -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'];