多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
扩展地址:https://github.com/aliyun/openapi-sdk-php 安裝扩展 ``` comoser require alibabacloud/sdk ``` 其中需要 key,secrets后台申请然后加上号码认证权限 ``` <?php namespace App\Services; use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; class GetMobile { /** * 号码认证 * @param $token * @return false|mixed * @throws ClientException * Download:https://github.com/aliyun/openapi-sdk-php * Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md */ public static function getMobile($token){ $accessKeyId = config('aliyun.phone_verify.key'); $accessKeySecret = config('aliyun.phone_verify.secret'); AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret) ->regionId('cn-hangzhou') ->asDefaultClient(); try { $result = AlibabaCloud::rpc() ->product('Dypnsapi') ->scheme('https') // https | http ->version('2017-05-25') ->action('GetMobile') ->method('POST') ->host('dypnsapi.aliyuncs.com') ->options([ 'query' => [ 'RegionId' => "cn-hangzhou", 'AccessToken' => $token ], ]) ->request(); $aliRes=$result->toArray(); /** * "Message" => "OK" "RequestId" => "7252830D-ED91-5C7B-B91E-7F3733953C52" "Code" => "OK" "GetMobileResultDTO" => array:1 [ "Mobile" => "18888888888" ] */ if($aliRes['Message'] == 'OK' && $aliRes['Code'] == 'OK'){ if(isset($aliRes['GetMobileResultDTO'])) { $mobile = $aliRes['GetMobileResultDTO']['Mobile'];//得到手机号 return $mobile; } } return false; } catch (ClientException $e) { throw new \Exception("获取手机号失败:{$e->getErrorMessage()}"); } catch (ServerException $e) { throw new \Exception("获取手机号失败:{$e->getErrorMessage()}"); } } } ```