public function postPlan($planSlug, Request $request, StripeBilling $billing) { $this->validate($request, ['first_name' => 'required', 'last_name' => 'required', 'password' => 'required', 'password_confirm' => 'required|same:password', 'email' => 'required|email|unique:users', 'phone' => 'required']); $plan = MembershipPlan::where('slug', $planSlug)->firstOrFail(); $planName = ucwords(str_replace('-', ' ', $planSlug)); if (!in_array($planSlug, ['annual-platinum', 'annual-gold', 'annual-silver', 'lifetime'])) { try { $charge = $billing->charge(array('amount' => $plan->amount, 'email' => $request->get('email'), 'name' => $request->get('first_name') . ' ' . $request->get('last_name') . ', ' . $planName, 'stripe-token' => $request->get('stripe-token'), 'plan' => $planSlug)); $customer = true; } catch (\Exception $e) { Flash::danger($e->getMessage()); return redirect()->refresh(); } } else { try { $charge = $billing->oneTime(array('amount' => $plan->amount, 'name' => $request->get('first_name') . ' ' . $request->get('last_name') . ', ' . $planName, 'stripe-token' => $request->get('stripe-token'))); $customer = false; } catch (\Exception $e) { Flash::danger($e->getMessage()); return redirect()->refresh(); } } if (!empty($charge['created'])) { $user = User::create(['plan_id' => $plan->id, 'first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'phone_number' => $request->get('phone'), 'street_address' => $request->get('address1') . ' ' . $request->get('address2'), 'city' => $request->get('city'), 'state' => $request->get('state_province'), 'zip' => $request->get('postal_code'), 'password' => Hash::make($request->get('password')), 'membership_expires' => $customer ? date('Y-m-d', strtotime('+1 year')) : null, 'customer_id' => $charge['id']]); if ($request->get('sms')) { Sms::create(['phone_number' => $request->get('phone')]); } if ($request->get('newsletter')) { try { $mailchimp = new Mailchimp(env('MAILCHIMP_API_KEY')); $mailchimp->lists->subscribe(env('MAILCHIMP_LIST_ID'), ['email' => $request->get('email')], null, 'html'); } catch (Mailchimp_List_AlreadySubscribed $e) { Flash::danger($e->getMessage()); return back(); } catch (\Exception $e) { Flash::danger($e->getMessage()); return back(); } } Flash::success('Congratulations! You are now a Lambda Phoenix Center ' . $planName . ' member.'); Auth::login($user); return redirect('dashboard/incentives/' . $planSlug); } }
public function sendMessage($content, $type, $userId, $phone) { $messagesUsersInfo['messages_id'] = 1; $messagesUsersInfo['type'] = $type; $messagesUsersInfo['title'] = Messages::$typeList[$type]; $messagesUsersInfo['users_id'] = $userId; $messagesUsersInfo['content'] = $content; $messagesUsersInfo['create_time'] = date('Y-m-d H:i:s', time()); $messagesUsersInfo['create_user'] = '******'; $messagesUsersInfo['update_time'] = date('Y-m-d H:i:s', time()); $messagesUsersInfo['update_user'] = '******'; MessagesUsers::addInfo($messagesUsersInfo); $smsModel = Sms::getInstance(Yii::$app->params['smsUserName'], Yii::$app->params['smsPassword']); $result = $smsModel->pushMt($phone, time(), $content, 0); return $result; }
public function receive() { $sender = preg_replace('/[^0-9]/', '', $_REQUEST['From']); $sender = substr($sender, 1); $body = $_REQUEST['Body']; if (strtolower($body) == 'stop') { $users = Sms::where('phone_number', $sender)->limit(1)->get(); foreach ($users as $user) { $user->delete(); } } return response()->view('sms/xml')->header('Content-Type', 'text/xml'); }
public function actionGetCheckNum() { $phone = Yii::$app->request->get('phone'); $checkNum = rand(100000, 999999); $session = Yii::$app->session; if (!isset($session['time'])) { $session['time'] = date("Y-m-d H:i:s"); } $session['checkNum'] = $checkNum; //将content的值保存在session中 if (!empty($phone)) { if (strtotime($session['time']) + 60 < time()) { //将获取的缓存时间转换成时间戳加上60秒后与当前时间比较,小于当前时间即为过期 session_destroy(); $session->remove('time'); $msg = '验证码已过期,请重新获取!'; } else { $content = "尊敬的学员,您的验证码是" . $checkNum . ",此验证码于一分钟后过期,谢谢!【教练系统】"; $smsModel = Sms::getInstance(Yii::$app->params['smsUserName'], Yii::$app->params['smsPassword']); $result = $smsModel->pushMt($phone, time(), $content, 0); if ($result == '0') { $msg = '验证码已经发送到手机' . $phone . ',请注意查收。'; } else { $msg = $result; } } } else { $msg = '发送失败,请再次尝试!'; } return $msg; }