Ejemplo n.º 1
0
 public function actionCreate()
 {
     $post = Yii::$app->request->post();
     //判断名称
     if (empty($post['name'])) {
         throw new NotFoundHttpException(Yii::t('yii', 'Missing required parameters: {params}', ['params' => '公众号名称']));
     }
     //判断类型
     if (empty($post['type'])) {
         throw new NotFoundHttpException(Yii::t('yii', 'Missing required parameters: {params}', ['params' => '公众号类型']));
     }
     //判断appid
     if (empty($post['appid'])) {
         throw new NotFoundHttpException(Yii::t('yii', 'Missing required parameters: {params}', ['params' => 'AppID(应用ID)']));
     }
     //判断appsecret
     if (empty($post['appsecret'])) {
         throw new NotFoundHttpException(Yii::t('yii', 'Missing required parameters: {params}', ['params' => 'AppSecret(应用密钥)']));
     }
     //加解密模式
     $post['encript_mode'] = !empty($post['encript_mode']) ? intval($post['encript_mode']) : 1;
     //默认明文模式
     $post['create_time'] = time();
     $post['update_time'] = time();
     $post['unique_id'] = md5(Yii::$app->security->generateRandomString() . time());
     //随机生成
     $post['token'] = Common::getGenerateSalt(8);
     //随机生成英文或者数字组合的随机字符串
     $model = new PublicNumber();
     if ($model->load(['PublicNumber' => $post]) && $model->save()) {
         $model->order_id = $model->id;
         $model->save();
         return $this->redirect(['public-number/form', 'id' => $model->id]);
     } else {
         throw new NotFoundHttpException(Yii::t('yii', 'An internal server error occurred.'));
     }
 }
Ejemplo n.º 2
0
 /**
  * 文件命名 规则
  */
 private function getSaveName($file)
 {
     $saveName = md5(uniqid() . Common::getGenerateSalt()) . '.' . $file['extension'];
     return $saveName;
 }