0, 'message' => '参数不全']; } AlibabaCloud::accessKeyClient(env('ALIYUNSMS.ACCESSKEYID'), env('aliyunsms.accesskey')) ->regionId(env('ALIYUNSMS.REGIONID')) ->asDefaultClient(); try { $result = AlibabaCloud::rpc() ->product('Dysmsapi') ->version('2017-05-25') ->action('SendSms') ->method('POST') ->host('dysmsapi.aliyuncs.com') ->options([ 'query' => [ 'RegionId' => env('ALIYUNSMS.REGIONID'), 'PhoneNumbers' => $number, 'SignName' => $signName, 'TemplateCode' => $template, 'TemplateParam' => "{\"code\":\"" . $code . "\"}", ], ]) ->request(); $result = $result->toArray(); return ['code' => 1, 'info' => $result]; } catch (ClientException $e) { return ['code' => 0, 'message' => $e->getErrorMessage()]; } catch (ServerException $e) { return ['code' => 0, 'message' => $e->getErrorMessage()]; } } /** * 获得用户的短信验证码 * * @param string $mobile [手机号] * @return array */ public static function getMobileCode($mobile) { $smsExpiration = env('system.smsExpiration'); $codeInfo = \app\tools\model\MobileCode::where('state=0 and mobile="'.$mobile.'"')->order('id desc')->find(); $notMessage = '请先发送短信再验证'; if ($codeInfo) { if ((time() - $codeInfo['create_at']) <= $smsExpiration) { return ['code' => 1, 'MobileCode' => $codeInfo['code'],'check_id'=>$codeInfo['id']]; } if ((time() - $codeInfo['create_at']) > $smsExpiration && (time() - $codeInfo['create_at']) <= 60 * 30) { return ['code' => 0, 'message' => '验证码已过期']; } return ['code' => 0, 'message' => $notMessage]; } return ['code' => 0, 'message' => $notMessage]; } /** * 号码认证服务,利用一键登录TOKEN获取手机号 * * @param string $token * @return array */ public static function getMobileNumber($token = ''): array { /** back array * { * "GetMobileResultDTO": { * "Mobile": "18620725473" * }, * "Message": "OK", * "RequestId": "098CC43B-8006-4127-9DC5-2B30CA741745", * "Code": "OK" * } */ if ($token == '') { return ['code' => 0, 'message' => '参数不全']; } AlibabaCloud::accessKeyClient(env('ALIYUNSMS.ACCESSKEYID'), env('ALIYUNSMS.ACCESSKEY')) ->regionId('cn-hangzhou') ->asDefaultClient(); try { $result = AlibabaCloud::rpc() ->product('Dypnsapi') ->scheme('https') ->version('2017-05-25') ->action('GetMobile') ->method('POST') ->host('dypnsapi.aliyuncs.com') ->options([ 'query' => [ 'RegionId' => "cn-hangzhou", 'AccessToken' => $token, ], ])->request(); return ['code' => 1, 'info' => $result->toArray()]; } catch (ClientException $e) { return ['code' => 0, 'message' => $e->getErrorMessage()]; } catch (ServerException $e) { return ['code' => 0, 'message' => $e->getErrorMessage()]; } } }