123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use think\Db;
- class Usercenter extends Base
- {
- public function initialize()
- {
- parent::check_login();
- }
-
- public function getUserInfo()
- {
- $uid = $this->uid;
- $field = 'id,phone,name,headimg,status,crystal,crystal_cash';
- $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- if(empty($user_info)) $this->error('用户信息不正确');
- if($user_info['status'] == 0) $this->error('该用户已被禁用');
- $this->success('获取成功',$user_info);
- }
-
- public function updateUserInfo()
- {
- $type = input('post.type',1);
- $headimg = input('post.headimg');
- $name = input('post.name');
- if(!in_array($type,[1,2])) $this->error('参数错误');
- $update_data= [];
- if($type == 1 && $name) $update_data['name'] = $name;
- if($type == 2 && $headimg) $update_data['headimg'] = $headimg;
- if(empty($update_data)) $this->error('参数错误');
- Db::name('store_member')->where('id',$this->uid)->update($update_data);
- $field = 'phone,name,headimg';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->uid)->find();
- $this->success('编辑成功',$user_info);
- }
-
- public function modifyPhone()
- {
- $uid = $this->uid;
- $phone = input('post.phone');
- $code = input('post.code');
- if(empty($phone) || empty($code) ) $this->error('参数错误');
- $store_member_sms = Db::name('store_member_sms')
- ->field('id,code')->where('phone',$phone)
- ->where('used',0)->order('id desc')
- ->find();
- if($store_member_sms['code'] != $code) $this->error('验证码错误');
-
- $member_id = Db::name('store_member')->where('phone','=',$phone)->where('id','<>',$this->uid)->value('id');
- if($member_id) $this->error('手机号已注册过');
- $up = ['phone'=>$phone];
- $res = Db::name('store_member')->where('id',$uid)->update($up);
- $field = 'phone,name,headimg,status,decode_password,password';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->uid)->find();
- if($res !==false){
- Db::name('store_member_sms')->where('id',$store_member_sms['id'])->update(['used'=>1]);
- $this->success('绑定成功',$user_info);
- }else{
- $this->error('绑定失败');
- }
- }
-
- public function sendSms(){
- $phone = input('post.phone');
- if(empty($phone)) $this ->error('参数错误');
- $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
- AlibabaCloud::accessKeyClient('LTAI5tSFmMzKUQC4zJjc3Guu', 'gdEyLTubu0KT6WzR26upX3dgiu5FD6')
- ->regionId('cn-hangzhou')->asDefaultClient();
- try {
- $result = AlibabaCloud::rpc()
- ->product('Dysmsapi')
- ->version('2017-05-25')
- ->action('SendSms')
- ->method('POST')
- ->host('dysmsapi.aliyuncs.com')
- ->options([
- 'query' => [
- 'RegionId' => "cn-hangzhou",
- 'PhoneNumbers' => $phone,
- 'SignName' => "验证码",
- 'TemplateCode' => "SMS_204845304",
- 'TemplateParam' => json_encode(array("code"=>$code)),
- ],
- ])->request();
- $result = $result->toArray();
- var_dump($result);
- if($result['Code'] == "OK")
- {
- $sms_data = array(
- 'phone'=>$phone,
- 'code'=>$code,
- 'result'=>$result['Message']
- );
- Db::name('store_member_sms')->insert($sms_data);
- $this->error('发送成功',$code);
- }else{
- $this->error('发送失败');
- }
- } catch (ClientException $e) {
- echo $e->getErrorMessage() . PHP_EOL;
- } catch (ServerException $e) {
- echo $e->getErrorMessage() . PHP_EOL;
- }
- }
- }
|