public function actionInvite()
 {
     $ph = Yii::$app->request->post();
     $model = new User();
     if ($model->find()->where(['phone' => $ph['phone']])->one()) {
         echo json_encode(array('flag' => 0, 'msg' => 'Phone has been registered!'));
         return;
     }
     $output = "app url";
     $rest = new REST();
     $apikey = '7d4294b4e224bd57377c85873b3e8430';
     $mobile = $ph['phone'];
     $tpl_id = 2;
     // 对应默认模板 【#company#】您的验证码是#code#
     $tpl_value = "#company#=云片网&#code#=" . $output;
     // $rest->send_sms($apikey,$text, $mobile);
     $data = $rest->tpl_send_sms($apikey, $tpl_id, $tpl_value, $mobile);
     $obj = json_decode($data);
     if ($obj->msg === 'OK') {
         echo json_encode(array('flag' => 1, 'msg' => 'Invite success!'));
     } else {
         var_dump($data);
         echo json_encode(array('flag' => 0, 'msg' => 'Send message failed!'));
     }
 }
 public function actionSend()
 {
     $ph = Yii::$app->request->post();
     $model = new User();
     if ($model->find()->where(['phone' => $ph['phone']])->one() && $ph['find'] == 0) {
         echo json_encode(array('flag' => 0, 'msg' => 'Phone has been registered!'));
         return;
     }
     $output = "";
     for ($i = 0; $i < 4; $i++) {
         $output .= mt_rand(0, 9);
     }
     $rest = new REST();
     $apikey = '7d4294b4e224bd57377c85873b3e8430';
     $mobile = $ph['phone'];
     $tpl_id = 2;
     // 对应默认模板 【#company#】您的验证码是#code#
     $tpl_value = "#company#=云片网&#code#=" . $output;
     // $rest->send_sms($apikey,$text, $mobile);
     $data = $rest->tpl_send_sms($apikey, $tpl_id, $tpl_value, $mobile);
     $obj = json_decode($data);
     if ($obj->msg === 'OK') {
         $model = new Vercode();
         $model->phone = $ph['phone'];
         $model->num = $output;
         $model->created_at = time();
         $model->save();
         echo json_encode(array('flag' => 1, 'msg' => 'Send success!'));
     } else {
         var_dump($data);
         echo json_encode(array('flag' => 0, 'msg' => 'Send failed!'));
     }
 }