| xqd
@@ -13,13 +13,32 @@ class sendNotice extends BatchAction
|
|
|
|
|
|
public function handle(Collection $collection)
|
|
|
{
|
|
|
- foreach ($collection as $model) {
|
|
|
- $openid = User::where('id',$model->id)->value('openid');
|
|
|
+ $info = $collection->toArray();
|
|
|
+ $ids = array_unique(array_column($info,'id'));
|
|
|
+ foreach ($ids as $id) {
|
|
|
+ $openid = User::where('id',$id)->value('openid');
|
|
|
$content = request('content');
|
|
|
$remark= request('remark');
|
|
|
-// $openid = 'oVxTzvgYlGktIDZXwfLMLQ01Tr5s'; 自己
|
|
|
+ $stime= request('stime');
|
|
|
+ $type= request('type',1);
|
|
|
+// $openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
|
|
|
+ $service_arr = [1=>'儿保服务',2=>'疫苗接种服务'];
|
|
|
+ $service_name = $service_arr[$type];
|
|
|
+
|
|
|
+ //没有openid 直接不发送
|
|
|
if(empty($openid)) continue;
|
|
|
- $this->send($openid,$content,$remark);
|
|
|
+ $template_arr = [
|
|
|
+ 1=>'CP3AxrgS-cbW1da8QlIDFcxd-H0RStMEuXdqNRePLoc',
|
|
|
+ 2=>'xpcaMFXI0Kc9U12o3D6CGPa7ASTpOZJwXJm2mlip6Zo'
|
|
|
+ ];
|
|
|
+ $tempId = $template_arr[$type];
|
|
|
+
|
|
|
+ $msg['content'] = $content;
|
|
|
+ $msg['service_date'] = $stime;
|
|
|
+ $msg['remark'] = $remark;
|
|
|
+ $msg['service_name'] = $service_name;
|
|
|
+
|
|
|
+ $this->send($openid,$tempId,$msg);
|
|
|
}
|
|
|
|
|
|
return $this->response()->success('发送成功')->refresh();
|
| xqd
@@ -27,43 +46,52 @@ class sendNotice extends BatchAction
|
|
|
|
|
|
public function form()
|
|
|
{
|
|
|
- $this->text('title','标题')->value('社区通知')->disable();
|
|
|
+
|
|
|
+// xpcaMFXI0Kc9U12o3D6CGPa7ASTpOZJwXJm2mlip6Zo 接种服务提醒
|
|
|
+// first,keyword1,keword2,remark;
|
|
|
+// CP3AxrgS-cbW1da8QlIDFcxd-H0RStMEuXdqNRePLoc 儿保服务提醒
|
|
|
+
|
|
|
+// 服务项目:XX疫苗接种
|
|
|
+// 服务日期:后台设置的服务时间
|
|
|
+
|
|
|
$this->textarea('content','内容')->rows(4);
|
|
|
+ $this->select('type','服务类型')->options([1=>'儿保',2=>'计免']);
|
|
|
+ $this->date('stime','服务时间');
|
|
|
$this->textarea('remark','备注')->rows(3);
|
|
|
}
|
|
|
|
|
|
- public function send($open_id,$cotent, $remark)
|
|
|
+ public function send($open_id,$tempId,$msg)
|
|
|
{
|
|
|
- if(empty($open_id)) return true;
|
|
|
- $config = [
|
|
|
- 'app_id' => 'wx1c2357232cd25f65',
|
|
|
- 'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
|
|
|
-// 'app_id' => 'wx13bedfcc62e9bab0',
|
|
|
-// 'secret' => '175e5518b6426dd12d3096f24ca68fb8',
|
|
|
- 'response_type' => 'array'
|
|
|
- ];
|
|
|
- $app = Factory::officialAccount($config);
|
|
|
- if(!isset($user['openid'])) return true;
|
|
|
- $res = $app->template_message->send([
|
|
|
+ $template = [
|
|
|
'touser' => $open_id,
|
|
|
- 'template_id' => 'GWIu1FBBA8SOdOwEbXRAmBL9LlYJP_H6EJUC7rv-YiQ',
|
|
|
- 'url' => 'https://t5.9026.com',
|
|
|
-// 'miniprogram' => [
|
|
|
-// 'appid' => 'wx6131f74e623bf6bf',
|
|
|
-// 'pagepath' => '/pages/index/index',
|
|
|
-// ],
|
|
|
- 'data' => [
|
|
|
- 'first'=>'社区通知',
|
|
|
- 'cardNumber' => '测试服务服务包',
|
|
|
- 'type' => '门诊',
|
|
|
- 'address' => '华西医院',
|
|
|
- 'VIPPhone' => 18719141830,
|
|
|
- 'VIPName' => '测试服务包',
|
|
|
- 'expDate' => '2021年12月31号',
|
|
|
- 'remark' => '请咨询13912345678。',
|
|
|
+ 'mp_template_msg' => [
|
|
|
+ 'appid' => env('OFFICIAL_WECHAT_APPID'),
|
|
|
+ 'template_id' => $tempId,
|
|
|
+ 'url' => '',
|
|
|
+ 'miniprogram' => [
|
|
|
+ 'appid' => env('WECHAT_APPID', 'wxd41dd232837996c4'),
|
|
|
+ 'pagepath' => '',
|
|
|
+ ],
|
|
|
+ 'data' => [
|
|
|
+ 'first' => [
|
|
|
+ 'value' => $msg['content'],
|
|
|
+ ],
|
|
|
+ 'keyword1' => [
|
|
|
+ 'value' => $msg['service_name'],
|
|
|
+ ],
|
|
|
+ 'keyword2' => [
|
|
|
+ 'value' => $msg['service_date'],
|
|
|
+ ],
|
|
|
+ 'remark' => [
|
|
|
+ 'value' => $msg['remark'],
|
|
|
+ ],
|
|
|
+ ],
|
|
|
],
|
|
|
- ]);
|
|
|
+ ];
|
|
|
+ $app = Factory::miniProgram(config('config.wechat_small_program'));
|
|
|
+ $app->uniform_message->send($template);
|
|
|
return true;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|