lizhen_gitee пре 9 месеци
родитељ
комит
09e35008b4
1 измењених фајлова са 58 додато и 2 уклоњено
  1. 58 2
      application/index/controller/Plantask.php

+ 58 - 2
application/index/controller/Plantask.php

@@ -53,8 +53,25 @@ class Plantask extends Controller
                 $result = $obj
                     ->to($order['email'])
                     ->subject('Don’t forget about your class tomorrow!')
-                    ->message('Hi,'.$order['firstname']. ' ' .$order['lastname'].',您预约的['.$order['name'].']将于'.date('Y-m-d H:i:s',$slot['starttime']).'开课,请合理安排时间,准时来上课哦!')
+                    ->message('Hi,'.$order['firstname']. ' ' .$order['lastname'].',您预约的['.$order['name'].']将于'.date('Y-m-d H:i',$slot['starttime']).'开课,请合理安排时间,准时来上课哦!')
                     ->send();
+
+                //发whatsapp
+                $parameters = [
+                    [
+                        'type' => 'text',
+                        'text' => $order['firstname'].' '.$order['lastname'],
+                    ],
+                    [
+                        'type' => 'text',
+                        'text' => $order['name_en'],
+                    ],
+                    [
+                        'type' => 'text',
+                        'text' => date('Y-m-d H:i',$slot['starttime']),
+                    ],
+                ];
+                $this->whatapp($order['whatsapp'],'the_class_will_start_tomorrow','en_US',$parameters);
             }
 
             //这节课时,任务完成
@@ -113,7 +130,7 @@ class Plantask extends Controller
 
             //这节课时,任务完成
             $update = [
-                'notice_status' => 1,
+                'cancel_notice_status' => 1,
             ];
             Db::name('lesson_slot')->where('id',$slot['id'])->update($update);
         }
@@ -234,6 +251,45 @@ class Plantask extends Controller
 
 /////////////////////////////////////////下面都是工具方法////////////////////////////////////////////////
 
+    public function whatapp($receive_mobile,$template,$code,$parameters){
+        if(empty($receive_mobile)){return true;}
+
+        $token = config('site.whatsapp_token');
+
+        //发送者
+        $mobile_id = '337736419413019'; //Elin Dance Stuido 2:+65 8015 4154  ,  WhatsApp Business Account ID: 336509229537586
+
+        //发送
+        $url = 'https://graph.facebook.com/v19.0/'.$mobile_id.'/messages';
+        $header = [
+            'Authorization: Bearer ' . $token,
+            'Content-Type: application/json',
+        ];
+        $body = [
+            'messaging_product' => 'whatsapp',
+            'recipient_type' => 'individual',
+            'to' => $receive_mobile,
+            'type' => 'template',
+            'template' => [
+                'name' => $template,
+                'language' => [
+                    'code' => $code
+                ],
+                'components' => [
+                    [
+                        'type' => 'body',
+                        'parameters' => $parameters
+                    ]
+
+                ],
+            ],
+        ];
+        $body = json_encode($body);
+
+        $rs = curl_post($url,$body,$header);
+        return true;
+    }
+
     //结果集信息里,多个字段需要翻译
     private function list_lang($list,$field,$lang = ''){
         if(!$list || empty($list)){